From 8e7a3f58229313b377b46941f9b4721c059355df Mon Sep 17 00:00:00 2001 From: Pedro Ribeiro Date: Tue, 28 Nov 2023 22:59:57 +0000 Subject: [PATCH] Rademacher Componentes not available after Restart Fixes #99 --- custom_components/rademacher/__init__.py | 2 ++ custom_components/rademacher/config_flow.py | 37 ++++++++++++++++++--- custom_components/rademacher/manifest.json | 2 +- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/custom_components/rademacher/__init__.py b/custom_components/rademacher/__init__.py index 1768cb7..5306ad1 100644 --- a/custom_components/rademacher/__init__.py +++ b/custom_components/rademacher/__init__.py @@ -12,6 +12,7 @@ CONF_HOST, CONF_PASSWORD, CONF_SENSOR_TYPE, + CONF_API_VERSION ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.device_registry import DeviceEntry, DeviceRegistry, format_mac @@ -95,6 +96,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: api = HomePilotApi( entry.data[CONF_HOST], entry.data[CONF_PASSWORD] if CONF_PASSWORD in entry.data else "", + entry.data[CONF_API_VERSION], ) try: manager = await HomePilotManager.async_build_manager(api) diff --git a/custom_components/rademacher/config_flow.py b/custom_components/rademacher/config_flow.py index d055e24..85779f4 100644 --- a/custom_components/rademacher/config_flow.py +++ b/custom_components/rademacher/config_flow.py @@ -15,6 +15,7 @@ CONF_HOST, CONF_PASSWORD, CONF_SENSOR_TYPE, + CONF_API_VERSION ) from homepilot.manager import HomePilotManager @@ -35,6 +36,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL host: str = "" password: str = "" + api_version: int = 1 mac_address: str = "" hostname: str = "" reauth_entry: ConfigEntry | None = None @@ -54,6 +56,7 @@ async def async_step_config(self, user_input=None): data = { CONF_HOST: self.host, CONF_PASSWORD: self.password, + CONF_API_VERSION: self.api_version } options = { CONF_EXCLUDE: self.exclude_devices, @@ -66,7 +69,7 @@ async def async_step_config(self, user_input=None): _LOGGER.exception("Unexpected exception", exc_info=True) errors["base"] = "unknown" api = HomePilotApi( - self.host, self.password + self.host, self.password, self.api_version ) # password can be empty if not defined ("") manager = await HomePilotManager.async_build_manager(api) self.hostname = await manager.get_nodename() @@ -100,6 +103,7 @@ async def async_step_reauth(self, user_input=None): data = { CONF_HOST: self.host, CONF_PASSWORD: "", + CONF_API_VERSION: 1 } self.hass.config_entries.async_update_entry(self.reauth_entry, data=data) await self.hass.config_entries.async_reload(self.reauth_entry.entry_id) @@ -138,6 +142,7 @@ async def async_step_user_password(self, user_input=None): data = { CONF_HOST: self.host, CONF_PASSWORD: self.password, + CONF_API_VERSION: 1 } self.hass.config_entries.async_update_entry(self.reauth_entry, data=data) await self.hass.config_entries.async_reload(self.reauth_entry.entry_id) @@ -177,24 +182,33 @@ async def async_step_user(self, user_input=None): _LOGGER.info("Starting manual config for IP %s", self.host) conn_test = await HomePilotApi.test_connection(user_input[CONF_HOST]) if conn_test == "ok": + self.api_version = 1 _LOGGER.info( "Connection Test Successful (IP %s), no Password required", self.host, ) return await self.async_step_config(user_input=user_input) if conn_test == "ok_v2": - self.host = f"{self.host}/hp" + self.api_version = 2 _LOGGER.info( "Connection Test Successful (IP %s) with New Homepilot, no Password required", self.host, ) return await self.async_step_config(user_input=user_input) if conn_test == "auth_required": + self.api_version = 1 _LOGGER.info( "Connection Test Successful (IP %s), Password needed", self.host, ) return await self.async_step_user_password(user_input=user_input) + if conn_test == "auth_required_v2": + self.api_version = 2 + _LOGGER.info( + "Connection Test Successful (IP %s) with New Homepilot, Password needed", + self.host, + ) + return await self.async_step_user_password(user_input=user_input) _LOGGER.warning("Connection Test not Successful (IP %s)", self.host) errors["base"] = "cannot_connect" @@ -225,7 +239,7 @@ async def async_step_confirm_discovery( "User confirmed integration (IP %s), creating entries", self.host ) return self.async_create_entry( - title=f"{self.hostname} ({self.mac_address})", data={CONF_HOST: self.host} + title=f"{self.hostname} ({self.mac_address})", data={CONF_HOST: self.host, CONF_API_VERSION: self.api_version} ) self._set_confirm_only() @@ -260,21 +274,29 @@ async def async_step_dhcp(self, discovery_info) -> data_entry_flow.FlowResult: conn_test = await HomePilotApi.test_connection(self.host) if conn_test == "ok": + self.api_version = 1 _LOGGER.info( "Connection Test Successful (IP %s), no Password required", self.host ) return await self.async_step_config() if conn_test == "ok_v2": - self.host = f"{self.host}/hp" + self.api_version = 2 _LOGGER.info( "Connection Test Successful (IP %s) with New Homepilot, no Password required", self.host ) return await self.async_step_config() if conn_test == "auth_required": + self.api_version = 1 _LOGGER.info( "Connection Test Successful (IP %s), Password needed", self.host ) return await self.async_step_user_password() + if conn_test == "auth_required_v2": + self.api_version = 2 + _LOGGER.info( + "Connection Test Successful (IP %s) with New Homepilot, Password needed", self.host + ) + return await self.async_step_user_password() _LOGGER.warning("Connection Test not Successful (IP %s)", self.host) return self.async_abort(reason="cannot_connect") @@ -336,8 +358,13 @@ async def async_step_init(self, user_input=None): if CONF_PASSWORD in self.config_entry.data else "" ) + self.api_version = ( + self.config_entry.data[CONF_API_VERSION] + if CONF_API_VERSION in self.config_entry.data + else 1 + ) api = HomePilotApi( - self.host, self.password + self.host, self.password, self.api_version ) # password can be empty if not defined ("") manager = await HomePilotManager.async_build_manager(api) self.mac_address = format_mac(await manager.get_hub_macaddress()) diff --git a/custom_components/rademacher/manifest.json b/custom_components/rademacher/manifest.json index 804df79..bcdf6ff 100644 --- a/custom_components/rademacher/manifest.json +++ b/custom_components/rademacher/manifest.json @@ -11,6 +11,6 @@ "integration_type": "hub", "iot_class": "local_polling", "issue_tracker": "https://github.com/peribeir/homeassistant-rademacher/issues", - "requirements": ["pyrademacher==0.11.2"], + "requirements": ["pyrademacher==0.13.1"], "version": "2.0.1" }