basnijholt / adaptive-lighting

Adaptive Lighting custom component for Home Assistant
https://basnijholt.github.io/adaptive-lighting/
Apache License 2.0
1.77k stars 132 forks source link

Light aren't turning off, logs show "KeyError" #738

Closed giannoug closed 1 year ago

giannoug commented 1 year ago

Sorry for not using the template, I'm opening this bug so I can fill in the information when it happens (it's totally random so I can't gather everything at once). I'm having this issue some days now. Everything is up to date, from HA to AL.

I have some lights (always the same ones) that stay on after being turned off. The AL group contains the same lights I'm always turning on or off. I noticed the following in the logs:

Traceback (most recent call last):
  File "/config/custom_components/adaptive_lighting/switch.py", line 2354, in state_changed_event_listener
    self.start_transition_timer(entity_id)
  File "/config/custom_components/adaptive_lighting/switch.py", line 2095, in start_transition_timer
    last_service_data = self.last_service_data[light]
                        ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
KeyError: 'light.countertop_small'

I will update the ticket when I manage to capture a debug log of this happening.

basnijholt commented 1 year ago

@giannoug, which version are you using?

I think not 1.19.0?

Can you update and see whether it still happens? (It shouldn't).

basnijholt commented 1 year ago

How do I know that you are not using the latest version?

Well this is the current code:

https://github.com/basnijholt/adaptive-lighting/blob/9112bb9f7329f8aee995ac33b9502ce83b8177f8/custom_components/adaptive_lighting/switch.py#L2045-L2053

and in your error message I see it is failing in this line:

  File "/config/custom_components/adaptive_lighting/switch.py", line 2095, in start_transition_timer
    last_service_data = self.last_service_data[light]

which does not exist anymore.

giannoug commented 1 year ago

I think not 1.19.0?

I was pretty confident I had updated... No I'm still running 1.18.3. Sorry about that! I'll close and report back if it happens again