Make per-sensor weights visible and labelled in the zone form
Sensor weights already existed, but only as a second step after saving
a zone with two or more sensors, with fields labelled by raw keys such
as weight__sensor.living_a, so they were easy to miss.
The zone form now says that choosing two or more sensors leads to a
sensor-weight step. That step uses numbered fields ("Sensor 1 weight",
English and Romanian) and its description lists which sensor is which
by friendly name. Editing a multi-sensor zone shows the saved weights.
Stored data is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2bddc74d37
commit
9bb64e79ca
5 files changed
+58
-15
No files matched your search
@@ -302,14 +302,23 @@ class ZoneSubentryFlow(config_entries.ConfigSubentryFlow):
|
||||
return await self._zone_form("reconfigure", user_input, existing, existing[ZONE_KEY])
|
||||
|
||||
async def async_step_sensor_weights(self, user_input: dict[str, Any] | None = None):
|
||||
"""One weight per sensor; fields are numbered so they have translated labels."""
|
||||
sensors = self._draft[ZONE_SENSORS]
|
||||
if user_input is not None:
|
||||
self._draft[ZONE_SENSOR_WEIGHTS] = {s: float(user_input[f"weight__{s}"]) for s in sensors}
|
||||
self._draft[ZONE_SENSOR_WEIGHTS] = {
|
||||
s: float(user_input[f"sensor_weight_{i}"]) for i, s in enumerate(sensors, 1)}
|
||||
return self._finish()
|
||||
weights = self._draft.get(ZONE_SENSOR_WEIGHTS) or {}
|
||||
return self.async_show_form(step_id="sensor_weights", data_schema=vol.Schema({
|
||||
vol.Required(f"weight__{s}", default=weights.get(s, 1.0)): _number(*SENSOR_WEIGHT_RANGE, 0.1)
|
||||
for s in sensors}))
|
||||
names = []
|
||||
for i, sensor in enumerate(sensors, 1):
|
||||
state = self.hass.states.get(sensor)
|
||||
names.append(f"{i}. {state.name if state else sensor} ({sensor})")
|
||||
return self.async_show_form(
|
||||
step_id="sensor_weights",
|
||||
data_schema=vol.Schema({
|
||||
vol.Required(f"sensor_weight_{i}", default=weights.get(s, 1.0)): _number(*SENSOR_WEIGHT_RANGE, 0.1)
|
||||
for i, s in enumerate(sensors, 1)}),
|
||||
description_placeholders={"sensors": "\n".join(names)})
|
||||
|
||||
def _finish(self):
|
||||
data = {key: self._draft[key] for key in (
|
||||
|
||||
Reference in new issue
Block a user