Keep the entry loaded when the last zone is deleted
Deleting the only zone in the UI reloaded the entry with no zones, and min() over an empty set of models raised during setup, so the entry failed to load. Counts and learning progress now default to 0, and the status reads "no_zones" until a zone is added again; adding one resumes normally. HA Core regression test included. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e62798dc4f
commit
dc92e2bac5
2 files changed
+25
-7
No files matched your search
@@ -290,3 +290,18 @@ async def test_learning_progress_and_last_sample_sensors(hass, entry, inputs, fr
|
||||
last = hass.states.get(last_id)
|
||||
assert last.state == "waiting_for_inputs"
|
||||
assert last.attributes["counts_since_start"] == {"first_sample": 1, "learned": 1, "waiting_for_inputs": 1}
|
||||
|
||||
|
||||
async def test_deleting_the_last_zone_keeps_the_entry_loaded(hass, entry, inputs, caplog):
|
||||
await setup(hass, entry)
|
||||
assert hass.config_entries.async_remove_subentry(entry, zone_subentry(entry, "sensor.room").subentry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert entry.state.name == "LOADED"
|
||||
coordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
assert (coordinator.rooms, coordinator.data["status"]) == ([], "no_zones")
|
||||
assert coordinator.data["learning_progress"] == 0
|
||||
assert "Error setting up entry" not in caplog.text
|
||||
# Adding a zone back resumes normally.
|
||||
add_zone(hass, entry, "sensor.room", ["sensor.room"])
|
||||
await hass.async_block_till_done()
|
||||
assert hass.data[DOMAIN][entry.entry_id].data["status"] == "learning"
|
||||
Reference in new issue
Block a user