Skip to content

Commit

Permalink
@Dbzman - Fix for: Modify host caused exception
Browse files Browse the repository at this point in the history
  • Loading branch information
marq24 authored and marq24 committed Aug 2, 2024
1 parent 9b36396 commit 453f393
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions custom_components/senec/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ def senec_entries(hass: HomeAssistant):
return conf_hosts


@staticmethod
def host_in_configuration_exists(hass: HomeAssistant, host: str) -> bool:
"""Return True if host exists in configuration."""
if host in senec_entries(hass):
return True
return False


class SenecConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for senec."""

Expand All @@ -106,12 +114,6 @@ def __init__(self):
self._app_master_plant_id = None
self._app_wallbox_num_max = None

def _host_in_configuration_exists(self, host) -> bool:
"""Return True if host exists in configuration."""
if host in senec_entries(self.hass):
return True
return False

async def _test_connection_senec(self, host, use_https):
"""Check if we can connect to the Senec device."""
self._errors = {}
Expand Down Expand Up @@ -260,7 +262,7 @@ async def async_step_system(self, user_input=None):
if host_entry.startswith('https://'):
host_entry = host_entry.replace("https://", "")

if self._host_in_configuration_exists(host_entry):
if host_in_configuration_exists(self.hass, host_entry):
self._errors[CONF_HOST] = "already_configured"
else:
# Build-In Inverter stuff
Expand Down Expand Up @@ -374,7 +376,7 @@ async def async_step_websetup(self, user_input=None):
already_exist_ident = f"{user}_{master_plant_val}"
master_plant_num = int(master_plant_val)

if self._host_in_configuration_exists(already_exist_ident):
if host_in_configuration_exists(self.hass, already_exist_ident):
self._errors[CONF_USERNAME] = "already_configured"
else:
if await self._test_connection_webapi(user, pwd, master_plant_num):
Expand Down Expand Up @@ -483,7 +485,7 @@ async def async_step_system(self, user_input=None):
self.options.update(user_input)
if self.data.get(CONF_HOST) != self.options.get(CONF_HOST):
# ok looks like the host has been changed... we need to do some things...
if self._host_in_configuration_exists(host_entry):
if host_in_configuration_exists(self.hass, host_entry):
self._errors[CONF_HOST] = "already_configured"
else:
return self._update_options()
Expand Down
2 changes: 1 addition & 1 deletion custom_components/senec/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/marq24/ha-senec-v3/issues",
"requirements": ["xmltodict>=0.12.0", "packaging>=21.0", "python-dateutil>=2.8.0"],
"version": "2024.7.0"
"version": "2024.8.0"
}

0 comments on commit 453f393

Please sign in to comment.