Repository: home-assistant/core
File: homeassistant/components/ads/light.py (Python)

Code before:
        ads_hub: AdsHub,
        ads_var_enable: str,
        ads_var_brightness: str | None,
        ads_var_color_temp_kelvin: str | None,
        min_color_temp_kelvin: int | None,
        max_color_temp_kelvin: int | None,
        name: str,
    ) -> None:
        """Initialize AdsLight entity."""
        super().__init__(ads_hub, name, ads_var_enable)
        self._state_dict[STATE_KEY_BRIGHTNESS] = None
        self._state_dict[STATE_KEY_COLOR_TEMP_KELVIN] = None
        self._ads_var_brightness = ads_var_brightness
        self._ads_var_color_temp_kelvin = ads_var_color_temp_kelvin
        self._min_color_temp_kelvin = min_color_temp_kelvin
        self._max_color_temp_kelvin = max_color_temp_kelvin

        # Determine supported color modes
        supported_modes = {ColorMode.ONOFF}
        if ads_var_brightness is not None:
            supported_modes.add(ColorMode.BRIGHTNESS)
        if ads_var_color_temp_kelvin is not None:
            supported_modes.add(ColorMode.COLOR_TEMP)

        self._attr_supported_color_modes = supported_modes
        self._attr_color_mode = next(iter(supported_modes))

        # Set color temperature range (static config values take precedence over defaults)
        self._attr_min_color_temp_kelvin = (
            min_color_temp_kelvin if min_color_temp_kelvin is not None else 2000
        )
        self._attr_max_color_temp_kelvin = (
            max_color_temp_kelvin if max_color_temp_kelvin is not None else 6500
        )

    async def async_added_to_hass(self) -> None:
        """Register device notification."""
        await self.async_initialize_device(self._ads_var, pyads.PLCTYPE_BOOL)

        if self._ads_var_brightness is not None:
            await self.async_initialize_device(
                self._ads_var_brightness,
                pyads.PLCTYPE_UINT,
                STATE_KEY_BRIGHTNESS,
            )

        if self._ads_var_color_temp_kelvin is not None:
            await self.async_initialize_device(
                self._ads_var_color_temp_kelvin,
                pyads.PLCTYPE_UINT,
                STATE_KEY_COLOR_TEMP_KELVIN,

Review comment (suggestion):
The order of elements in a set can differ from the sequence in which they were added.
Please use a `list` to avoid an unexpected order and then transform it to a `set` for `self._attr_supported_color_modes`.
Or keep it simple with a similar pattern to the one that was being used before the changes, where `self._attr_color_mode` is set and a color mode is added to `self._attr_supported_color_modes` if the condition is meet.

Code after:

    def __init__(
        self,
        ads_hub: AdsHub,
        ads_var_enable: str,
        ads_var_brightness: str | None,
        ads_var_color_temp_kelvin: str | None,
        min_color_temp_kelvin: int | None,
        max_color_temp_kelvin: int | None,
        name: str,
    ) -> None:
        """Initialize AdsLight entity."""
        super().__init__(ads_hub, name, ads_var_enable)
        self._state_dict[STATE_KEY_BRIGHTNESS] = None
        self._state_dict[STATE_KEY_COLOR_TEMP_KELVIN] = None
        self._ads_var_brightness = ads_var_brightness
        self._ads_var_color_temp_kelvin = ads_var_color_temp_kelvin

        # Determine supported color modes
        color_modes = {ColorMode.ONOFF}
        if ads_var_brightness is not None:
            color_modes.add(ColorMode.BRIGHTNESS)
        if ads_var_color_temp_kelvin is not None:
            color_modes.add(ColorMode.COLOR_TEMP)

        self._attr_supported_color_modes = filter_supported_color_modes(color_modes)
        self._attr_color_mode = next(iter(self._attr_supported_color_modes))

        # Set color temperature range (static config values take precedence over defaults)
        if ads_var_color_temp_kelvin is not None:
            self._attr_min_color_temp_kelvin = (
                min_color_temp_kelvin
                if min_color_temp_kelvin is not None
                else DEFAULT_MIN_KELVIN
            )
            self._attr_max_color_temp_kelvin = (
                max_color_temp_kelvin
                if max_color_temp_kelvin is not None
                else DEFAULT_MAX_KELVIN
            )

    async def async_added_to_hass(self) -> None:
        """Register device notification."""
        await self.async_initialize_device(self._ads_var, pyads.PLCTYPE_BOOL)

        if self._ads_var_brightness is not None:
            await self.async_initialize_device(
                self._ads_var_brightness,
                pyads.PLCTYPE_UINT,
                STATE_KEY_BRIGHTNESS,
            )