Home Assistant Unofficial Reference 2024.12.1
switch.py
Go to the documentation of this file.
1 """Support for Lupusec Security System switches."""
2 
3 from __future__ import annotations
4 
5 from datetime import timedelta
6 from functools import partial
7 from typing import Any
8 
9 import lupupy.constants as CONST
10 
11 from homeassistant.components.switch import SwitchEntity
12 from homeassistant.config_entries import ConfigEntry
13 from homeassistant.core import HomeAssistant
14 from homeassistant.helpers.entity_platform import AddEntitiesCallback
15 
16 from . import DOMAIN
17 from .entity import LupusecBaseSensor
18 
19 SCAN_INTERVAL = timedelta(seconds=2)
20 
21 
23  hass: HomeAssistant,
24  config_entry: ConfigEntry,
25  async_add_entities: AddEntitiesCallback,
26 ) -> None:
27  """Set up Lupusec switch devices."""
28 
29  data = hass.data[DOMAIN][config_entry.entry_id]
30 
31  device_types = CONST.TYPE_SWITCH
32 
33  partial_func = partial(data.get_devices, generic_type=device_types)
34  devices = await hass.async_add_executor_job(partial_func)
35 
37  LupusecSwitch(device, config_entry.entry_id) for device in devices
38  )
39 
40 
42  """Representation of a Lupusec switch."""
43 
44  _attr_name = None
45 
46  def turn_on(self, **kwargs: Any) -> None:
47  """Turn on the device."""
48  self._device_device.switch_on()
49 
50  def turn_off(self, **kwargs: Any) -> None:
51  """Turn off the device."""
52  self._device_device.switch_off()
53 
54  @property
55  def is_on(self) -> bool:
56  """Return true if device is on."""
57  return self._device_device.is_on
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: switch.py:26