1
0
mirror of https://github.com/home-assistant/core.git synced 2026-06-01 05:04:21 +01:00

fix: Do not forget segments from state when a new config arrives (#170265)

Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Sören Beye
2026-05-10 22:17:52 +02:00
committed by GitHub
parent afc97268de
commit cd945a42e6
2 changed files with 54 additions and 0 deletions
+4
View File
@@ -249,6 +249,10 @@ class MqttStateVacuum(MqttEntity, StateVacuumEntity):
supported_feature_strings: list[str] = config[CONF_SUPPORTED_FEATURES]
self._attr_supported_features = _strings_to_services(
supported_feature_strings, STRING_TO_SERVICE
) | (
self.supported_features & VacuumEntityFeature.CLEAN_AREA
if CONF_CLEAN_SEGMENTS_COMMAND_TOPIC in config
else 0
)
self._clean_segments_command_topic = config.get(
CONF_CLEAN_SEGMENTS_COMMAND_TOPIC
+50
View File
@@ -592,6 +592,56 @@ async def test_removing_clean_segments_command_topic_resets_feature(
)
async def test_clean_area_feature_preserved_on_config_update(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None:
"""Test the clean area feature is preserved when config is updated with the same topic.
When a new config arrives that still has `clean_segments_command_topic` and
segments were previously received from state, the CLEAN_AREA feature should
be preserved without needing another state message.
"""
await mqtt_mock_entry()
config = CONFIG_CLEAN_SEGMENTS[mqtt.DOMAIN][vacuum.DOMAIN]
async_fire_mqtt_message(
hass,
"homeassistant/vacuum/bla/config",
json.dumps(config),
)
await hass.async_block_till_done()
message = """{
"battery_level": 54,
"state": "idle",
"segments":{
"1":"Livingroom",
"2":"Kitchen"
}
}"""
async_fire_mqtt_message(hass, "vacuum/state", message)
await hass.async_block_till_done()
state = hass.states.get("vacuum.test")
assert (
state.attributes.get(ATTR_SUPPORTED_FEATURES)
& vacuum.VacuumEntityFeature.CLEAN_AREA
)
updated_config = config.copy()
updated_config["name"] = "renamed"
async_fire_mqtt_message(
hass,
"homeassistant/vacuum/bla/config",
json.dumps(updated_config),
)
await hass.async_block_till_done()
state = hass.states.get("vacuum.test")
assert (
state.attributes.get(ATTR_SUPPORTED_FEATURES)
& vacuum.VacuumEntityFeature.CLEAN_AREA
)
@pytest.mark.parametrize("hass_config", [CONFIG_ALL_SERVICES])
async def test_status(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator