basnijholt / adaptive-lighting

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

Fix isinstance-asserts in switch.py #949

Closed bouwew closed 3 months ago

bouwew commented 3 months ago

This fixes the error reported in #919

The isinstance() asserts need to match the corresponding typing definitions: image

Or, match to the corresponding is_on typing definition: image

basnijholt commented 3 months ago

Thanks for opening this PR, however, it is not the correct fix because the functions that use these variables expect that the variables are booleans.

The correct fix would make sure that the types are correct to begin with.

basnijholt commented 3 months ago

The fact that these variables are None means that this function must have failed:

https://github.com/basnijholt/adaptive-lighting/blob/f2a124c30f53e67ea8606adeabd83df84c7a5c51/custom_components/adaptive_lighting/switch.py#L1591-L1600

bouwew commented 3 months ago

I considered that as a second option :)

What can I do to troubleshoot this error? Enable debug-logging?

bouwew commented 3 months ago

If you are correct then this error should happen directly after a Core-restart. As far as I can remember, haven't seen the error for some time because I updated the code locally, this error did not show directly after a Core restart but significantly later.

Or, are there reloads happening during runtime? Yes, of course, when updating the configuration. Maybe then it happened, I'll revert and watch the HA LOGBOOK.

bouwew commented 3 months ago

After capturing some logging, it turns out the error is caused by a light that is no longer present.