fix: Crash if hallway automation is called before door/trash have been initialized

Resolves: #4
This commit is contained in:
2025-09-04 01:33:56 +02:00
parent 8109dcf2f5
commit f3b1854beb

View File

@@ -437,7 +437,7 @@ local hallway_light_automation = {
self.group.set_on(true)
elseif not self.forced then
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)
end
end)
@@ -447,13 +447,21 @@ local hallway_light_automation = {
if open then
self.group.set_on(true)
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)
end
end
end,
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
self.timeout:cancel()
self.forced = true