Skip to content

Commit

Permalink
Merge pull request #101 from dominikamann/Add-reconfiguration-flow
Browse files Browse the repository at this point in the history
Add the possibility to reconfigurate the settings
  • Loading branch information
dominikamann authored Jan 8, 2025
2 parents 6a20272 + 19263f5 commit 49fa29f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
60 changes: 60 additions & 0 deletions custom_components/oekofen_pellematic_compact/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import voluptuous as vol

from homeassistant import config_entries
from typing import Any, Dict


from homeassistant.const import (
CONF_NAME,
Expand Down Expand Up @@ -103,3 +105,61 @@ async def async_step_user(self, user_input=None):
return self.async_show_form(
step_id="user", data_schema=DATA_SCHEMA, errors=errors
)

async def async_step_reconfigure(self, user_input: Dict[str, Any] | None = None):
"""Handle reconfiguration."""
errors = {}

# Ensure the context contains the entry ID
if "entry_id" not in self.context:
return self.async_abort(reason="missing_entry_id")

# Get the current configuration entry
config_entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
if not config_entry:
return self.async_abort(reason="entry_not_found")

# Load current configuration as defaults for the form
current_config = config_entry.data

if user_input is not None:
# Validate and save the new configuration
host = user_input[CONF_HOST]

if not host_valid(host):
errors[CONF_HOST] = "invalid_host_ip"
else:
# Merge new input with current config
updated_config = {**current_config, **user_input}
self.hass.config_entries.async_update_entry(
config_entry,
data=updated_config,
)
await self.hass.config_entries.async_reload(config_entry.entry_id)
return self.async_abort(reason="reconfiguration_successful")

# Create a schema with current configuration as defaults
data_schema = vol.Schema(
{
#vol.Optional(CONF_NAME, default=current_config.get(CONF_NAME, DEFAULT_NAME)): str, Do not add as it has changes in sensor names
vol.Optional(CONF_HOST, default=current_config.get(CONF_HOST, DEFAULT_HOST)): str,
vol.Optional(CONF_SCAN_INTERVAL, default=current_config.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)): int,
vol.Optional(CONF_NUM_OF_HEATING_CIRCUIT, default=current_config.get(CONF_NUM_OF_HEATING_CIRCUIT, DEFAULT_NUM_OF_HEATING_CIRCUIT)): int,
vol.Optional(CONF_NUM_OF_HOT_WATER, default=current_config.get(CONF_NUM_OF_HOT_WATER, DEFAULT_NUM_OF_HOT_WATER)): int,
vol.Optional(CONF_NUM_OF_PELLEMATIC_HEATER, default=current_config.get(CONF_NUM_OF_PELLEMATIC_HEATER, DEFAULT_NUM_OF_PELLEMATIC_HEATER)): int,
vol.Optional(CONF_SOLAR_CIRCUIT, default=current_config.get(CONF_SOLAR_CIRCUIT, False)): bool,
vol.Optional(CONF_NUM_OF_SMART_PV_SE, default=current_config.get(CONF_NUM_OF_SMART_PV_SE, DEFAULT_NUM_OF_SMART_PV_SE)): int,
vol.Optional(CONF_NUM_OF_SMART_PV_SK, default=current_config.get(CONF_NUM_OF_SMART_PV_SK, DEFAULT_NUM_OF_SMART_PV_SK)): int,
vol.Optional(CONF_NUM_OF_HEAT_PUMPS, default=current_config.get(CONF_NUM_OF_HEAT_PUMPS, DEFAULT_NUM_OF_HEAT_PUMPS)): int,
vol.Optional(CONF_CIRCULATOR, default=current_config.get(CONF_CIRCULATOR, False)): bool,
vol.Optional(CONF_SMART_PV, default=current_config.get(CONF_SMART_PV, False)): bool,
vol.Optional(CONF_STIRLING, default=current_config.get(CONF_STIRLING, False)): bool,
vol.Optional(CONF_CHARSET, default=current_config.get(CONF_CHARSET, DEFAULT_CHARSET)): str,
}
)

return self.async_show_form(
step_id="reconfigure",
data_schema=data_schema,
errors=errors,
)
2 changes: 1 addition & 1 deletion custom_components/oekofen_pellematic_compact/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/dominikamann/oekofen-pellematic-compact/issues",
"requirements": [],
"version": "v3.4.0"
"version": "v3.4.1"
}

0 comments on commit 49fa29f

Please sign in to comment.