BottlecapDave / HomeAssistant-OctopusEnergy

Unofficial Home Assistant integration for interacting with Octopus Energy
https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/
MIT License
612 stars 61 forks source link

Potential connectivity issue #654

Closed djdarlo closed 11 months ago

djdarlo commented 11 months ago

Describe the bug

Integration not initialising

Reproduction steps

Restart RPi. Integration not initialised.

Expected behaviour

Rates available

Tariff Code

Na

Integration Version

Latest

Home Assistant Version

Latest

Fresh Install?

Not specified

Home Assistant Logs

Logger: homeassistant.config_entries Source: config_entries.py:402 First occurred: 3:21:42 AM (1 occurrences) Last logged: 3:21:42 AM

Error setting up entry A-B90F354E for octopus_energy Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 1173, in _create_direct_connection hosts = await asyncio.shield(host_resolved) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 884, 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 402, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/octopus_energy/init.py", line 83, in async_setup_entry await async_setup_dependencies(hass, config) File "/config/custom_components/octopus_energy/init.py", line 128, in async_setup_dependencies account_info = await client.async_get_account(config[CONFIG_MAIN_ACCOUNT_ID]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/octopus_energy/api_client/init.py", line 411, in async_get_account await self.async_refresh_token() File "/config/custom_components/octopus_energy/api_client/init.py", line 393, in async_refresh_token async with client.post(url, json=payload) as token_response: File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 1187, in aenter self._resp = await self._coro ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 574, in _request conn = await self._connector.connect( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 544, in connect proto = await self._create_connection(req, traces, timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 911, in _createconnection , proto = await self._create_direct_connection(req, traces, timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 1187, in _create_direct_connection raise ClientConnectorError(req.connection_key, exc) from exc aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host api.octopus.energy:443 ssl:default [Try again]

Confirmation

BottlecapDave commented 11 months ago

Hello. Due to this being a cloud based integration, this can happen from time to time either through local internet connectivity or the APIs being unavailable for whatever reason. The integration requires this data in order to give you the most accurate sensors for your account. For these reasons, there is very little I can do with this issue.

You can reload the integration by going to the integrations page within your HA settings, click the three dots and then click reload. This will attempt to start the integration again.

Jilas commented 11 months ago

Hi there,

Just got caught out by this again today as I missed the fact it didn't load after a server reboot.

While there is nothing you can do regarding octopus being unavailable.... Is there any way to trap the error and get the integration to retry Vs just crashing?

Cheers,

BottlecapDave commented 11 months ago

I'm planning on looking in this area soonish, so I'll see what I can do (but no promises)

Jilas commented 11 months ago

Many thanks. At the very basic, a simple boolean that is flagged as true by the add-on when it's running. Then if it fails (so becoming unavailable). It's easy to monitor and similar to say running state that z2m and similar have.

After that then it could get interesting if you wanted additional entities to show errors or issues. This I guess would be per meter, as then you can show specific errors, which could help people to report issues. This is much more complex if possible.

Thanks for considering and having it on the road map.