thomasloven / hass-plejd

🔹 Plejd BLE integration for Home Assistant
81 stars 10 forks source link

Won't start if no access to Plejd API at boot #37

Closed mudape closed 5 months ago

mudape commented 10 months ago

Hello, First, thanks for this integration which works perfect for me!

Noticed an issue when HA was restarted while we had an Internet outage, then no connection to Plejd mesh. Could a fallback to use already stored info when/if Plejd API is unavailable be added? In the spirit of local access :)

This error originated from a custom integration.

Logger: homeassistant.config_entries 
Source: custom_components/plejd/__init__.py:26 
Integration: Plejd (documentation) 
First occurred: 09:39:33 (1 occurrences) 
Last logged: 09:39:33 

Error setting up entry <my-plejd-site-name> for plejd 
Traceback (most recent call last): 
File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 1155, in _create_direct_connection 
hosts = await asyncio.shield(host_resolved) 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 874, in _resolve_host 
addrs = await self._resolver.resolve(host, port, family=self._family) 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

File "/usr/local/lib/python3.11/site-packages/aiohttp/resolver.py", line 33, in resolve 
infos = await self._loop.getaddrinfo( 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

File "/usr/local/lib/python3.11/asyncio/base_events.py", line 867, in getaddrinfo 
return await self.run_in_executor( 
^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

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/socket.py", line 962, in getaddrinfo 
for res in _socket.getaddrinfo(host, port, family, type, proto, flags): 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

socket.gaierror: [Errno -3] Try again 
The above exception was the direct cause of the following exception: 
Traceback (most recent call last): 
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 388, in async_setup 
result = await component.async_setup_entry(hass, self) 

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

File "/config/custom_components/plejd/__init__.py", line 26, in async_setup_entry 
await plejdManager.init() 
File "/usr/local/lib/python3.11/site-packages/pyplejd/__init__.py", line 35, in init 
await self.cloud.ensure_details_loaded() 
File "/usr/local/lib/python3.11/site-packages/pyplejd/cloud/__init__.py", line 75, in ensure_details_loaded 
await self.get_details() 

File "/usr/local/lib/python3.11/site-packages/pyplejd/cloud/__init__.py", line 63, in get_details 
await _set_session_token(session, self.username, self.password) 

File "/usr/local/lib/python3.11/site-packages/pyplejd/cloud/__init__.py", line 26, in _set_session_token 
resp = await session.post( 
^^^^^^^^^^^^^^^^^^^ 

File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 536, in _request 
conn = await self._connector.connect( 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 540, in connect 
proto = await self._create_connection(req, traces, timeout) 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 901, in _create_connection 
_, proto = await self._create_direct_connection(req, traces, timeout) 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 1169, in _create_direct_connection 
raise ClientConnectorError(req.connection_key, exc) from exc 
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host cloud.plejd.com:443 ssl:default [Try again] 
thomasloven commented 10 months ago

Thanks. I've realized this may happen, and it's on my todo list to cache the cloud data between restarts. Expect it soon.

thomasloven commented 6 months ago

0.6.0 has been released and should fix this.