Repository: home-assistant/core
File: homeassistant/components/matter/vacuum.py (Python)

Code before:
        state: VacuumActivity | None = None
        if TYPE_CHECKING:
            assert self._supported_run_modes is not None
        if operational_state in (OperationalState.CHARGING, OperationalState.DOCKED):
            state = VacuumActivity.DOCKED
        elif operational_state == OperationalState.SEEKING_CHARGER:
            state = VacuumActivity.RETURNING
        elif operational_state == OperationalState.ERROR:
            state = VacuumActivity.ERROR
        elif operational_state == OperationalState.PAUSED:
            state = VacuumActivity.PAUSED
        elif (run_mode := self._supported_run_modes.get(run_mode_raw)) is not None:
            tags = {x.value for x in run_mode.modeTags}
            if ModeTag.CLEANING in tags:
                state = VacuumActivity.CLEANING
            elif ModeTag.IDLE in tags:
                state = VacuumActivity.IDLE
            elif ModeTag.MAPPING in tags:
                state = VacuumActivity.CLEANING
        self._attr_activity = state

        if (
            VacuumEntityFeature.CLEAN_AREA in self.supported_features
            and self.registry_entry is not None
            and (last_seen_segments := self.last_seen_segments) is not None
            and self._current_segments != last_seen_segments
        ):
            self.async_create_segments_issue()

    @callback
    def _calculate_features(self) -> None:
        """Calculate features for HA Vacuum platform."""
        accepted_operational_commands: list[int] = self.get_matter_attribute_value(
            clusters.RvcOperationalState.Attributes.AcceptedCommandList
        )
        service_area_feature_map: int | None = self.get_matter_attribute_value(
            clusters.ServiceArea.Attributes.FeatureMap
        )

        # In principle the feature set should not change, except for accepted
        # commands and service area feature map.
        if (
            self._last_accepted_commands == accepted_operational_commands
            and self._last_service_area_feature_map == service_area_feature_map
        ):
            return

        self._last_accepted_commands = accepted_operational_commands
        self._last_service_area_feature_map = service_area_feature_map
        supported_features: VacuumEntityFeature = VacuumEntityFeature(0)
        supported_features |= VacuumEntityFeature.START

Review comment (suggestion):
```suggestion
            and self._current_segments != {s.id: s for s in last_seen_segments}
```
I don't think we should care about order here.

Code after:
        state: VacuumActivity | None = None
        if TYPE_CHECKING:
            assert self._supported_run_modes is not None
        if operational_state in (OperationalState.CHARGING, OperationalState.DOCKED):
            state = VacuumActivity.DOCKED
        elif operational_state == OperationalState.SEEKING_CHARGER:
            state = VacuumActivity.RETURNING
        elif operational_state == OperationalState.ERROR:
            state = VacuumActivity.ERROR
        elif operational_state == OperationalState.PAUSED:
            state = VacuumActivity.PAUSED
        elif (run_mode := self._supported_run_modes.get(run_mode_raw)) is not None:
            tags = {x.value for x in run_mode.modeTags}
            if ModeTag.CLEANING in tags:
                state = VacuumActivity.CLEANING
            elif ModeTag.IDLE in tags:
                state = VacuumActivity.IDLE
            elif ModeTag.MAPPING in tags:
                state = VacuumActivity.CLEANING
        self._attr_activity = state

        if (
            VacuumEntityFeature.CLEAN_AREA in self.supported_features
            and self.registry_entry is not None
            and (last_seen_segments := self.last_seen_segments) is not None
            and self._current_segments != {s.id: s for s in last_seen_segments}
        ):
            self.async_create_segments_issue()

    @callback
    def _calculate_features(self) -> None:
        """Calculate features for HA Vacuum platform."""
        accepted_operational_commands: list[int] = self.get_matter_attribute_value(
            clusters.RvcOperationalState.Attributes.AcceptedCommandList
        )
        service_area_feature_map: int | None = self.get_matter_attribute_value(
            clusters.ServiceArea.Attributes.FeatureMap
        )

        # In principle the feature set should not change, except for accepted
        # commands and service area feature map.
        if (
            self._last_accepted_commands == accepted_operational_commands
            and self._last_service_area_feature_map == service_area_feature_map
        ):
            return

        self._last_accepted_commands = accepted_operational_commands
        self._last_service_area_feature_map = service_area_feature_map
        supported_features: VacuumEntityFeature = VacuumEntityFeature(0)
        supported_features |= VacuumEntityFeature.START