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

Code before:
        """Return the brightness of this light between 0..255."""
        return self._brightness

    @property
    def color_mode(self) -> ColorMode | None:
        """Return the color mode of the light."""
        return self._color_mode

    @property
    def color_temp_kelvin(self) -> int | None:
        """Return the color temperature value in Kelvin."""
        return (
            color_util.color_temperature_mired_to_kelvin(self._color_temp)
            if self._color_temp
            else None
        )

    @property
    def max_color_temp_kelvin(self) -> int:
        """Return the coldest color_temp_kelvin that this light supports."""
        return color_util.color_temperature_mired_to_kelvin(
            self._tasmota_entity.min_mireds
        )

    @property
    def min_color_temp_kelvin(self) -> int:
        """Return the warmest color_temp_kelvin that this light supports."""
        return color_util.color_temperature_mired_to_kelvin(
            self._tasmota_entity.max_mireds
        )

    @property
    def effect(self) -> str | None:
        """Return the current effect."""
        return self._effect

    @property
    def effect_list(self) -> list[str] | None:
        """Return the list of supported effects."""
        return self._tasmota_entity.effect_list

    @property
    def hs_color(self) -> tuple[float, float] | None:
        """Return the hs color value."""
        if self._hs is None:
            return None
        hs_color = self._hs
        return (hs_color[0], hs_color[1])

    @property
    def supported_color_modes(self) -> set[ColorMode] | None:

Review comment (refactor):
Side note: Will we be able to clean up other integrations which have now redundant None-checks when accessing `supported_color_modes ?

Code after:
    @property
    def max_color_temp_kelvin(self) -> int:
        """Return the coldest color_temp_kelvin that this light supports."""
        return color_util.color_temperature_mired_to_kelvin(
            self._tasmota_entity.min_mireds
        )

    @property
    def min_color_temp_kelvin(self) -> int:
        """Return the warmest color_temp_kelvin that this light supports."""
        return color_util.color_temperature_mired_to_kelvin(
            self._tasmota_entity.max_mireds
        )

    @property
    def effect_list(self) -> list[str] | None:
        """Return the list of supported effects."""
        return self._tasmota_entity.effect_list

    async def async_turn_on(self, **kwargs: Any) -> None:
        """Turn the entity on."""
        supported_color_modes = self._attr_supported_color_modes

        attributes: dict[str, Any] = {}

        if ATTR_HS_COLOR in kwargs and ColorMode.HS in supported_color_modes:  # type: ignore[operator]
            hs_color = kwargs[ATTR_HS_COLOR]
            attributes["color_hs"] = [hs_color[0], hs_color[1]]

        if ATTR_WHITE in kwargs and ColorMode.WHITE in supported_color_modes:  # type: ignore[operator]
            attributes["white_value"] = scale_brightness(kwargs[ATTR_WHITE])

        if ATTR_TRANSITION in kwargs:
            attributes["transition"] = kwargs[ATTR_TRANSITION]

        if ATTR_BRIGHTNESS in kwargs and brightness_supported(supported_color_modes):
            attributes["brightness"] = scale_brightness(kwargs[ATTR_BRIGHTNESS])

        if (
            ATTR_COLOR_TEMP_KELVIN in kwargs
            and ColorMode.COLOR_TEMP in supported_color_modes  # type: ignore[operator]
        ):
            attributes["color_temp"] = color_util.color_temperature_kelvin_to_mired(
                kwargs[ATTR_COLOR_TEMP_KELVIN]
            )

        if ATTR_EFFECT in kwargs:
            attributes["effect"] = kwargs[ATTR_EFFECT]

        await self._tasmota_entity.set_state(True, attributes)