RobertD502 / home-assistant-iocare

Home Assistant custom component for monitoring and controlling Coway Airmega Purifiers
MIT License
50 stars 8 forks source link

‘Purifier' object has no attribute 'timer' #4

Closed kvermilion closed 2 years ago

kvermilion commented 2 years ago

I get the following error when adding the integration as well as when restarting Home Assistant. I am using Home Assistant core and have the coway folder symlinked into my custom_components folder. Using the latest release tag. I had updated to 2022.3.0 and my Coway integration stopped working, so I decided to try this fork since it is more actively maintained. I checked the 2022.3.0 release notes for a breaking change that might cause this but don’t see one… maybe I missed it…

Traceback (most recent call last):
  File "/opt/ha/lib/python3.9/site-packages/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
    await asyncio.gather(*tasks)
  File "/opt/ha/lib/python3.9/site-packages/homeassistant/helpers/entity_platform.py", line 521, in _async_add_entity
    original_icon=entity.icon,
  File "/home/ha/.homeassistant/custom_components/coway/select.py", line 75, in icon
    if self.current_option is "OFF":
  File "/home/ha/.homeassistant/custom_components/coway/select.py", line 83, in current_option
    return IOCARE_TIMERS_TO_HASS.get(self.coordinator.data[self._device].timer)
AttributeError: 'Purifier' object has no attribute 'timer'
kvermilion commented 2 years ago

Turns out this was caused by the actual device being offline. I guess I was unlucky enough that it went offline around the time I was upgrading.

I suppose it would be nice if there was a more clear identification of this issue.

RobertD502 commented 2 years ago

Purifiers are set to become unavailable if Coway's servers show the purifier as not being connected to their servers. On rare occasions, as I've found out myself, their servers fail to update some endpoints and show old information - in your case the endpoint that contains info about the purifier's connection to Coway's servers hadn't updated, but the endpoint that returns info about the purifier had updated and correctly showed no info is available.

I'll need to add an additional check to the code for situations such as this one and log that the purifier is potentially offline.

RobertD502 commented 2 years ago

@kvermilion Pushing a release shortly to properly log if a purifier is offline. Thanks for bringing this to my attention.