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

Code before:
        # this is compatible with both Matter 1.2 and 1.3+ devices.
        mode = self._get_run_mode_by_tag(ModeTag.CLEANING)
        if mode is None:
            raise HomeAssistantError(
                "No supported run mode found to start the vacuum cleaner."
            )

        # Reset selected areas to an unconstrained selection to ensure start
        # performs a full clean and does not reuse a previous area-targeted
        # selection.
        if VacuumEntityFeature.CLEAN_AREA in self.supported_features:
            # Matter ServiceArea: an empty NewAreas list means unconstrained
            # operation (full clean).
            await self.send_device_command(
                clusters.ServiceArea.Commands.SelectAreas(newAreas=[])
            )

        await self.send_device_command(
            clusters.RvcRunMode.Commands.ChangeToMode(newMode=mode.mode)
        )

    async def async_pause(self) -> None:
        """Pause the cleaning task."""
        await self.send_device_command(clusters.RvcOperationalState.Commands.Pause())

    def _current_segments(self) -> list[Segment]:
        """Return the current cleanable segments reported by the device."""
        supported_areas: list[clusters.ServiceArea.Structs.AreaStruct] = (
            self.get_matter_attribute_value(
                clusters.ServiceArea.Attributes.SupportedAreas
            )
        )

        segments: list[Segment] = []
        for area in supported_areas:
            area_name = None
            if area.areaInfo and area.areaInfo.locationInfo:
                area_name = area.areaInfo.locationInfo.locationName

            if area_name:
                segments.append(
                    Segment(
                        id=str(area.areaID),
                        name=area_name,
                    )
                )

        return segments

    async def async_get_segments(self) -> list[Segment]:
        """Get the segments that can be cleaned.

Review comment (suggestion):
```suggestion
    @property
    def _current_segments(self) -> list[Segment]:
```
Adjust the usage accordingly.

Code after:
        # that has the cleaning tag to start the vacuum cleaner.
        # this is compatible with both Matter 1.2 and 1.3+ devices.
        mode = self._get_run_mode_by_tag(ModeTag.CLEANING)
        if mode is None:
            raise HomeAssistantError(
                "No supported run mode found to start the vacuum cleaner."
            )

        # Reset selected areas to an unconstrained selection to ensure start
        # performs a full clean and does not reuse a previous area-targeted
        # selection.
        if VacuumEntityFeature.CLEAN_AREA in self.supported_features:
            # Matter ServiceArea: an empty NewAreas list means unconstrained
            # operation (full clean).
            await self.send_device_command(
                clusters.ServiceArea.Commands.SelectAreas(newAreas=[])
            )

        await self.send_device_command(
            clusters.RvcRunMode.Commands.ChangeToMode(newMode=mode.mode)
        )

    async def async_pause(self) -> None:
        """Pause the cleaning task."""
        await self.send_device_command(clusters.RvcOperationalState.Commands.Pause())

    @property
    def _current_segments(self) -> dict[str, Segment]:
        """Return the current cleanable segments reported by the device."""
        supported_areas: list[clusters.ServiceArea.Structs.AreaStruct] = (
            self.get_matter_attribute_value(
                clusters.ServiceArea.Attributes.SupportedAreas
            )
        )

        segments: dict[str, Segment] = {}
        for area in supported_areas:
            area_name = None
            if area.areaInfo and area.areaInfo.locationInfo:
                area_name = area.areaInfo.locationInfo.locationName

            if area_name:
                segment_id = str(area.areaID)
                segments[segment_id] = Segment(id=segment_id, name=area_name)

        return segments

    async def async_get_segments(self) -> list[Segment]:
        """Get the segments that can be cleaned.

        Returns a list of segments containing their ids and names.