Home Assistant Unofficial Reference 2024.12.1
switch.py
Go to the documentation of this file.
1 """Support for XS1 switches."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from xs1_api_client.api_constants import ActuatorType
8 
9 from homeassistant.components.switch import SwitchEntity
10 from homeassistant.core import HomeAssistant
11 from homeassistant.helpers.entity_platform import AddEntitiesCallback
12 from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
13 
14 from . import ACTUATORS, DOMAIN as COMPONENT_DOMAIN
15 from .entity import XS1DeviceEntity
16 
17 
19  hass: HomeAssistant,
20  config: ConfigType,
21  add_entities: AddEntitiesCallback,
22  discovery_info: DiscoveryInfoType | None = None,
23 ) -> None:
24  """Set up the XS1 switch platform."""
25  actuators = hass.data[COMPONENT_DOMAIN][ACTUATORS]
26 
28  XS1SwitchEntity(actuator)
29  for actuator in actuators
30  if (actuator.type() == ActuatorType.SWITCH)
31  or (actuator.type() == ActuatorType.DIMMER)
32  )
33 
34 
36  """Representation of a XS1 switch actuator."""
37 
38  @property
39  def name(self):
40  """Return the name of the device if any."""
41  return self.devicedevice.name()
42 
43  @property
44  def is_on(self):
45  """Return true if switch is on."""
46  return self.devicedevice.value() == 100
47 
48  def turn_on(self, **kwargs: Any) -> None:
49  """Turn the device on."""
50  self.devicedevice.turn_on()
51 
52  def turn_off(self, **kwargs: Any) -> None:
53  """Turn the device off."""
54  self.devicedevice.turn_off()
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)
Definition: switch.py:23