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

Code before:
                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.

        Returns a list of segments containing their ids and names.
        """
        return self._current_segments

    async def async_clean_segments(self, segment_ids: list[str], **kwargs: Any) -> None:
        """Clean the specified segments.

        Args:
            segment_ids: List of segment IDs to clean.
            **kwargs: Additional arguments (unused).

        """
        # Convert string IDs to integers
        area_ids = [int(segment_id) for segment_id in segment_ids]

        # Ensure a CLEANING run mode is available before changing device state
        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."
            )

        # Send the SelectAreas command to the vacuum
        await self.send_device_command(
            clusters.ServiceArea.Commands.SelectAreas(newAreas=area_ids)
        )

        # Start cleaning using ChangeToMode with CLEANING tag

Review comment (suggestion):
```suggestion
        return list(self._current_segments.values())
```

Code after:
                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())

    async def async_clean_segments(self, segment_ids: list[str], **kwargs: Any) -> None:
        """Clean the specified segments.

        Args:
            segment_ids: List of segment IDs to clean.
            **kwargs: Additional arguments (unused).

        """
        area_ids = [int(segment_id) for segment_id in segment_ids]

        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."
            )

        response = await self.send_device_command(
            clusters.ServiceArea.Commands.SelectAreas(newAreas=area_ids)
        )

        if (
            response
            and response.status != clusters.ServiceArea.Enums.SelectAreasStatus.kSuccess
        ):
            raise HomeAssistantError(
                f"Failed to select areas: {response.statusText or response.status.name}"
            )