hassio-addons / addon-appdaemon

AppDaemon4 - Home Assistant Community Add-ons
https://addons.community
MIT License
151 stars 47 forks source link

4.2.3 addon cannot read HA config #236

Closed realthk closed 1 year ago

realthk commented 1 year ago

Problem/Motivation

Updating to 4.2.3 (425810d) breaks my Appdaemon-HAOS connection. Appdaemon cannot read HA config, log entry is produced every 5 seconds:

2023-03-11 09:29:23.448992 INFO AppDaemon: Found 16 active apps
2023-03-11 09:29:23.449711 INFO AppDaemon: Found 0 inactive apps
2023-03-11 09:29:23.450401 INFO AppDaemon: Found 0 global libraries
2023-03-11 09:29:23.451158 INFO AppDaemon: Starting Apps with 16 workers and 16 pins
2023-03-11 09:29:23.461464 INFO AppDaemon: Running on port 5050
2023-03-11 09:29:28.404466 INFO HASS: Connected to Home Assistant 2023.3.3
2023-03-11 09:29:28.431791 WARNING HASS: Error getting metadata - retrying: Only absolute URLs without path part are supported
2023-03-11 09:29:28.433889 WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds
2023-03-11 09:29:33.483247 INFO HASS: Connected to Home Assistant 2023.3.3
2023-03-11 09:29:33.511294 WARNING HASS: Error getting metadata - retrying: Only absolute URLs without path part are supported
2023-03-11 09:29:33.513121 WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds
2023-03-11 09:29:38.547054 INFO HASS: Connected to Home Assistant 2023.3.3
2023-03-11 09:29:38.574837 WARNING HASS: Error getting metadata - retrying: Only absolute URLs without path part are supported
2023-03-11 09:29:38.577056 WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds

I believe this must coming be from this line: https://github.com/AppDaemon/appdaemon/blob/dev/appdaemon/plugins/hass/hassplugin.py#L750 which is strange, according to the doc of this addon, there is no need for ha_url and token options, so I don't have those in my appdaemon config, only this:

secrets: /config/secrets.yaml
appdaemon:
  latitude: 46.xxxxxx
  longitude: 19.xxxxxx
  elevation: 80
  time_zone: Europe/Budapest
  utility_delay: 5
  utility_skew: 4
  plugins:
    HASS:
      type: hass
  exclude_dirs:
    - .git
http:
  url: http://127.0.0.1:5050
admin:
api:
hadashboard:
logs:
  main_log:
    filename: /config/appdaemon/logs/appdaemon.log
    log_generations: 3
    log_size: 50000
  access_log:
    filename: /config/appdaemon/logs/access.log
  error_log:
    filename: /config/appdaemon/logs/error.log
  diag_log:
    filename: /config/appdaemon/logs/diag.log
    log_generations: 3
    log_size: 1024
    format: "{asctime} {levelname:<8} {appname:<10}: {message}"

(and this was enough for version 4.2.1 indeed. After restoring backup of 1d6ea93 it works again)

chatziko commented 1 year ago

Same problem for me, here's some DEBUG logs with a stacktrace:


