Skip to content

Commit 2c3cb52

Browse files
committed
allow reconfiguration
1 parent b7efa13 commit 2c3cb52

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

custom_components/bwt_perla/config_flow.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,28 @@
99
from homeassistant import config_entries
1010
from homeassistant.const import CONF_CODE, CONF_HOST
1111
from homeassistant.core import HomeAssistant
12+
from homeassistant.config_entries import ConfigFlowResult
1213
from homeassistant.data_entry_flow import FlowResult
1314

1415
from .const import DOMAIN
1516

1617
_LOGGER = logging.getLogger(__name__)
1718

18-
STEP_USER_DATA_SCHEMA = vol.Schema(
19+
def _bwt_schema(
20+
host: str | None = None,
21+
code: str | None = None,
22+
): return vol.Schema(
1923
{
20-
vol.Required(CONF_HOST): str,
21-
vol.Required(CONF_CODE): str,
24+
vol.Required(CONF_HOST, default=host): str,
25+
vol.Required(CONF_CODE, default=code) : str,
2226
}
2327
)
2428

2529

2630
async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Any]:
2731
"""Validate the user input allows us to connect.
2832
29-
Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
33+
Data has the keys from _bwt_schema with values provided by the user.
3034
"""
3135
async with BwtApi(data[CONF_HOST], data[CONF_CODE]) as api:
3236
await api.get_current_data()
@@ -40,6 +44,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
4044

4145
VERSION = 2
4246

47+
4348
async def async_step_user(
4449
self, user_input: dict[str, Any] | None = None
4550
) -> FlowResult:
@@ -60,5 +65,33 @@ async def async_step_user(
6065
errors["base"] = "unknown"
6166

6267
return self.async_show_form(
63-
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
68+
step_id="user", data_schema=_bwt_schema(), errors=errors
69+
)
70+
71+
72+
async def async_step_reconfigure(self, user_input: dict[str, Any] | None = None):
73+
"""Manual reconfiguration to change a setting."""
74+
current = self._get_reconfigure_entry()
75+
errors: dict[str, str] = {}
76+
if user_input is not None:
77+
try:
78+
await validate_input(self.hass, user_input)
79+
self.hass.config_entries.async_update_entry(current, data=user_input)
80+
await self.hass.config_entries.async_reload(current.entry_id)
81+
return self.async_abort(reason="reconfiguration_successful")
82+
except ConnectException:
83+
_LOGGER.exception("Connection error setting up the Bwt Api")
84+
errors["base"] = "cannot_connect"
85+
except WrongCodeException:
86+
_LOGGER.exception("Wrong user code passed to bwt api")
87+
errors["base"] = "invalid_auth"
88+
except Exception: # pylint: disable=broad-except
89+
_LOGGER.exception("Unexpected exception")
90+
errors["base"] = "unknown"
91+
92+
return self.async_show_form(
93+
step_id="reconfigure", data_schema=_bwt_schema(
94+
host=current.data[CONF_HOST],
95+
code=current.data[CONF_CODE],
96+
), errors=errors
6497
)

custom_components/bwt_perla/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
"issue_tracker": "https://github.com/dkarv/ha-bwt-perla/issues",
1212
"requirements": ["bwt_api==0.5.1"],
1313
"ssdp": [],
14-
"version": "0.5.6",
14+
"version": "0.5.7",
1515
"zeroconf": []
1616
}

0 commit comments

Comments
 (0)