Skip to content

Commit

Permalink
Merge pull request #101 from peribeir/peribeir/issue99
Browse files Browse the repository at this point in the history
Rademacher Componentes not available after Restart
  • Loading branch information
peribeir authored Nov 28, 2023
2 parents c06fbbc + 7ec6c89 commit 3483810
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
2 changes: 2 additions & 0 deletions custom_components/rademacher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
37 changes: 32 additions & 5 deletions custom_components/rademacher/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
CONF_HOST,
CONF_PASSWORD,
CONF_SENSOR_TYPE,
CONF_API_VERSION
)

from homepilot.manager import HomePilotManager
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion custom_components/rademacher/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"integration_type": "hub",
"iot_class": "local_polling",
"issue_tracker": "https://github.com/peribeir/homeassistant-rademacher/issues",
"requirements": ["pyrademacher==0.12.3"],
"requirements": ["pyrademacher==0.13.1"],
"version": "2.1.0"
}

0 comments on commit 3483810

Please sign in to comment.