Home Assistant Unofficial Reference 2024.12.1
light.py
Go to the documentation of this file.
1 """The lookin integration light platform."""
2 
3 from __future__ import annotations
4 
5 import logging
6 from typing import Any
7 
8 from homeassistant.components.light import ColorMode, LightEntity
9 from homeassistant.config_entries import ConfigEntry
10 from homeassistant.const import Platform
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.entity_platform import AddEntitiesCallback
13 
14 from .const import DOMAIN, TYPE_TO_PLATFORM
15 from .entity import LookinPowerPushRemoteEntity
16 from .models import LookinData
17 
18 LOGGER = logging.getLogger(__name__)
19 
20 
22  hass: HomeAssistant,
23  config_entry: ConfigEntry,
24  async_add_entities: AddEntitiesCallback,
25 ) -> None:
26  """Set up the light platform for lookin from a config entry."""
27  lookin_data: LookinData = hass.data[DOMAIN][config_entry.entry_id]
28  entities = []
29 
30  for remote in lookin_data.devices:
31  if TYPE_TO_PLATFORM.get(remote["Type"]) != Platform.LIGHT:
32  continue
33  uuid = remote["UUID"]
34  coordinator = lookin_data.device_coordinators[uuid]
35  device = coordinator.data
36  entities.append(
38  coordinator=coordinator,
39  uuid=uuid,
40  device=device,
41  lookin_data=lookin_data,
42  )
43  )
44 
45  async_add_entities(entities)
46 
47 
49  """A lookin IR controlled light."""
50 
51  _attr_supported_color_modes = {ColorMode.ONOFF}
52  _attr_color_mode = ColorMode.ONOFF
53 
54  async def async_turn_on(self, **kwargs: Any) -> None:
55  """Turn on the light."""
56  await self._async_send_command_async_send_command(self._power_on_command_power_on_command)
57  self._attr_is_on_attr_is_on = True
58  self.async_write_ha_stateasync_write_ha_state()
59 
60  async def async_turn_off(self, **kwargs: Any) -> None:
61  """Turn off the light."""
62  await self._async_send_command_async_send_command(self._power_off_command_power_off_command)
63  self._attr_is_on_attr_is_on = False
64  self.async_write_ha_stateasync_write_ha_state()
65 
66  def _update_from_status(self, status: str) -> None:
67  """Update media property from status.
68 
69  1000
70  0 - 0/1 on/off
71  """
72  if len(status) != 4:
73  return
74  state = status[0]
75 
76  self._attr_is_on_attr_is_on = state == "1"
None _async_send_command(self, str command, str signal="FF")
Definition: entity.py:122
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: light.py:25