2019-02-14 04:35:12 +00:00
|
|
|
"""Support for Lupusec Security System switches."""
|
2022-01-03 18:23:11 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2018-11-07 11:51:12 +00:00
|
|
|
from datetime import timedelta
|
2022-09-01 12:14:31 +00:00
|
|
|
from typing import Any
|
2018-11-07 11:51:12 +00:00
|
|
|
|
2019-10-21 08:07:09 +00:00
|
|
|
import lupupy.constants as CONST
|
|
|
|
|
2020-04-26 16:50:37 +00:00
|
|
|
from homeassistant.components.switch import SwitchEntity
|
2024-01-25 17:52:30 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2022-01-03 18:23:11 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2018-11-07 11:51:12 +00:00
|
|
|
|
2024-01-25 17:52:30 +00:00
|
|
|
from . import DOMAIN, LupusecDevice
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2018-11-07 11:51:12 +00:00
|
|
|
SCAN_INTERVAL = timedelta(seconds=2)
|
|
|
|
|
|
|
|
|
2024-01-25 17:52:30 +00:00
|
|
|
async def async_setup_entry(
|
2022-01-03 18:23:11 +00:00
|
|
|
hass: HomeAssistant,
|
2024-01-25 17:52:30 +00:00
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_devices: AddEntitiesCallback,
|
2022-01-03 18:23:11 +00:00
|
|
|
) -> None:
|
2018-11-07 11:51:12 +00:00
|
|
|
"""Set up Lupusec switch devices."""
|
|
|
|
|
2024-01-25 17:52:30 +00:00
|
|
|
data = hass.data[DOMAIN][config_entry.entry_id]
|
2018-11-07 11:51:12 +00:00
|
|
|
|
2023-11-13 09:37:49 +00:00
|
|
|
device_types = CONST.TYPE_SWITCH
|
2018-11-07 11:51:12 +00:00
|
|
|
|
2024-01-25 17:52:30 +00:00
|
|
|
switches = []
|
2023-11-07 13:46:02 +00:00
|
|
|
for device in data.lupusec.get_devices(generic_type=device_types):
|
2024-01-25 17:52:30 +00:00
|
|
|
switches.append(LupusecSwitch(data, device))
|
2018-11-07 11:51:12 +00:00
|
|
|
|
2024-01-25 17:52:30 +00:00
|
|
|
async_add_devices(switches)
|
2018-11-07 11:51:12 +00:00
|
|
|
|
|
|
|
|
2020-04-26 16:50:37 +00:00
|
|
|
class LupusecSwitch(LupusecDevice, SwitchEntity):
|
2018-11-07 11:51:12 +00:00
|
|
|
"""Representation of a Lupusec switch."""
|
|
|
|
|
2022-09-01 12:14:31 +00:00
|
|
|
def turn_on(self, **kwargs: Any) -> None:
|
2018-11-07 11:51:12 +00:00
|
|
|
"""Turn on the device."""
|
|
|
|
self._device.switch_on()
|
|
|
|
|
2022-09-01 12:14:31 +00:00
|
|
|
def turn_off(self, **kwargs: Any) -> None:
|
2018-11-07 11:51:12 +00:00
|
|
|
"""Turn off the device."""
|
|
|
|
self._device.switch_off()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return true if device is on."""
|
|
|
|
return self._device.is_on
|