Home Assistant Unofficial Reference 2024.12.1
switch.py
Go to the documentation of this file.
1 """Support for HLK-SW16 switches."""
2 
3 from typing import Any
4 
5 from homeassistant.components.switch import SwitchEntity
6 from homeassistant.config_entries import ConfigEntry
7 from homeassistant.core import HomeAssistant
8 from homeassistant.helpers.entity_platform import AddEntitiesCallback
9 
10 from . import DATA_DEVICE_REGISTER
11 from .const import DOMAIN
12 from .entity import SW16Entity
13 
14 PARALLEL_UPDATES = 0
15 
16 
17 def devices_from_entities(hass, entry):
18  """Parse configuration and add HLK-SW16 switch devices."""
19  device_client = hass.data[DOMAIN][entry.entry_id][DATA_DEVICE_REGISTER]
20  devices = []
21  for i in range(16):
22  device_port = f"{i:01x}"
23  device = SW16Switch(device_port, entry.entry_id, device_client)
24  devices.append(device)
25  return devices
26 
27 
29  hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
30 ) -> None:
31  """Set up the HLK-SW16 platform."""
33 
34 
36  """Representation of a HLK-SW16 switch."""
37 
38  @property
39  def is_on(self):
40  """Return true if device is on."""
41  return self._is_on_is_on
42 
43  async def async_turn_on(self, **kwargs: Any) -> None:
44  """Turn the device on."""
45  await self._client_client.turn_on(self._device_port_device_port)
46 
47  async def async_turn_off(self, **kwargs: Any) -> None:
48  """Turn the device off."""
49  await self._client_client.turn_off(self._device_port_device_port)
None turn_off(self, **Any kwargs)
Definition: entity.py:1705
None turn_on(self, **Any kwargs)
Definition: entity.py:1697
def devices_from_entities(hass, entry)
Definition: switch.py:17
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: switch.py:30