dave-code-ruiz / elkbledom

Home Assistant custom component for LED STRIP NAME ELK BLEDOM
MIT License
77 stars 16 forks source link

self.brightness value can be None, leading to a crash in _transform_color_brightness #21

Closed TriWitch closed 1 year ago

TriWitch commented 1 year ago

In some cases, the function _transform_color_brightness crashes because it is given a None value for brightness by the upstream funnctions.

Error is: unsupported operand type(s) for *: 'int' and 'NoneType'

Relevant part of the trace:

File "/usr/src/homeassistant/homeassistant/components/light/init.py", line 582, in async_handle_light_on_service await light.async_turn_on(*filter_turn_on_params(light, params)) File "/config/custom_components/elkbledom/light.py", line 163, in async_turn_on color = self._transform_color_brightness(color, self.brightness) File "/config/custom_components/elkbledom/light.py", line 130, in _transform_color_brightness res = tuple(color set_brightness // 255 for color in rgb) File "/config/custom_components/elkbledom/light.py", line 130, in res = tuple(color set_brightness // 255 for color in rgb) TypeError: unsupported operand type(s) for : 'int' and 'NoneType'

Context: This seems to happen when self.brightness is None from a new/uninitialized/switched-off device, but I cannot say exactly

Workaround: A workaround is a sanity check in _transform_color_brightness, e.g. if set_brightens is None: set_brightness =0

but it would be better to find the root cause and fix the initialization, I guess. Happy to help when I get the time, thanks so much for your great work!

dave-code-ruiz commented 1 year ago

i think version 1.0.2 solves your problem

please check it and post results

Thanks

TriWitch commented 1 year ago

I see you set the property default for brightness to 250, which makes sense in the absence of a "current state retrieval". With that change (using 1.0.2) it works for me. Impressive response time!