sbidy / wiz_light

A WiZ Light integration for Home Assistant
MIT License
341 stars 68 forks source link

Light has to be turned on when adding to HASS or during HASS startup otherwise it will not work [0.40] #110

Closed wingedseed closed 2 years ago

wingedseed commented 3 years ago

Logger: homeassistant.components.light Source: custom_components/wiz_light/light.py:225 Integration: Light (documentation, issues) First occurred: 10:00:15 PM (4 occurrences) Last logged: 10:00:15 PM

Error adding entities for domain light with platform wiz_light Error while setting up wiz_light platform for light Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 315, in async_add_entities await asyncio.gather(*tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 421, in _async_add_entity capabilities=entity.capability_attributes, File "/usr/src/homeassistant/homeassistant/components/light/init.py", line 462, in capability_attributes data[ATTR_EFFECT_LIST] = self.effect_list File "/config/custom_components/wiz_light/light.py", line 224, in effect_list return [ File "/config/custom_components/wiz_light/light.py", line 225, in self._scenes[key] IndexError: list index out of range

After updating to 0.40, I noticed that all my lights stop working. After some testings, I find that if I don't turn on my lights during the adding process, it will only create a device entry without any entities. Then I found out that if I have them turned on during the adding process then they will be added just fine. If the device capability attribute can only be obtained when the light is on, maybe adding some notice during the adding process can help to avoid this?

Another similar issue is if those lights are not turned on during a HASS restart, they will become unavailable again.

It seems like the light capability attribute detection routine will run every time the component is loaded and if lights are not on, it will have a problem getting the attributes and those added lights will become unavailable.

Maybe this can be fixed by creating a device registry after a light is successfully added, and HASS can use this info in the device registry instead of running the routine everytime?

Thanks!

sbidy commented 3 years ago

I'm working on that. This error is a cascading one from the (currently) main issue. If the bulb is offline at startup, HASS will never bring the bulb in the state available. Regardless if the bulb is switched on after startup. Currently the workaround is to connect all bulb to power on startup.

It seems to be an issue with the HASS core because my integration will report the correct state in the available property. But if the bulb is offline at startup HASS flags this as "removed".

wingedseed commented 3 years ago

Before 0.40, the bulb doesn't have to be turned on (not offline, the bulb is powered and connected but with an OFF state) during the HASS startup. But after upgrading to 0.40, if I turn off the bulb (again, still powered and connected, just soft-off), it will become unavailable in HASS, but I can still control it via the app. Thanks!

sbidy commented 3 years ago

I'm still working on the issue. It seems to be an interaction error with the HASS core. This makes it really difficult to debug. Unfortunately, the maintainer from HASS are also not so responsive to give some feedback,

ccpk1 commented 3 years ago

I was having this issue, but it seems to be fixed in 0.4.2. I confirmed on the the following bulbs: 23004 (A19 White only color changing), 23007 (A19 Full color), and B23065 (A19 Full color)

RichieFrame commented 3 years ago

0.4.2 did not actually fix this issue for me, after 3 reboots of HA they were all still offline, except for one that came back then went offline at some point (automation set bulb color). What did fix (maybe) was deleting all the bulb entities before restarting HA.

sbidy commented 3 years ago

Yes, the issue still exists.

bdraco commented 2 years ago

This can be closed as its fixed in the core version