|
4 | 4 | import voluptuous as vol |
5 | 5 | from homeassistant import config_entries |
6 | 6 | from homeassistant.config_entries import ConfigFlowResult |
| 7 | +from homeassistant.data_entry_flow import FlowResult |
7 | 8 | from homeassistant.helpers.service_info import zeroconf |
8 | 9 | from homeassistant.const import CONF_HOST, CONF_PORT |
9 | 10 |
|
@@ -87,6 +88,33 @@ def __init__(self): |
87 | 88 | # data_schema=data_schema, |
88 | 89 | # errors=errors |
89 | 90 | # ) |
| 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 | + ) |
90 | 118 |
|
91 | 119 | async def async_step_zeroconf( |
92 | 120 | self, discovery_info: zeroconf.ZeroconfServiceInfo |
|
0 commit comments