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:
buzeraandClaude Opus 5.5 committed 2026-10-27 03:29:29 +02:00
1 parent 2bddc74d37
commit 9bb64e79ca
5 files changed
+58 -15

No files matched your search

+12 -2
View File
@@ -132,8 +132,11 @@ async def test_zone_subentry_add_edit_and_validation(hass, entry, inputs):
"name": " Living ", "sensors": ["sensor.living_a", "sensor.living_b"], "comfort_weight": 2,
"target_offset": 0.5, "neighbors": ["sensor.room"]})
assert result["step_id"] == "sensor_weights"
result = await flows.async_configure(result["flow_id"], {
"weight__sensor.living_a": 3, "weight__sensor.living_b": 1})
# Numbered, translated fields; the description says which sensor is which.
assert [str(key) for key in result["data_schema"].schema] == ["sensor_weight_1", "sensor_weight_2"]
assert result["description_placeholders"]["sensors"].splitlines() == [
"1. living a (sensor.living_a)", "2. living b (sensor.living_b)"] # HA name fallback
result = await flows.async_configure(result["flow_id"], {"sensor_weight_1": 3, "sensor_weight_2": 1})
assert result["type"] is FlowResultType.CREATE_ENTRY
await hass.async_block_till_done()
living = next(sub for sub in zones_of(entry).values() if sub.title == "Living")
@@ -149,6 +152,13 @@ async def test_zone_subentry_add_edit_and_validation(hass, entry, inputs):
result = await flows.async_configure(result["flow_id"], {
"name": "Living", "sensors": ["sensor.living_a"], "comfort_weight": 1, "target_offset": 0})
assert result["type"] is FlowResultType.ABORT and result["reason"] == "reconfigure_successful"
# Editing a multi-sensor zone shows the saved sensor weights.
result = await flows.async_init((entry.entry_id, "zone"), context={
"source": SOURCE_RECONFIGURE, "subentry_id": living.subentry_id})
result = await flows.async_configure(result["flow_id"], {
"name": "Living", "sensors": ["sensor.living_a", "sensor.living_b"], "comfort_weight": 1, "target_offset": 0})
assert result["data_schema"]({})["sensor_weight_1"] == 1.0
flows.async_abort(result["flow_id"])
await hass.async_block_till_done()
assert entry.subentries[living.subentry_id].data["key"] == key
assert hass.data[DOMAIN][entry.entry_id].zones[key].sensors == ("sensor.living_a",)