2023-03-11 11:49:21.143701 INFO HASS: Connected to Home Assistant 2023.3.3
2023-03-11 11:49:21.144109 DEBUG AppDaemon: thread_async loop, args={'function': <bound method Events.process_event of <appdaemon.events.Events object at 0x7f44abd8d960>>, 'args': ('admin', {'event_type': '__AD_LOG_EVENT', 'data': {'level': 'INFO', 'app_name': 'HASS', 'message': 'Connected to Home Assistant 2023.3.3', 'type': 'log', 'log_type': 'main_log', 'asctime': '2023-03-11 11:49:21.143766', 'ts': datetime.datetime(2023, 3, 11, 11, 49, 21, 143556), 'formatted_message': '2023-03-11 11:49:21.143766 INFO HASS: Connected to Home Assistant 2023.3.3'}}), 'kwargs': {}}
2023-03-11 11:49:21.144732 DEBUG AppDaemon: Event type:__AD_LOG_EVENT:
2023-03-11 11:49:21.144966 DEBUG AppDaemon: {'level': 'INFO', 'app_name': 'HASS', 'message': 'Connected to Home Assistant 2023.3.3', 'type': 'log', 'log_type': 'main_log', 'asctime': '2023-03-11 11:49:21.143766', 'ts': datetime.datetime(2023, 3, 11, 11, 49, 21, 143556), 'formatted_message': '2023-03-11 11:49:21.143766 INFO HASS: Connected to Home Assistant 2023.3.3'}
2023-03-11 11:49:21.145188 DEBUG AppDaemon: process_event_callbacks() admin {'event_type': '__AD_LOG_EVENT', 'data': {'level': 'INFO', 'app_name': 'HASS', 'message': 'Connected to Home Assistant 2023.3.3', 'type': 'log', 'log_type': 'main_log', 'asctime': '2023-03-11 11:49:21.143766', 'ts': datetime.datetime(2023, 3, 11, 11, 49, 21, 143556), 'formatted_message': '2023-03-11 11:49:21.143766 INFO HASS: Connected to Home Assistant 2023.3.3'}}
2023-03-11 11:49:21.145492 DEBUG AppDaemon: thread_async loop, args={'function': <bound method ADStream.process_event of <appdaemon.stream.adstream.ADStream object at 0x7f44ab2cc370>>, 'args': ({'event_type': '__AD_LOG_EVENT', 'data': {'level': 'INFO', 'app_name': 'HASS', 'message': 'Connected to Home Assistant 2023.3.3', 'type': 'log', 'log_type': 'main_log', 'asctime': '2023-03-11 11:49:21.143766', 'formatted_message': '2023-03-11 11:49:21.143766 INFO HASS: Connected to Home Assistant 2023.3.3'}, 'namespace': 'admin'},), 'kwargs': {}}
2023-03-11 11:49:21.147954 DEBUG HASS: get_ha_config()
2023-03-11 11:49:21.148085 DEBUG HASS: get_ha_config: url is /api/config
2023-03-11 11:49:21.148372 WARNING HASS: Error getting metadata - retrying: Only absolute URLs without path part are supported
2023-03-11 11:49:21.148538 DEBUG AppDaemon: Clearing callbacks for HASS
2023-03-11 11:49:21.148658 WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds
2023-03-11 11:49:21.148794 DEBUG HASS: ------------------------------------------------------------
2023-03-11 11:49:21.148935 DEBUG HASS: Unexpected error:
2023-03-11 11:49:21.149037 DEBUG HASS: ------------------------------------------------------------
2023-03-11 11:49:21.149257 DEBUG HASS: Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/appdaemon/plugins/hass/hassplugin.py", line 343, in get_updates
    self.metadata = await self.get_hass_config()
  File "/usr/lib/python3.10/site-packages/appdaemon/plugins/hass/hassplugin.py", line 700, in get_hass_config
    r = await self.session.get(api_url)
  File "/usr/lib/python3.10/site-packages/appdaemon/plugins/hass/hassplugin.py", line 118, in session
    self._session = aiohttp.ClientSession(
  File "/usr/lib/python3.10/site-packages/aiohttp/client.py", line 235, in __init__
    self._base_url.origin() == self._base_url
AssertionError: Only absolute URLs without path part are supported```
chatziko commented 1 year ago

Digging into it, the latest AppDaemon passes base_url to aiohttp.ClientSession:

https://github.com/AppDaemon/appdaemon/blob/99702b931a2ae7aaf2a6413bd827fb47ca9cf931/appdaemon/plugins/hass/hassplugin.py#L150-L155

base_url should be a URL without path:

https://github.com/aio-libs/aiohttp/blob/3ff81dc9c9ce20efd3bf54cf52adaf438c483a92/aiohttp/client.py#L220-L223

However the addon sets ha_url = "http://supervisor/core", causing the above check to fail.

chatziko commented 1 year ago

A workaround is to generate an access token and pass ha_url and token manually in appdaemon.yaml, as described here.

github-actions[bot] commented 1 year ago

There hasn't been any activity on this issue recently, so we clean up some of the older and inactive issues. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by leaving a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thanks!