Skip to content

Commit 950ee0c

Browse files
committed
Fix reconfigure flow
1 parent d18fd4b commit 950ee0c

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

custom_components/eurotronic_cometblue/config_flow.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111
from homeassistant.components.bluetooth import async_discovered_service_info
1212
from homeassistant.components.bluetooth.models import BluetoothServiceInfoBleak
13-
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
13+
from homeassistant.config_entries import (
14+
SOURCE_RECONFIGURE,
15+
ConfigFlow,
16+
ConfigFlowResult,
17+
)
1418
from homeassistant.const import CONF_ADDRESS, CONF_PIN, CONF_TIMEOUT
1519
from homeassistant.data_entry_flow import FlowResult
1620
from homeassistant.helpers.device_registry import format_mac
@@ -62,22 +66,35 @@ def __init__(self) -> None:
6266
self._discovered_device: str | None = None
6367
self._discovered_devices: list[str] = []
6468

65-
def _create_entry(self, pin: int, device_name: str | None = None) -> FlowResult:
69+
def _create_entry(
70+
self,
71+
pin: int,
72+
device_name: str | None = None,
73+
timeout: int = DEFAULT_TIMEOUT_SECONDS,
74+
retry_count: int = DEFAULT_RETRY_COUNT,
75+
) -> FlowResult:
6676
"""Create an entry for a discovered device."""
6777

78+
entry_data = {
79+
CONF_ADDRESS: None,
80+
CONF_PIN: pin,
81+
CONF_DEVICE_NAME: device_name,
82+
CONF_TIMEOUT: timeout,
83+
CONF_RETRY_COUNT: retry_count,
84+
}
85+
86+
if self.source == SOURCE_RECONFIGURE:
87+
entry_data[CONF_ADDRESS] = self._existing_entry_data[CONF_ADDRESS]
88+
return self.async_update_reload_and_abort(
89+
self._get_reconfigure_entry(),
90+
data=entry_data,
91+
)
92+
6893
if self._discovery_info is None or self._discovery_info.address is None:
6994
raise ValueError("Discovery info not set")
95+
entry_data[CONF_ADDRESS] = self._discovery_info.address
7096

71-
return self.async_create_entry(
72-
title=device_name,
73-
data={
74-
CONF_ADDRESS: self._discovery_info.address,
75-
CONF_PIN: pin,
76-
CONF_DEVICE_NAME: device_name,
77-
CONF_TIMEOUT: DEFAULT_TIMEOUT_SECONDS,
78-
CONF_RETRY_COUNT: DEFAULT_RETRY_COUNT,
79-
},
80-
)
97+
return self.async_create_entry(title=device_name, data=entry_data)
8198

8299
async def async_step_bluetooth_confirm(
83100
self, user_input: dict[str, Any] | None = None
@@ -86,7 +103,10 @@ async def async_step_bluetooth_confirm(
86103

87104
if user_input is not None:
88105
return self._create_entry(
89-
user_input[CONF_PIN], user_input.get(CONF_DEVICE_NAME)
106+
user_input[CONF_PIN],
107+
user_input.get(CONF_DEVICE_NAME),
108+
timeout=user_input.get(CONF_TIMEOUT),
109+
retry_count=user_input.get(CONF_RETRY_COUNT),
90110
)
91111

92112
try:

custom_components/eurotronic_cometblue/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
"requirements": [
1818
"git+https://github.com/rikroe/eurotronic-cometblue.git@ha-component#eurotronic-cometblue==1.0"
1919
],
20-
"version": "20241114.1"
20+
"version": "20241118.1"
2121
}

custom_components/eurotronic_cometblue/strings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"config": {
33
"flow_title": "{name}",
44
"abort": {
5-
"no_devices_found": "There aren't any Comet Blue Bluetooth TRVs nearby."
5+
"no_devices_found": "There aren't any Comet Blue Bluetooth TRVs nearby.",
6+
"reconfigure_successful": "Re-configuration was successful"
67
},
78
"step": {
89
"bluetooth_confirm": {

custom_components/eurotronic_cometblue/translations/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"config": {
33
"abort": {
4-
"no_devices_found": "There aren't any Comet Blue Bluetooth TRVs nearby."
4+
"no_devices_found": "There aren't any Comet Blue Bluetooth TRVs nearby.",
5+
"reconfigure_successful": "Re-configuration was successful"
56
},
67
"flow_title": "{name}",
78
"step": {

0 commit comments

Comments
 (0)