Skip to content

Commit f1c95f3

Browse files
committed
Initial reconfigure flow added
1 parent ecac7ce commit f1c95f3

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

custom_components/powersensor/config_flow.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import voluptuous as vol
55
from homeassistant import config_entries
66
from homeassistant.config_entries import ConfigFlowResult
7+
from homeassistant.data_entry_flow import FlowResult
78
from homeassistant.helpers.service_info import zeroconf
89
from homeassistant.const import CONF_HOST, CONF_PORT
910

@@ -87,6 +88,33 @@ def __init__(self):
8788
# data_schema=data_schema,
8889
# errors=errors
8990
# )
91+
async def async_step_reconfigure(self, user_input: dict | None = None)->FlowResult:
92+
entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
93+
94+
if user_input is not None:
95+
await self.hass.config_entries.async_reload(entry.entry_id)
96+
return self.async_abort(reason="Powersensor role updates successful!")
97+
98+
dispatcher = entry.runtime_data["dispatcher"]
99+
sensor_roles = {}
100+
for sensor_mac in dispatcher.sensors:
101+
role = entry.data.get('roles', {}).get(sensor_mac, None)
102+
if not role:
103+
sensor_roles[vol.Optional(f"device_type_{sensor_mac}")] = vol.In(
104+
["house-net", "solar", "water", "appliance", "none"] # Your supported types
105+
)
106+
else:
107+
sensor_roles[vol.Optional(f"device_type_{sensor_mac}", description={"suggested_value": role})] = vol.In(
108+
["house-net", "solar", "water", "appliance", "none"] # Your supported types
109+
)
110+
111+
return self.async_show_form(
112+
step_id="reconfigure",
113+
data_schema=vol.Schema(sensor_roles),
114+
description_placeholders={
115+
"device_count": str(len(sensor_roles))
116+
}
117+
)
90118

91119
async def async_step_zeroconf(
92120
self, discovery_info: zeroconf.ZeroconfServiceInfo

0 commit comments

Comments
 (0)