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

Code before:
        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) -> 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
    def _current_segments(self) -> dict[str, Segment]:
```
Let's return here a dict with IDs as keys. Adjust the function body to do that.

Code after:
        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.
        """
        return list(self._current_segments.values())