"""Light/LED support for the Skybell HD Doorbell."""
from __future__ import annotations

from homeassistant.components.light import (
    ATTR_BRIGHTNESS,
    ATTR_HS_COLOR,
    SUPPORT_BRIGHTNESS,
    SUPPORT_COLOR,
    LightEntity,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
import homeassistant.util.color as color_util

from . import DOMAIN as SKYBELL_DOMAIN, SkybellDevice


def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the platform for a Skybell device."""
    skybell = hass.data[SKYBELL_DOMAIN]

    sensors = []
    for device in skybell.get_devices():
        sensors.append(SkybellLight(device))

    add_entities(sensors, True)


def _to_skybell_level(level):
    """Convert the given Home Assistant light level (0-255) to Skybell (0-100)."""
    return int((level * 100) / 255)


def _to_hass_level(level):
    """Convert the given Skybell (0-100) light level to Home Assistant (0-255)."""
    return int((level * 255) / 100)


class SkybellLight(SkybellDevice, LightEntity):
    """A binary sensor implementation for Skybell devices."""

    def __init__(self, device):
        """Initialize a light for a Skybell device."""
        super().__init__(device)
        self._name = self._device.name

    @property
    def name(self):
        """Return the name of the sensor."""
        return self._name

    def turn_on(self, **kwargs):
        """Turn on the light."""
        if ATTR_HS_COLOR in kwargs:
            rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
            self._device.led_rgb = rgb
        elif ATTR_BRIGHTNESS in kwargs:
            self._device.led_intensity = _to_skybell_level(kwargs[ATTR_BRIGHTNESS])
        else:
            self._device.led_intensity = _to_skybell_level(255)

    def turn_off(self, **kwargs):
        """Turn off the light."""
        self._device.led_intensity = 0

    @property
    def is_on(self):
        """Return true if device is on."""
        return self._device.led_intensity > 0

    @property
    def brightness(self):
        """Return the brightness of the light."""
        return _to_hass_level(self._device.led_intensity)

    @property
    def hs_color(self):
        """Return the color of the light."""
        return color_util.color_RGB_to_hs(*self._device.led_rgb)

    @property
    def supported_features(self):
        """Flag supported features."""
        return SUPPORT_BRIGHTNESS | SUPPORT_COLOR

@@ -175,45 +175,17 @@
     
-SUPPORT_BRIGHTNESS,%0A    SUPPORT_COLOR
+ColorMode
 ,%0A  
@@ -1303,16 +1303,102 @@
 es.%22%22%22%0A%0A
+    _attr_color_mode = ColorMode.HS%0A    _attr_supported_color_modes = %7BColorMode.HS%7D%0A%0A
     def 
@@ -1527,21 +1527,20 @@
 lf._
+attr_
 name = 
-self._
 devi
@@ -1552,114 +1552,8 @@
 me%0A%0A
-    @property%0A    def name(self):%0A        %22%22%22Return the name of the sensor.%22%22%22%0A        return self._name%0A%0A
     
@@ -2418,32 +2418,32 @@
 f the light.%22%22%22%0A
+
         return c
@@ -2495,142 +2495,4 @@
 gb)%0A
-%0A    @property%0A    def supported_features(self):%0A        %22%22%22Flag supported features.%22%22%22%0A        return SUPPORT_BRIGHTNESS %7C SUPPORT_COLOR%0A

Migrate skybell light to ColorMode (#70878)