2019-02-14 04:35:12 +00:00
|
|
|
"""Support for Lupusec Security System switches."""
|
2024-03-08 14:01:29 +00:00
|
|
|
|
2022-01-03 18:23:11 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2018-11-07 11:51:12 +00:00
|
|
|
from datetime import timedelta
|
2024-02-06 00:20:14 +00:00
|
|
|
from functools import partial
|
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-28 15:06:57 +00:00
|
|
|
from . import DOMAIN
|
|
|
|
from .entity import LupusecBaseSensor
|
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,
|
2024-02-06 00:20:14 +00:00
|
|
|
async_add_entities: 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-02-06 00:20:14 +00:00
|
|
|
partial_func = partial(data.get_devices, generic_type=device_types)
|
|
|
|
devices = await hass.async_add_executor_job(partial_func)
|
2018-11-07 11:51:12 +00:00
|
|
|
|
2024-03-13 20:28:21 +00:00
|
|
|
async_add_entities(
|
|
|
|
LupusecSwitch(device, config_entry.entry_id) for device in devices
|
|
|
|
)
|
2018-11-07 11:51:12 +00:00
|
|
|
|
|
|
|
|
2024-01-28 15:06:57 +00:00
|
|
|
class LupusecSwitch(LupusecBaseSensor, SwitchEntity):
|
2018-11-07 11:51:12 +00:00
|
|
|
"""Representation of a Lupusec switch."""
|
|
|
|
|
2024-01-28 15:06:57 +00:00
|
|
|
_attr_name = None
|
|
|
|
|
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
|
2024-01-28 18:26:05 +00:00
|
|
|
def is_on(self) -> bool:
|
2018-11-07 11:51:12 +00:00
|
|
|
"""Return true if device is on."""
|
|
|
|
return self._device.is_on
|