jeatheak / Mitsubishi-WF-RAC-Integration

WF-RAC homeassistant integration
MIT License
125 stars 23 forks source link

Handle connection errors gracefully #57

Open hmmbob opened 1 year ago

hmmbob commented 1 year ago

Every now and then HA doesn't get an answer from any of my airco's (I have 4) and throws a long error. It would be great if this error is caught and handled nicely.

2023-09-07 09:26:50.772 ERROR (MainThread) [custom_components.mitsubishi_wf_rac.wfrac.device] Error: something went wrong updating the airco [Airco ec0baefc92e4] values
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 466, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 461, in _make_request
httplib_response = conn.getresponse()
^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/http/client.py", line 1378, in getresponse
response.begin()
File "/usr/local/lib/python3.11/http/client.py", line 318, in begin
version, status, reason = self._read_status()
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/http/client.py", line 279, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/socket.py", line 706, in readinto
return self._sock.recv_into(b)
^^^^^^^^^^^^^^^^^^^^^^^
TimeoutError: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/requests/adapters.py", line 486, in send
resp = conn.urlopen(
^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 798, in urlopen
retries = retries.increment(
^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/urllib3/util/retry.py", line 550, in increment
raise six.reraise(type(error), error, _stacktrace)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/urllib3/packages/six.py", line 770, in reraise
raise value
File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 714, in urlopen
httplib_response = self._make_request(
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 468, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 357, in _raise_timeout
raise ReadTimeoutError(
urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='192.168.1.221', port=51443): Read timed out. (read timeout=30)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/mitsubishi_wf_rac/wfrac/device.py", line 53, in update
response = await self._api.get_aircon_stats()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/mitsubishi_wf_rac/wfrac/repository.py", line 110, in get_aircon_stats
result = await self._post("getAirconStat")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/mitsubishi_wf_rac/wfrac/repository.py", line 66, in _post
response = await self._hass.async_add_executor_job(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/requests/api.py", line 115, in post
return request("post", url, data=data, json=json, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/requests/api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/requests/adapters.py", line 532, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='192.168.1.221', port=51443): Read timed out. (read timeout=30)
vaneeten commented 1 year ago

First of all, thank you for taking the trouble to write this integration!

I'm having a very similar problem here, also with 4 airco units. After about every reboot, one of the four does not come to live, with a log message like this:

Logger: custom_components.mitsubishi_wf_rac.wfrac.device
Source: custom_components/mitsubishi_wf_rac/wfrac/repository.py:66 
Integration: Mitsubishi WF-RAC ([documentation](https://github.com/jeatheak/Mitsubishi-WF-RAC-Integration/)) 
First occurred: 4:34:35 PM (1 occurrences) 
Last logged: 4:34:35 PM

Error: something went wrong updating the airco [Airco werkkamer] values
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 95, in create_connection
    raise err
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 85, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

which then triggers a cascade of errors in the log.

It's not always the same unit that doesn't work. Sometimes, after a series of HA restarts, all 4 work so I wouldn't expect some actual incompatibility. As the official Smart M-Air app itself also takes several seconds to connect to the 4 units, and even had some real trouble keeping all 4 units connected when I didn't use their cloud account yet, I suspect that connection failures are to be expected and retried periodically with this interface.

KixAss commented 8 months ago

First of all, thank you for taking the trouble to write this integration!

I'm having a very similar problem here, also with 4 airco units. After about every reboot, one of the four does not come to live, with a log message like this:

Logger: custom_components.mitsubishi_wf_rac.wfrac.device
Source: custom_components/mitsubishi_wf_rac/wfrac/repository.py:66 
Integration: Mitsubishi WF-RAC ([documentation](https://github.com/jeatheak/Mitsubishi-WF-RAC-Integration/)) 
First occurred: 4:34:35 PM (1 occurrences) 
Last logged: 4:34:35 PM

Error: something went wrong updating the airco [Airco werkkamer] values
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 95, in create_connection
    raise err
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 85, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

which then triggers a cascade of errors in the log.

It's not always the same unit that doesn't work. Sometimes, after a series of HA restarts, all 4 work so I wouldn't expect some actual incompatibility. As the official Smart M-Air app itself also takes several seconds to connect to the 4 units, and even had some real trouble keeping all 4 units connected when I didn't use their cloud account yet, I suspect that connection failures are to be expected and retried periodically with this interface.

Same problem here. 3 units and often when I reboot Home Assistant, 1 of 2 don't connect.

airco log.txt

vinzouilleus commented 7 months ago

First of all, thank you for taking the trouble to write this integration! I'm having a very similar problem here, also with 4 airco units. After about every reboot, one of the four does not come to live, with a log message like this:

Logger: custom_components.mitsubishi_wf_rac.wfrac.device
Source: custom_components/mitsubishi_wf_rac/wfrac/repository.py:66 
Integration: Mitsubishi WF-RAC ([documentation](https://github.com/jeatheak/Mitsubishi-WF-RAC-Integration/)) 
First occurred: 4:34:35 PM (1 occurrences) 
Last logged: 4:34:35 PM

Error: something went wrong updating the airco [Airco werkkamer] values
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 95, in create_connection
    raise err
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 85, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

which then triggers a cascade of errors in the log. It's not always the same unit that doesn't work. Sometimes, after a series of HA restarts, all 4 work so I wouldn't expect some actual incompatibility. As the official Smart M-Air app itself also takes several seconds to connect to the 4 units, and even had some real trouble keeping all 4 units connected when I didn't use their cloud account yet, I suspect that connection failures are to be expected and retried periodically with this interface.

Same problem here. 3 units and often when I reboot Home Assistant, 1 of 2 don't connect.

airco log.txt

Same here as well. After a HA Core update for example, I typically have to restart HA a few more times to ensure all AC entities are visible again.