2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Abode Security System switches."""
|
2017-08-29 15:34:19 +00:00
|
|
|
import logging
|
|
|
|
|
2019-10-12 20:02:12 +00:00
|
|
|
import abodepy.helpers.constants as CONST
|
|
|
|
import abodepy.helpers.timeline as TIMELINE
|
|
|
|
|
2017-08-29 15:34:19 +00:00
|
|
|
from homeassistant.components.switch import SwitchDevice
|
|
|
|
|
2019-10-13 18:01:04 +00:00
|
|
|
from . import AbodeAutomation, AbodeDevice
|
|
|
|
from .const import DOMAIN
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2019-02-13 20:21:14 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2017-08-29 15:34:19 +00:00
|
|
|
|
|
|
|
|
2019-10-13 18:01:04 +00:00
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
|
|
"""Set up Abode switch devices."""
|
|
|
|
data = hass.data[DOMAIN]
|
2017-08-29 15:34:19 +00:00
|
|
|
|
2019-11-09 06:35:45 +00:00
|
|
|
entities = []
|
2017-08-29 15:34:19 +00:00
|
|
|
|
2017-09-18 15:39:41 +00:00
|
|
|
for device in data.abode.get_devices(generic_type=CONST.TYPE_SWITCH):
|
2019-11-09 06:35:45 +00:00
|
|
|
entities.append(AbodeSwitch(data, device))
|
2017-09-18 15:39:41 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
for automation in data.abode.get_automations(generic_type=CONST.TYPE_AUTOMATION):
|
2019-11-09 06:35:45 +00:00
|
|
|
entities.append(
|
2019-07-31 19:25:30 +00:00
|
|
|
AbodeAutomationSwitch(data, automation, TIMELINE.AUTOMATION_EDIT_GROUP)
|
|
|
|
)
|
2017-09-18 15:39:41 +00:00
|
|
|
|
2019-11-09 06:35:45 +00:00
|
|
|
async_add_entities(entities)
|
2017-08-29 15:34:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AbodeSwitch(AbodeDevice, SwitchDevice):
|
|
|
|
"""Representation of an Abode 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
|
2017-09-18 15:39:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AbodeAutomationSwitch(AbodeAutomation, SwitchDevice):
|
|
|
|
"""A switch implementation for Abode automations."""
|
|
|
|
|
|
|
|
def turn_on(self, **kwargs):
|
|
|
|
"""Turn on the device."""
|
|
|
|
self._automation.set_active(True)
|
|
|
|
|
|
|
|
def turn_off(self, **kwargs):
|
|
|
|
"""Turn off the device."""
|
|
|
|
self._automation.set_active(False)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return True if the binary sensor is on."""
|
|
|
|
return self._automation.is_active
|