fix: Crash if hallway automation is called before door/trash have been initialized
Resolves: #4
This commit is contained in:
14
config.lua
14
config.lua
@@ -437,7 +437,7 @@ local hallway_light_automation = {
|
|||||||
self.group.set_on(true)
|
self.group.set_on(true)
|
||||||
elseif not self.forced then
|
elseif not self.forced then
|
||||||
self.timeout:start(debug and 10 or 2 * 60, function()
|
self.timeout:start(debug and 10 or 2 * 60, function()
|
||||||
if self.trash:open_percent() == 0 then
|
if self.trash == nil or self.trash:open_percent() == 0 then
|
||||||
self.group.set_on(false)
|
self.group.set_on(false)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@@ -447,13 +447,21 @@ local hallway_light_automation = {
|
|||||||
if open then
|
if open then
|
||||||
self.group.set_on(true)
|
self.group.set_on(true)
|
||||||
else
|
else
|
||||||
if not self.timeout:is_waiting() and self.door:open_percent() == 0 and not self.forced then
|
if
|
||||||
|
not self.timeout:is_waiting()
|
||||||
|
and (self.door == nil or self.door:open_percent() == 0)
|
||||||
|
and not self.forced
|
||||||
|
then
|
||||||
self.group.set_on(false)
|
self.group.set_on(false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
light_callback = function(self, on)
|
light_callback = function(self, on)
|
||||||
if on and self.trash:open_percent() == 0 and self.door:open_percent() == 0 then
|
if
|
||||||
|
on
|
||||||
|
and (self.trash == nil or self.trash:open_percent()) == 0
|
||||||
|
and (self.door == nil or self.door:open_percent() == 0)
|
||||||
|
then
|
||||||
-- If the door and trash are not open, that means the light got turned on manually
|
-- If the door and trash are not open, that means the light got turned on manually
|
||||||
self.timeout:cancel()
|
self.timeout:cancel()
|
||||||
self.forced = true
|
self.forced = true
|
||||||
|
|||||||
Reference in New Issue
Block a user