rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
2.91k stars 557 forks source link

New update by device is producing exception if device is not available #54

Closed ultratoto14 closed 4 years ago

ultratoto14 commented 4 years ago

For the light bulbs, we can have some bulbs that are not logically off but physically off.

In that case, the new way of getting status (by device) produces exception traces in logs:

Traceback (most recent call last):
  File "/config/custom_components/localtuya/common.py", line 75, in __get_status
    status = self._interface.status()
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 381, in status
    data = self._send_receive(payload)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 194, in _send_receive
    raise e
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 191, in _send_receive
    s.connect((self.address, self.port))
OSError: [Errno 113] Host is unreachable
postlund commented 4 years ago

What was the behavior before? Must have been something similar, perhaps just printed to console. Anyway, we can suppress errors and just make the entities unavailable instead. I was thinking of adding an error attribute to state_attributes as well since Home Assistant has very poor support for reporting problems (other than the log, which isn't a very user-friendly way of doing so).

ultratoto14 commented 4 years ago

Yes, previously, we just had the status set to unavailable and no exception. It seems also that the startup of ha is delayed, the integration is trying multiple times to get the status before letting the startup continue.

postlund commented 4 years ago

I've noticed the delay start up as well. Not sure why that happens, I thought I "fixed that". Oh, nooow I see... Will deal with that later today.

postlund commented 4 years ago

Ok, so, if a device is unavailable then state attributes are not shown in the UI (which seems logical since the entity is not available, so no info should be present). This however makes it tricky to display any error information. I have an idea though...

postlund commented 4 years ago

I created #57 which should fix this. Would be great if you can try it out!