bramstroker / homeassistant-powercalc

Custom component to calculate estimated power consumption of lights and other appliances
MIT License
956 stars 252 forks source link

Plugin no longer working in offline mode #2296

Closed pmffromspace closed 3 months ago

pmffromspace commented 3 months ago

System Health details

dockerized homeassistant in a offline lan

Checklist

Describe the issue

Altough there is someone else with a similar issue, I think my issue is still different. I am using my homassistant and smarthome of in a isolated network (only temporarly internet connetctivity when I do updates) and I like it that way. Recent updates of this plugin however rendered the plugin useless when the plugin is loaded / homassistant boots without internet connectivity.

For now I need to disable the plugin, I would love to see this fixed for offline installations like mine. Will this be adressed? kind regards

Reproduction steps

  1. disable internet connection for homeassistant instance
  2. restart homeassistant
  3. get notification with the link to the error logs like below

Debug logs

Logger: homeassistant.setup
Quelle: setup.py:402
Erstmals aufgetreten: 02:31:31 (1 Vorkommnisse)
Zuletzt protokolliert: 02:31:31

Error during setup of component powercalc
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1203, in _create_direct_connection
    hosts = await self._resolve_host(host, port, traces=traces)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 880, in _resolve_host
    return await asyncio.shield(resolved_host_task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 917, in _resolve_host_with_throttle
    addrs = await self._resolver.resolve(host, port, family=self._family)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/resolver.py", line 33, in resolve
    infos = await self._loop.getaddrinfo(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 899, in getaddrinfo
    return await self.run_in_executor(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/socket.py", line 963, 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/setup.py", line 402, in _async_setup_component
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/powercalc/__init__.py", line 240, in async_setup
    await discovery_manager.start_discovery()
  File "/config/custom_components/powercalc/discovery.py", line 123, in start_discovery
    power_profile = await self.get_power_profile(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/powercalc/discovery.py", line 144, in get_power_profile
    self.power_profiles[entity_id] = await get_power_profile(
                                     ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/powercalc/power_profile/factory.py", line 39, in get_power_profile
    library = await ProfileLibrary.factory(hass)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/powercalc/power_profile/library.py", line 49, in factory
    await library.initialize()
  File "/config/custom_components/powercalc/power_profile/library.py", line 35, in initialize
    await self._loader.initialize()
  File "/config/custom_components/powercalc/power_profile/loader/composite.py", line 14, in initialize
    [await loader.initialize() for loader in self.loaders]  # type: ignore[func-returns-value]
     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/powercalc/power_profile/loader/remote.py", line 36, in initialize
    self.library_contents = await self.load_library_json()
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/powercalc/power_profile/loader/remote.py", line 60, in load_library_json
    async with aiohttp.ClientSession() as session, session.get(ENDPOINT_LIBRARY) as resp:
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 1197, in __aenter__
    self._resp = await self._coro
                 ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 581, in _request
    conn = await self._connector.connect(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 544, in connect
    proto = await self._create_connection(req, traces, timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 944, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1209, in _create_direct_connection
    raise ClientConnectorError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host powercalc.lauwbier.nl:443 ssl:default [Try again]

Diagnostics dump or YAML config

No response

bramstroker commented 3 months ago

@pmffromspace Please see https://homeassistant-powercalc.readthedocs.io/en/latest/library/library.html#disable-download-feature.

I have added that option when implementing the download feature for people who like to fully operate locally. The drawback is you'll need to manage downloading the profiles yourself.

Let me know when you have any further questions.

pmffromspace commented 3 months ago

Thanks for the quick reply