SecKatie / ha-wyzeapi

Home Assistant Integration for Wyze devices.
733 stars 112 forks source link

[Bug] Older wyze bulbs fail to load - Error while setting up wyzeapi platform for light #504

Closed BoredMind closed 1 year ago

BoredMind commented 1 year ago

Describe the bug Non color Wyze bulbs, pre-2019 bulbs, do not load any longer. Started a few days ago.

To Reproduce Steps to reproduce the behavior:

  1. Go to Integrations -> Wyze Home Assistant Integration -> Entities
  2. Click on any older, non color, Wyze bulb.
  3. See error:

This entity is no longer being provided by the wyzeapi integration. If the entity is no longer in use, delete it in settings.

Expected behavior Should be able to control bulb, cannot change any attributes.

System configuration HA Version: 2023.8. WyzeApi Version: 0.1.22

Device info WLPA19 by WyzeLabs

home-assistant.log

Error adding entities for domain light with platform wyzeapi
Error while setting up wyzeapi platform for light
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 510, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 750, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1004, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 746, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 810, in _async_write_ha_state
    attr.update(self.state_attributes or {})
                ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 996, in state_attributes
    color_mode = self._light_internal_color_mode
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 822, in _light_internal_color_mode
    if (color_mode := self.color_mode) is None:
                      ^^^^^^^^^^^^^^^
  File "/config/custom_components/wyzeapi/light.py", line 221, in color_mode
    return ColorMode.COLOR_TEMP if self._bulb.color_mode == "2" else ColorMode.HS
                                   ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Bulb' object has no attribute 'color_mode'
SecKatie commented 1 year ago

@brg468 can you look at this issue? Is it related to your recent PR?

brg468 commented 1 year ago

@SecKatie it must be based on the timing. I was under the impression that all bulbs reported the color mode property, but apparently the early ones might not. I’ll take a look.

brg468 commented 1 year ago

@BoredMind if you would like to try this before it gets merged to make sure it actually fixes the problem, you can edit your light.py file starting at line 219 like below.

https://github.com/SecKatie/ha-wyzeapi/blob/c19080c2b2a5e8e4346c11faa567d32ed7fe9d28/custom_components/wyzeapi/light.py#L219-L223

BoredMind commented 1 year ago

The bulbs are now active again, and while I can turn them on and off, I get this error when it happens:

Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/wyzeapi/light.py:221
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 4:09:28 PM (3 occurrences)
Last logged: 4:09:38 PM

