Fix Abode capture_image and trigger_quick_action services (#28546)

* Fix Abode services

* Bump abodepy version

* Updated using dispatcher helper

* Code review fixes

* Removed init method from AbodeQuickActionBinary Sensor
This commit is contained in:
shred86 2019-11-08 22:35:45 -08:00 committed by Martin Hjelmare
parent 45b53c8e82
commit 97224df4fd
13 changed files with 76 additions and 51 deletions

View file

@ -5,9 +5,10 @@ import abodepy.helpers.constants as CONST
import abodepy.helpers.timeline as TIMELINE
from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from . import AbodeAutomation, AbodeDevice
from .const import DOMAIN
from .const import DOMAIN, SIGNAL_TRIGGER_QUICK_ACTION
_LOGGER = logging.getLogger(__name__)
@ -18,7 +19,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up a sensor for an Abode device."""
"""Set up Abode binary sensor devices."""
data = hass.data[DOMAIN]
device_types = [
@ -29,19 +30,19 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
CONST.TYPE_OPENING,
]
devices = []
entities = []
for device in data.abode.get_devices(generic_type=device_types):
devices.append(AbodeBinarySensor(data, device))
entities.append(AbodeBinarySensor(data, device))
for automation in data.abode.get_automations(generic_type=CONST.TYPE_QUICK_ACTION):
devices.append(
entities.append(
AbodeQuickActionBinarySensor(
data, automation, TIMELINE.AUTOMATION_EDIT_GROUP
)
)
async_add_entities(devices)
async_add_entities(entities)
class AbodeBinarySensor(AbodeDevice, BinarySensorDevice):
@ -61,6 +62,12 @@ class AbodeBinarySensor(AbodeDevice, BinarySensorDevice):
class AbodeQuickActionBinarySensor(AbodeAutomation, BinarySensorDevice):
"""A binary sensor implementation for Abode quick action automations."""
async def async_added_to_hass(self):
"""Subscribe Abode events."""
await super().async_added_to_hass()
signal = SIGNAL_TRIGGER_QUICK_ACTION.format(self.entity_id)
async_dispatcher_connect(self.hass, signal, self.trigger)
def trigger(self):
"""Trigger a quick automation."""
self._automation.trigger()