From aca2b8f471a1e0f3d5351cbdb4fb39055e6db210 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Thu, 15 Feb 2024 10:33:31 +0100 Subject: [PATCH] Fix HomeAssistant provider on supervised installs (#1082) --- .../server/providers/hass/__init__.py | 58 ++++++++++++++----- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/music_assistant/server/providers/hass/__init__.py b/music_assistant/server/providers/hass/__init__.py index 3d951e3a3..42cecec3c 100644 --- a/music_assistant/server/providers/hass/__init__.py +++ b/music_assistant/server/providers/hass/__init__.py @@ -91,30 +91,58 @@ async def get_config_entries( # set the retrieved token on the values object to pass along values[CONF_AUTH_TOKEN] = long_lived_token - entries = () - if not await async_is_supervisor(): - entries = ( + if await async_is_supervisor(): + # on supervisor, we use the internal url + # token set to None for auto retrieval + return ( ConfigEntry( key=CONF_URL, type=ConfigEntryType.STRING, - label="URL", + label=CONF_URL, required=True, - description="URL to your Home Assistant instance (e.g. http://192.168.1.1:8123)", - value=values.get(CONF_URL) if values else None, + default_value="http://supervisor/core/api", + value="http://supervisor/core/api", ), ConfigEntry( key=CONF_AUTH_TOKEN, - type=ConfigEntryType.SECURE_STRING, - label="Authentication token for HomeAssistant", - description="You need to link Music Assistant to your Home Assistant instance.", - action=CONF_ACTION_AUTH, - action_label="Authenticate Home Assistant", - depends_on=CONF_URL, - value=values.get(CONF_AUTH_TOKEN) if values else None, + type=ConfigEntryType.STRING, + label=CONF_AUTH_TOKEN, + required=False, + default_value=None, + value=None, ), ) - - return entries + # manual configuration + return ( + ConfigEntry( + key=CONF_URL, + type=ConfigEntryType.STRING, + label="URL", + required=True, + description="URL to your Home Assistant instance (e.g. http://192.168.1.1:8123)", + value=values.get(CONF_URL) if values else None, + ), + ConfigEntry( + key=CONF_ACTION_AUTH, + type=ConfigEntryType.ACTION, + label="(re)Authenticate Home Assistant", + description="Authenticate to your home assistant " + "instance and generate the long lived token.", + action=CONF_ACTION_AUTH, + depends_on=CONF_URL, + required=False, + ), + ConfigEntry( + key=CONF_AUTH_TOKEN, + type=ConfigEntryType.SECURE_STRING, + label="Authentication token for HomeAssistant", + description="You can either paste a Long Lived Token here manually or use the " + "'authenticate' button to generate a token for you with logging in.", + depends_on=CONF_URL, + value=values.get(CONF_AUTH_TOKEN) if values else None, + advanced=True, + ), + ) class HomeAssistant(PluginProvider):