Home Assistant Unofficial Reference 2024.12.1
light.py
Go to the documentation of this file.
1 """Support for Balboa Spa lights."""
2 
3 from __future__ import annotations
4 
5 from typing import Any, cast
6 
7 from pybalboa import SpaControl
8 from pybalboa.enums import OffOnState, UnknownState
9 
10 from homeassistant.components.light import ColorMode, LightEntity
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.entity_platform import AddEntitiesCallback
13 
14 from . import BalboaConfigEntry
15 from .entity import BalboaEntity
16 
17 
19  hass: HomeAssistant,
20  entry: BalboaConfigEntry,
21  async_add_entities: AddEntitiesCallback,
22 ) -> None:
23  """Set up the spa's lights."""
24  spa = entry.runtime_data
25  async_add_entities(BalboaLightEntity(control) for control in spa.lights)
26 
27 
29  """Representation of a Balboa Spa light entity."""
30 
31  _attr_color_mode = ColorMode.ONOFF
32  _attr_supported_color_modes = {ColorMode.ONOFF}
33 
34  def __init__(self, control: SpaControl) -> None:
35  """Initialize a Balboa Spa light entity."""
36  super().__init__(control.client, control.name)
37  self._control_control = control
38  self._attr_translation_key_attr_translation_key = (
39  "light_of_n" if len(control.client.lights) > 1 else "only_light"
40  )
41  self._attr_translation_placeholders_attr_translation_placeholders = {
42  "index": f"{cast(int, control.index) + 1}"
43  }
44 
45  async def async_turn_off(self, **kwargs: Any) -> None:
46  """Turn the light off."""
47  await self._control_control.set_state(OffOnState.OFF)
48 
49  async def async_turn_on(self, **kwargs: Any) -> None:
50  """Turn the light on."""
51  await self._control_control.set_state(OffOnState.ON)
52 
53  @property
54  def is_on(self) -> bool | None:
55  """Return true if the light is on."""
56  if self._control_control.state == UnknownState.UNKNOWN:
57  return None
58  return self._control_control.state != OffOnState.OFF
None __init__(self, SpaControl control)
Definition: light.py:34
None async_setup_entry(HomeAssistant hass, BalboaConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: light.py:22