sarahhenkens / home-assistant-iocare

27 stars 15 forks source link

Uncaught exception #19

Open NavreetGill opened 3 years ago

NavreetGill commented 3 years ago

If HomeAssistant is unable to reach an air filter (e.g. if the unit is powered off, or other connectivity issue), an exception is raised.

Currently, this exception is not handled, and may cause issues for updating status for other devices. For example, if a person had 3 air purifiers connected, and the first one throws an exception, it is possible that status for other devices is not retrieved since processing (a for loop) is stopped due to an exception.

Proposal: We should catch and log the exception, but continue trying to refresh status of other devices.

Please note that this was mentioned in #6, but the issue seemed to have been closed prematurely.

Here is the relevant call stack:

File "/config/custom_components/iocare/fan.py", line 184, in update self._device.refresh() File "/usr/local/lib/python3.8/site-packages/iocare/devices/purifier.py", line 16, in refresh self.is_on = control_status['0001'] == '1' KeyError: '0001'

RobertD502 commented 3 years ago

If you have any experience, please create a PR solving the problem as I personally don't have the time at this moment.

RobertD502 commented 3 years ago

@NavreetGill Just looked at my own HA logs and saw the same error being reported multiple times (36 to be exact). However, the KeyError doesn't seem to be keeping other devices from updating. Regardless, you are correct in stating that this exception should be handled. I will look into it when I have some time. The problem stems from an API that wasn't written by @sarahhenkens or I.

RobertD502 commented 3 years ago

Just tested out a fix that hasn't thrown a KeyError. Make sure to restart Home Assistant. It should pull my fork of the python-iocare requirement that includes the fix on restart.