[547493361856] 'Bulb' object has no attribute 'color_mode'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 226, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1974, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2011, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 235, in handle_service
    return await service.entity_service_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 870, in entity_service_call
    response_data = await _handle_entity_call(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 942, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 580, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/config/custom_components/wyzeapi/token_manager.py", line 45, in inner_function
    await func(*args, **kwargs)
  File "/config/custom_components/wyzeapi/light.py", line 201, in async_turn_on
    self.async_schedule_update_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 903, in async_schedule_update_ha_state
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 746, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 810, in _async_write_ha_state
    attr.update(self.state_attributes or {})
                ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 996, in state_attributes
    color_mode = self._light_internal_color_mode
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 822, in _light_internal_color_mode
    if (color_mode := self.color_mode) is None:
                      ^^^^^^^^^^^^^^^
  File "/config/custom_components/wyzeapi/light.py", line 221, in color_mode
    if self._bulb.type is DeviceTypes.LIGHT:
                                 ^^^^^^^^^^^^
AttributeError: 'Bulb' object has no attribute 'color_mode'
BoredMind commented 1 year ago

Did a full restart of HA, might not be seeing that error any longer, the "AttributeError: 'Bulb' object has no attribute 'color_mode'" one

brg468 commented 1 year ago

So all good?

BoredMind commented 1 year ago

So all good?

Appears to be all good

saicrazyfire commented 1 year ago

@BoredMind if you would like to try this before it gets merged to make sure it actually fixes the problem, you can edit your light.py file starting at line 219 like below.

https://github.com/SecKatie/ha-wyzeapi/blob/c19080c2b2a5e8e4346c11faa567d32ed7fe9d28/custom_components/wyzeapi/light.py#L219-L223

I can confirm this works for me after a restart

brg468 commented 1 year ago

@1h8fulkat you modified the code as above? 0.1.22 does not incorporate this change unless you made it yourself.

1h8fulkat commented 1 year ago

@1h8fulkat you modified the code as above? 0.1.22 does not incorporate this change unless you made it yourself.

I retract my previous statement 🤦‍♂️

prnewman commented 1 year ago

Updating light.py fixed it for me

RobertL1988 commented 1 year ago

Just completed the change and restarted HA. No more error.

MMachor commented 1 year ago

Just ran into this issue, or at least realized I was running into this issue. Found the open bug with workaround and am happy to report that after adjusting the code it fixed the issue here as well. Thank you!

nicksardo commented 12 months ago

Is there ever going to be a release containing this PR? Seems crazy to put out a release that breaks bulbs and not put out another release with the fix. Having folks fix the file manually is absurd.

brg468 commented 12 months ago

@nicksardo, while I would like to see this get merged at well, let’s remember that this integration is totally built and maintained by volunteers in their spare time. Until the update is pushed, I gave you a simple copy and paste fix that you can choose to use or not.

nibeckd commented 11 months ago

This is my first attempt to edit code. I applied the above and it worked for the first 3 of my 7 bulbs. The other 4 are still showing Unavailable status. Any advice?

James62370 commented 9 months ago

I'm getting the same error with older 2019 Wyze bulbs. I tried applying the fix above, but then most of my other bulbs don't even load. The light turns on even with the error, but when ran within an automation, the script halts with an error and never completes the automation.

Logger: wyzeapy.services.update_manager Source: /usr/local/lib/python3.11/site-packages/wyzeapy/services/update_manager.py:46 First occurred: 12:13:12 AM (1 occurrences) Last logged: 12:13:12 AM

Unknown error happened during updating device info Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/wyzeapy/services/update_manager.py", line 44, in update self.device.callback_function(self.device) File "/config/custom_components/wyzeapi/light.py", line 353, in async_update_callback self.async_schedule_update_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 956, in async_schedule_update_ha_state self.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 779, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 879, in _async_write_ha_state state, attr = self._async_generate_attributes() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 822, in _async_generate_attributes attr.update(self.state_attributes or {}) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/light/init.py", line 1007, in state_attributes color_mode = self._light_internal_color_mode ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/light/init.py", line 833, in _light_internal_color_mode if (color_mode := self.color_mode) is None: ^^^^^^^^^^^^^^^ File "/config/custom_components/wyzeapi/light.py", line 221, in color_mode return ColorMode.COLOR_TEMP if self._bulb.color_mode == "2" else ColorMode.HS ^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Bulb' object has no attribute 'color_mode'


Logger: homeassistant.components.websocket_api.http.connection Source: components/websocket_api/commands.py:226 Integration: Home Assistant WebSocket API (documentation, issues) First occurred: 12:13:00 AM (1 occurrences) Last logged: 12:13:00 AM

[140066697070528] 'Bulb' object has no attribute 'color_mode' Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 226, in handle_call_service await hass.services.async_call( File "/usr/src/homeassistant/homeassistant/core.py", line 2012, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2049, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 235, in handle_service return await service.entity_service_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 876, in entity_service_call response_data = await _handle_entity_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 948, in _handle_entity_call result = await task ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/light/init.py", line 580, in async_handle_light_on_service await light.async_turn_on(*filter_turn_on_params(light, params)) File "/config/custom_components/wyzeapi/token_manager.py", line 45, in inner_function await func(args, **kwargs) File "/config/custom_components/wyzeapi/light.py", line 201, in async_turn_on self.async_schedule_update_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 956, in async_schedule_update_ha_state self.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 779, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 879, in _async_write_ha_state state, attr = self._async_generate_attributes() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 822, in _async_generate_attributes attr.update(self.state_attributes or {}) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/light/init.py", line 1007, in state_attributes color_mode = self._light_internal_color_mode ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/light/init.py", line 833, in _light_internal_color_mode if (color_mode := self.color_mode) is None: ^^^^^^^^^^^^^^^ File "/config/custom_components/wyzeapi/light.py", line 221, in color_mode return ColorMode.COLOR_TEMP if self._bulb.color_mode == "2" else ColorMode.HS ^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Bulb' object has no attribute 'color_mode'

brg468 commented 9 months ago

@James62370 I'm guessing something didn't go right when you edited the code since the error still refers to the "if" statement on line 221. I posted an easier way to correct this problem here:

https://github.com/SecKatie/ha-wyzeapi/issues/521#issuecomment-1757428836

James62370 commented 9 months ago

@James62370 I'm guessing something didn't go right when you edited the code since the error still refers to the "if" statement on line 221. I posted an easier way to correct this problem here:

#521 (comment)

Thanks for pointing me to the right location. I downloaded the updated script and appears to be working well now.