diff --git a/custom_components/unraid_docker/__init__.py b/custom_components/unraid_docker/__init__.py index 4a6f21a..d62ddec 100644 --- a/custom_components/unraid_docker/__init__.py +++ b/custom_components/unraid_docker/__init__.py @@ -50,11 +50,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Setzt eine ConfigEntry Instanz auf.""" hass.data.setdefault(DOMAIN, {}) + host = entry.data[CONF_HOST] + port = entry.data[CONF_PORT] + username = entry.data[CONF_USERNAME] + secret = str(entry.data[CONF_PASSWORD]) + config = UnraidConnectionConfig( - host=entry.data[CONF_HOST], - port=entry.data[CONF_PORT], - username=entry.data[CONF_USERNAME], - password=entry.data[CONF_PASSWORD], + host=host, + port=port, + username=username, + password=secret, known_hosts=entry.data.get(CONF_KNOWN_HOSTS), ) diff --git a/custom_components/unraid_docker/config_flow.py b/custom_components/unraid_docker/config_flow.py index c11db0b..9fab4e9 100644 --- a/custom_components/unraid_docker/config_flow.py +++ b/custom_components/unraid_docker/config_flow.py @@ -33,14 +33,19 @@ async def async_step_user(self, user_input: dict[str, Any] | None = None): errors: dict[str, str] = {} if user_input is not None: - await self.async_set_unique_id(f"{user_input[CONF_USERNAME]}@{user_input[CONF_HOST]}") + host = user_input[CONF_HOST] + username = user_input[CONF_USERNAME] + secret = str(user_input[CONF_PASSWORD]) + port = int(user_input[CONF_PORT]) + + await self.async_set_unique_id(f"{username}@{host}") self._abort_if_unique_id_configured() connection_config = UnraidConnectionConfig( - host=user_input[CONF_HOST], - port=user_input[CONF_PORT], - username=user_input[CONF_USERNAME], - password=user_input[CONF_PASSWORD], + host=host, + port=port, + username=username, + password=secret, known_hosts=user_input.get(CONF_KNOWN_HOSTS), ) api = UnraidApiClient(connection_config) @@ -55,23 +60,23 @@ async def async_step_user(self, user_input: dict[str, Any] | None = None): except Exception: # pragma: no cover - Schutz fuer unerwartete Fehler _LOGGER.exception( "Unerwarteter Fehler im Config Flow fuer Host=%s Benutzer=%s", - user_input.get(CONF_HOST), - user_input.get(CONF_USERNAME), + host, + username, ) errors["base"] = "cannot_connect" else: data = { - CONF_HOST: user_input[CONF_HOST], - CONF_PORT: user_input[CONF_PORT], - CONF_USERNAME: user_input[CONF_USERNAME], - CONF_PASSWORD: user_input[CONF_PASSWORD], + CONF_HOST: host, + CONF_PORT: port, + CONF_USERNAME: username, + CONF_PASSWORD: secret, CONF_KNOWN_HOSTS: user_input.get(CONF_KNOWN_HOSTS, ""), } options = { CONF_SCAN_INTERVAL: user_input[CONF_SCAN_INTERVAL], } return self.async_create_entry( - title=f"{user_input[CONF_HOST]}", + title=f"{host}", data=data, options=options, )