2019-02-14 04:35:12 +00:00
|
|
|
"""Support for Lupusec Security System switches."""
|
2018-11-07 11:51:12 +00:00
|
|
|
from datetime import timedelta
|
2019-03-21 05:56:46 +00:00
|
|
|
import logging
|
2018-11-07 11:51:12 +00:00
|
|
|
|
2019-10-21 08:07:09 +00:00
|
|
|
import lupupy.constants as CONST
|
|
|
|
|
2018-11-07 11:51:12 +00:00
|
|
|
from homeassistant.components.switch import SwitchDevice
|
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import DOMAIN as LUPUSEC_DOMAIN, LupusecDevice
|
|
|
|
|
2018-11-07 11:51:12 +00:00
|
|
|
SCAN_INTERVAL = timedelta(seconds=2)
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
|
|
|
"""Set up Lupusec switch devices."""
|
|
|
|
if discovery_info is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
data = hass.data[LUPUSEC_DOMAIN]
|
|
|
|
|
|
|
|
devices = []
|
|
|
|
|
|
|
|
for device in data.lupusec.get_devices(generic_type=CONST.TYPE_SWITCH):
|
|
|
|
|
|
|
|
devices.append(LupusecSwitch(data, device))
|
|
|
|
|
|
|
|
add_entities(devices)
|
|
|
|
|
|
|
|
|
|
|
|
class LupusecSwitch(LupusecDevice, SwitchDevice):
|
|
|
|
"""Representation of a Lupusec switch."""
|
|
|
|
|
|
|
|
def turn_on(self, **kwargs):
|
|
|
|
"""Turn on the device."""
|
|
|
|
self._device.switch_on()
|
|
|
|
|
|
|
|
def turn_off(self, **kwargs):
|
|
|
|
"""Turn off the device."""
|
|
|
|
self._device.switch_off()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return true if device is on."""
|
|
|
|
return self._device.is_on
|