From 6a56c86d5aced97d88ff2437f9d61ec3272ffcd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Beye?= Date: Sun, 10 May 2026 15:46:15 +0200 Subject: [PATCH 1/5] fix: Do not forget segments from state when a new config arrives --- homeassistant/components/mqtt/vacuum.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/homeassistant/components/mqtt/vacuum.py b/homeassistant/components/mqtt/vacuum.py index 3ab42edcbb855a..a21a509d31817c 100644 --- a/homeassistant/components/mqtt/vacuum.py +++ b/homeassistant/components/mqtt/vacuum.py @@ -250,6 +250,12 @@ def _strings_to_services( self._attr_supported_features = _strings_to_services( supported_feature_strings, STRING_TO_SERVICE ) + + if getattr(self, "_segments", None) and config.get( + CONF_CLEAN_SEGMENTS_COMMAND_TOPIC + ): + self._attr_supported_features |= VacuumEntityFeature.CLEAN_AREA + self._clean_segments_command_topic = config.get( CONF_CLEAN_SEGMENTS_COMMAND_TOPIC ) From 8affdae7921cb336d71a7930f25588d5dcc51842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Beye?= Date: Sun, 10 May 2026 17:16:18 +0200 Subject: [PATCH 2/5] chore: Add test --- tests/components/mqtt/test_vacuum.py | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/components/mqtt/test_vacuum.py b/tests/components/mqtt/test_vacuum.py index 52ac9ad64c2d46..55bdf13077306b 100644 --- a/tests/components/mqtt/test_vacuum.py +++ b/tests/components/mqtt/test_vacuum.py @@ -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 From c4fb7f165ed72f2744b4c74026688a7a06172b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Beye?= Date: Sun, 10 May 2026 21:28:32 +0200 Subject: [PATCH 3/5] Update homeassistant/components/mqtt/vacuum.py Co-authored-by: Jan Bouwhuis --- homeassistant/components/mqtt/vacuum.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/mqtt/vacuum.py b/homeassistant/components/mqtt/vacuum.py index a21a509d31817c..6a6c8e049a1a1b 100644 --- a/homeassistant/components/mqtt/vacuum.py +++ b/homeassistant/components/mqtt/vacuum.py @@ -247,8 +247,10 @@ def _strings_to_services( return services supported_feature_strings: list[str] = config[CONF_SUPPORTED_FEATURES] - self._attr_supported_features = _strings_to_services( - supported_feature_strings, STRING_TO_SERVICE + self._attr_supported_features = ( + (self.supported_features & VacuumEntityFeature.CLEAN_AREA) + if CONF_CLEAN_SEGMENTS_COMMAND_TOPIC in config + else 0 | _strings_to_services(supported_feature_strings, STRING_TO_SERVICE) ) if getattr(self, "_segments", None) and config.get( From 7e5b726a2e77d9c19d6bb7a3b8853d39bcf24ade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Beye?= Date: Sun, 10 May 2026 21:28:41 +0200 Subject: [PATCH 4/5] Update homeassistant/components/mqtt/vacuum.py Co-authored-by: Jan Bouwhuis --- homeassistant/components/mqtt/vacuum.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/homeassistant/components/mqtt/vacuum.py b/homeassistant/components/mqtt/vacuum.py index 6a6c8e049a1a1b..6312b2f9fa7dac 100644 --- a/homeassistant/components/mqtt/vacuum.py +++ b/homeassistant/components/mqtt/vacuum.py @@ -252,12 +252,6 @@ def _strings_to_services( if CONF_CLEAN_SEGMENTS_COMMAND_TOPIC in config else 0 | _strings_to_services(supported_feature_strings, STRING_TO_SERVICE) ) - - if getattr(self, "_segments", None) and config.get( - CONF_CLEAN_SEGMENTS_COMMAND_TOPIC - ): - self._attr_supported_features |= VacuumEntityFeature.CLEAN_AREA - self._clean_segments_command_topic = config.get( CONF_CLEAN_SEGMENTS_COMMAND_TOPIC ) From ea574501a196ab46650d96aabc06d4e7ef249147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Beye?= Date: Sun, 10 May 2026 21:39:20 +0200 Subject: [PATCH 5/5] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- homeassistant/components/mqtt/vacuum.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/mqtt/vacuum.py b/homeassistant/components/mqtt/vacuum.py index 6312b2f9fa7dac..bce59a8277c5a9 100644 --- a/homeassistant/components/mqtt/vacuum.py +++ b/homeassistant/components/mqtt/vacuum.py @@ -247,10 +247,12 @@ def _strings_to_services( return services supported_feature_strings: list[str] = config[CONF_SUPPORTED_FEATURES] - self._attr_supported_features = ( - (self.supported_features & VacuumEntityFeature.CLEAN_AREA) + 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 | _strings_to_services(supported_feature_strings, STRING_TO_SERVICE) + else 0 ) self._clean_segments_command_topic = config.get( CONF_CLEAN_SEGMENTS_COMMAND_TOPIC