Home Assistant Unofficial Reference 2024.12.1
light.py
Go to the documentation of this file.
1 """Light/LED support for the Skybell HD Doorbell."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from aioskybell.helpers.const import BRIGHTNESS, RGB_COLOR
8 
10  ATTR_BRIGHTNESS,
11  ATTR_RGB_COLOR,
12  ColorMode,
13  LightEntity,
14  LightEntityDescription,
15 )
16 from homeassistant.config_entries import ConfigEntry
17 from homeassistant.core import HomeAssistant
18 from homeassistant.helpers.entity_platform import AddEntitiesCallback
19 
20 from .const import DOMAIN
21 from .entity import SkybellEntity
22 
23 
25  hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
26 ) -> None:
27  """Set up Skybell switch."""
29  SkybellLight(coordinator, LightEntityDescription(key="light"))
30  for coordinator in hass.data[DOMAIN][entry.entry_id]
31  )
32 
33 
35  """A light implementation for Skybell devices."""
36 
37  _attr_color_mode = ColorMode.RGB
38  _attr_supported_color_modes = {ColorMode.RGB}
39  _attr_name = None
40 
41  async def async_turn_on(self, **kwargs: Any) -> None:
42  """Turn on the light."""
43  if ATTR_RGB_COLOR in kwargs:
44  await self._device_device.async_set_setting(RGB_COLOR, kwargs[ATTR_RGB_COLOR])
45  if ATTR_BRIGHTNESS in kwargs:
46  level = int((kwargs.get(ATTR_BRIGHTNESS, 0) * 100) / 255)
47  await self._device_device.async_set_setting(BRIGHTNESS, level)
48 
49  async def async_turn_off(self, **kwargs: Any) -> None:
50  """Turn off the light."""
51  await self._device_device.async_set_setting(ATTR_BRIGHTNESS, 0)
52 
53  @property
54  def is_on(self) -> bool:
55  """Return true if device is on."""
56  return self._device_device.led_intensity > 0
57 
58  @property
59  def brightness(self) -> int:
60  """Return the brightness of the light."""
61  return int((self._device_device.led_intensity * 255) / 100)
62 
63  @property
64  def rgb_color(self) -> tuple[int, int, int] | None:
65  """Return the rgb color value [int, int, int]."""
66  return self._device_device.led_rgb
tuple[int, int, int]|None rgb_color(self)
Definition: light.py:64
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: light.py:26