nbogojevic / homeassistant-midea-air-appliances-lan

This Home Assistant custom component adding support for controlling Midea air conditioners and dehumidifiers on local network.
MIT License
268 stars 29 forks source link

Whole integration crashes when unplugging one device #19

Closed gsportelli closed 2 years ago

gsportelli commented 2 years ago

I get the following error when I unplug one of my dehumidifiers from the power outlet:

Logger: midea_beautiful_dehumidifier.lan
Source: /srv/homeassistant/lib/python3.9/site-packages/midea_beautiful_dehumidifier/lan.py:521
First occurred: 11:21:39 (1 occurrences)
Last logged: 11:21:39
Unable to send data after 3 retries, last error for id=31885837219292 ip=192.168.1.132:6444 version=3

The problem is that, when it happens, the whole integration goes out of service reporting "Failed to set up" in the integrations page and also the other devices become unavailable.

Moreover, there is no way to reload the integration without restarting home assistant when it goes into this state.

nbogojevic commented 2 years ago

hello @gsportelli new version 0.6.0-beta has been published. You can see details in #32. Can you check if the problem has been addressed - integration should no longer go into failed setup mode?

gsportelli commented 2 years ago

When I disconnect one of the three devices, it goes unavailable while the others keep working, as expected. However, if in this state I restart HA, it gives the following errors and I get all three devices unavailable:

This error originated from a custom integration.

Logger: custom_components.midea_dehumidifier_lan.hub
Source: custom_components/midea_dehumidifier_lan/api.py:52
Integration: Midea Air Appliances (LAN) (documentation, issues)
First occurred: 17:34:20 (1 occurrences)
Last logged: 17:34:20

Error while setting appliance id=20890720935792 sn=000000P0000000Q1847C9B43CC8B0000 ip=192.168.1.126: Failed to perform handshake for sn=000000P0000000Q1847C9B43CC8B0000 id=20890720935792 address=192.168.1.126 version=3
Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/custom_components/midea_dehumidifier_lan/hub.py", line 515, in _process_appliance
    appliance = await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/midea_dehumidifier_lan/api.py", line 52, in appliance_state
    return midea_beautiful_api.appliance_state(
  File "/srv/homeassistant/lib/python3.9/site-packages/midea_beautiful/__init__.py", line 130, in appliance_state
    return get_appliance_state(
  File "/srv/homeassistant/lib/python3.9/site-packages/midea_beautiful/lan.py", line 950, in get_appliance_state
    appliance.identify(cloud, use_cloud)
  File "/srv/homeassistant/lib/python3.9/site-packages/midea_beautiful/lan.py", line 746, in identify
    self._valid_token(cloud)
  File "/srv/homeassistant/lib/python3.9/site-packages/midea_beautiful/lan.py", line 731, in _valid_token
    self._authenticate()
  File "/srv/homeassistant/lib/python3.9/site-packages/midea_beautiful/lan.py", line 503, in _authenticate
    raise AuthenticationError(f"Failed to perform handshake for {self}")
midea_beautiful.exceptions.AuthenticationError: Failed to perform handshake for sn=000000P0000000Q1847C9B43CC8B0000 id=20890720935792 address=192.168.1.126 version=3

and

This error originated from a custom integration.

Logger: custom_components.midea_dehumidifier_lan.hub
Source: custom_components/midea_dehumidifier_lan/api.py:52
Integration: Midea Air Appliances (LAN) (documentation, issues)
First occurred: 17:32:53 (6 occurrences)
Last logged: 17:37:14

Error while setting appliance id=31885837219292 sn=000000P0000000Q1847C9B6827520000 ip=192.168.1.132: Timeout while connecting to appliance 192.168.1.132:6445
Error while setting appliance id=20890720935792 sn=000000P0000000Q1847C9B43CC8B0000 ip=192.168.1.126: Timeout while connecting to appliance 192.168.1.126:6445
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.9/site-packages/midea_beautiful/lan.py", line 917, in get_appliance_state
    response = sock.recv(512)
socket.timeout: timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/custom_components/midea_dehumidifier_lan/hub.py", line 515, in _process_appliance
    appliance = await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/midea_dehumidifier_lan/api.py", line 52, in appliance_state
    return midea_beautiful_api.appliance_state(
  File "/srv/homeassistant/lib/python3.9/site-packages/midea_beautiful/__init__.py", line 130, in appliance_state
    return get_appliance_state(
  File "/srv/homeassistant/lib/python3.9/site-packages/midea_beautiful/lan.py", line 926, in get_appliance_state
    raise MideaNetworkError(
midea_beautiful.exceptions.MideaNetworkError: Timeout while connecting to appliance 192.168.1.132:6445
nbogojevic commented 2 years ago

thanks @gsportelli , can reproduce the problem now.

nbogojevic commented 2 years ago

I have updated beta version with code that should handle unavailable devices correctly at startup. It should also be able to detect them once they come online. Can you give it a try?

gsportelli commented 2 years ago

I have updated beta version with code that should handle unavailable devices correctly at startup. It should also be able to detect them once they come online. Can you give it a try?

Now it works, thanks!