Home Assistant Unofficial Reference 2024.12.1
light.py
Go to the documentation of this file.
1 """Support for Dynalite channels as lights."""
2 
3 from typing import Any
4 
5 from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity
6 from homeassistant.config_entries import ConfigEntry
7 from homeassistant.core import HomeAssistant
8 from homeassistant.helpers.entity_platform import AddEntitiesCallback
9 
10 from .entity import DynaliteBase, async_setup_entry_base
11 
12 
14  hass: HomeAssistant,
15  config_entry: ConfigEntry,
16  async_add_entities: AddEntitiesCallback,
17 ) -> None:
18  """Record the async_add_entities function to add them later when received from Dynalite."""
20  hass, config_entry, async_add_entities, "light", DynaliteLight
21  )
22 
23 
25  """Representation of a Dynalite Channel as a Home Assistant Light."""
26 
27  _attr_color_mode = ColorMode.BRIGHTNESS
28  _attr_supported_color_modes = {ColorMode.BRIGHTNESS}
29 
30  @property
31  def brightness(self) -> int:
32  """Return the brightness of this light between 0..255."""
33  return self._device_device.brightness
34 
35  @property
36  def is_on(self) -> bool:
37  """Return true if device is on."""
38  return self._device_device.is_on
39 
40  async def async_turn_on(self, **kwargs: Any) -> None:
41  """Turn the light on."""
42  await self._device_device.async_turn_on(**kwargs)
43 
44  async def async_turn_off(self, **kwargs: Any) -> None:
45  """Turn the light off."""
46  await self._device_device.async_turn_off(**kwargs)
47 
48  def initialize_state(self, state):
49  """Initialize the state from cache."""
50  target_level = state.attributes.get(ATTR_BRIGHTNESS)
51  if target_level is not None:
52  self._device_device.init_level(target_level)
None async_setup_entry_base(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities, str platform, Callable entity_from_device)
Definition: entity.py:26
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: light.py:17