natekspencer / hacs-vivint

Home Assistant integration for a Vivint home security system.
MIT License
66 stars 5 forks source link

Web socket errors to Vivint API #5

Closed mat1583 closed 3 years ago

mat1583 commented 3 years ago

Before upgrading to latest version, I restarted HA for an unrelated reason. Upon restart, HA was unresponsive for nearly 9-10 minutes. Once it was responsive again, the logs showed many errors trying to setup the initial connection to Vivint and updating Vivint sensors via the api. There was a 500 second timeout setting up the connection, which also locked up the rest of HA for that time period. I tried installing the latest version, deleted the current integration, restarted HA, and reinstalled the Vivint integration. Same result. I had to disable the integration completely for the time being.

Traceback for some of the socket errors:

Logger: homeassistant.components.sensor Source: custom_components/vivint/init.py:167 Integration: Sensor (documentation, issues) First occurred: 9:46:10 PM (2 occurrences) Last logged: 9:50:32 PM

Error adding entities for domain sensor with platform vivint Error while setting up vivint platform for sensor Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 969, in _wrap_create_connection return await self._loop.create_connection(*args, **kwargs) # type: ignore # noqa File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1025, in create_connection raise exceptions[0] File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1010, in create_connection sock = await self._connect_sock( File "/usr/local/lib/python3.8/asyncio/base_events.py", line 924, in _connect_sock await self.sock_connect(sock, address) File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 496, in sock_connect return await fut File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 528, in _sock_connect_cb raise OSError(err, f'Connect call failed {address}') TimeoutError: [Errno 110] Connect call failed ('23.253.164.235', 80)

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

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 317, in async_add_entities await asyncio.gather(tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 385, in _async_add_entity device_info = entity.device_info File "/config/custom_components/vivint/init.py", line 167, in device_info "manufacturer": self.device.manufacturer, File "/usr/local/lib/python3.8/site-packages/vivintpy/devices/init.py", line 86, in manufacturer self.get_zwave_details() File "/usr/local/lib/python3.8/site-packages/vivintpy/devices/init.py", line 134, in get_zwave_details result = pool.submit(asyncio.run, self.get_zwave_details_async()).result() File "/usr/local/lib/python3.8/concurrent/futures/_base.py", line 439, in result return self.get_result() File "/usr/local/lib/python3.8/concurrent/futures/_base.py", line 388, in get_result raise self._exception File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(self.args, **self.kwargs) File "/usr/local/lib/python3.8/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/usr/local/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete return future.result() File "/usr/local/lib/python3.8/site-packages/vivintpy/devices/init.py", line 141, in get_zwave_details_async result = await self.vivintskyapi.get_zwave_details( File "/usr/local/lib/python3.8/site-packages/vivintpy/vivintskyapi.py", line 401, in get_zwave_details async with session.get( File "/usr/local/lib/python3.8/site-packages/aiohttp/client.py", line 1117, in aenter self._resp = await self._coro File "/usr/local/lib/python3.8/site-packages/aiohttp/client.py", line 520, in _request conn = await self._connector.connect( File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 535, in connect proto = await self._create_connection(req, traces, timeout) File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 892, in _createconnection , proto = await self._create_direct_connection(req, traces, timeout) File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 1051, in _create_direct_connection raise last_exc File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection transp, proto = await self._wrap_create_connection( File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 975, in _wrap_create_connection raise client_error(req.connection_key, exc) from exc aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host openzwave.net:80 ssl:default [Connect call failed ('23.253.164.235', 80)]

natekspencer commented 3 years ago

This should be fixed with 2021.3.1

mat1583 commented 3 years ago

I had previously attempted an update from a fresh install with the same result. What finally seemed to work was logging into my API user in the Vivint mobile app, then signing out of all devices. Once I did that, the integration started working again. My best guess according to the log messages is that a web socket connection was left open for that api user and the integration could not establish a new connection.

If this is the case, then I would still consider this an issue. If the web socket create attempt fails, then it should not attempt to update any of the Vivint devices. Each device update took 10 seconds to timeout, and it seems the attempts were in serial. That left HA unresponsive during that period.

Let me know if you need to see any other logs.

natekspencer commented 3 years ago

The logs you posted here all directly point to an issue with the way I was retrieving Z-Wave device details for such devices connected to the panel.

TimeoutError: [Errno 110] Connect call failed ('23.253.164.235', 80)

That's the IP address of the openzwave website I was using for device lookup. If you try to go to that address, or ping it even, you'll see that it is taking a long time or down altogether now.

File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 317, in async_add_entities await asyncio.gather(*tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 385, in _async_add_entity device_info = entity.device_info File "/config/custom_components/vivint/init.py", line 167, in device_info "manufacturer": self.device.manufacturer, File "/usr/local/lib/python3.8/site-packages/vivintpy/devices/init.py", line 86, in manufacturer self.get_zwave_details()

Here, again, you'll see it is when trying to save the device_info, which does a lookup for manufacturer, which, if Z-Wave, would try to get the information from openzwave and hang.

I knew it might be a potential problem in the future, and have been thinking of ways to get around it, but haven't done so yet. So for now, Z-wave devices will just show an unknown manufacturer and model until I get that updated.

mat1583 commented 3 years ago

Makes sense. Thanks for the explanation. I think there was still some web socket connection issue going on, but those logs have cleared after I signed out of all devices. If the issue pops up again, I'll make sure to enable more verbose logging and update this issue.

natekspencer commented 3 years ago

I'm gonna close this issue. But if you do see some websocket stuff, open up a new one so I can help track it there. Thanks, @mat1583!