Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions homeassistant/components/mqtt/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ def _strings_to_services(
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
Expand Down
50 changes: 50 additions & 0 deletions tests/components/mqtt/test_vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Comment thread
jbouwh marked this conversation as resolved.
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
)


Comment thread
jbouwh marked this conversation as resolved.
@pytest.mark.parametrize("hass_config", [CONFIG_ALL_SERVICES])
async def test_status(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
Expand Down
Loading