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:
parent
45b53c8e82
commit
97224df4fd
13 changed files with 76 additions and 51 deletions
|
@ -20,10 +20,17 @@ from homeassistant.const import (
|
|||
CONF_USERNAME,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
)
|
||||
from homeassistant.helpers.dispatcher import dispatcher_send
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from .const import ATTRIBUTION, DOMAIN, DEFAULT_CACHEDB
|
||||
from .const import (
|
||||
ATTRIBUTION,
|
||||
DOMAIN,
|
||||
DEFAULT_CACHEDB,
|
||||
SIGNAL_CAPTURE_IMAGE,
|
||||
SIGNAL_TRIGGER_QUICK_ACTION,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -89,7 +96,7 @@ class AbodeSystem:
|
|||
|
||||
self.abode = abode
|
||||
self.polling = polling
|
||||
self.devices = []
|
||||
self.entity_ids = set()
|
||||
self.logout_listener = None
|
||||
|
||||
|
||||
|
@ -179,27 +186,29 @@ def setup_hass_services(hass):
|
|||
"""Capture a new image."""
|
||||
entity_ids = call.data.get(ATTR_ENTITY_ID)
|
||||
|
||||
target_devices = [
|
||||
device
|
||||
for device in hass.data[DOMAIN].devices
|
||||
if device.entity_id in entity_ids
|
||||
target_entities = [
|
||||
entity_id
|
||||
for entity_id in hass.data[DOMAIN].entity_ids
|
||||
if entity_id in entity_ids
|
||||
]
|
||||
|
||||
for device in target_devices:
|
||||
device.capture()
|
||||
for entity_id in target_entities:
|
||||
signal = SIGNAL_CAPTURE_IMAGE.format(entity_id)
|
||||
dispatcher_send(hass, signal)
|
||||
|
||||
def trigger_quick_action(call):
|
||||
"""Trigger a quick action."""
|
||||
entity_ids = call.data.get(ATTR_ENTITY_ID, None)
|
||||
|
||||
target_devices = [
|
||||
device
|
||||
for device in hass.data[DOMAIN].devices
|
||||
if device.entity_id in entity_ids
|
||||
target_entities = [
|
||||
entity_id
|
||||
for entity_id in hass.data[DOMAIN].entity_ids
|
||||
if entity_id in entity_ids
|
||||
]
|
||||
|
||||
for device in target_devices:
|
||||
device.trigger()
|
||||
for entity_id in target_entities:
|
||||
signal = SIGNAL_TRIGGER_QUICK_ACTION.format(entity_id)
|
||||
dispatcher_send(hass, signal)
|
||||
|
||||
hass.services.register(
|
||||
DOMAIN, SERVICE_SETTINGS, change_setting, schema=CHANGE_SETTING_SCHEMA
|
||||
|
@ -290,6 +299,7 @@ class AbodeDevice(Entity):
|
|||
self._device.device_id,
|
||||
self._update_callback,
|
||||
)
|
||||
self.hass.data[DOMAIN].entity_ids.add(self.entity_id)
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""Unsubscribe from device events."""
|
||||
|
@ -352,13 +362,14 @@ class AbodeAutomation(Entity):
|
|||
self._event = event
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe Abode events."""
|
||||
"""Subscribe to a group of Abode timeline events."""
|
||||
if self._event:
|
||||
self.hass.async_add_job(
|
||||
self._data.abode.events.add_event_callback,
|
||||
self._event,
|
||||
self._update_callback,
|
||||
)
|
||||
self.hass.data[DOMAIN].entity_ids.add(self.entity_id)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
|
|
|
@ -23,9 +23,8 @@ 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 an alarm control panel for an Abode device."""
|
||||
"""Set up Abode alarm control panel device."""
|
||||
data = hass.data[DOMAIN]
|
||||
|
||||
async_add_entities(
|
||||
[AbodeAlarm(data, await hass.async_add_executor_job(data.abode.get_alarm))]
|
||||
)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -7,10 +7,11 @@ import abodepy.helpers.timeline as TIMELINE
|
|||
import requests
|
||||
|
||||
from homeassistant.components.camera import Camera
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.util import Throttle
|
||||
|
||||
from . import AbodeDevice
|
||||
from .const import DOMAIN
|
||||
from .const import DOMAIN, SIGNAL_CAPTURE_IMAGE
|
||||
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=90)
|
||||
|
||||
|
@ -23,15 +24,15 @@ 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 camera for an Abode device."""
|
||||
|
||||
"""Set up Abode camera devices."""
|
||||
data = hass.data[DOMAIN]
|
||||
|
||||
devices = []
|
||||
for device in data.abode.get_devices(generic_type=CONST.TYPE_CAMERA):
|
||||
devices.append(AbodeCamera(data, device, TIMELINE.CAPTURE_IMAGE))
|
||||
entities = []
|
||||
|
||||
async_add_entities(devices)
|
||||
for device in data.abode.get_devices(generic_type=CONST.TYPE_CAMERA):
|
||||
entities.append(AbodeCamera(data, device, TIMELINE.CAPTURE_IMAGE))
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class AbodeCamera(AbodeDevice, Camera):
|
||||
|
@ -54,6 +55,9 @@ class AbodeCamera(AbodeDevice, Camera):
|
|||
self._capture_callback,
|
||||
)
|
||||
|
||||
signal = SIGNAL_CAPTURE_IMAGE.format(self.entity_id)
|
||||
async_dispatcher_connect(self.hass, signal, self.capture)
|
||||
|
||||
def capture(self):
|
||||
"""Request a new image capture."""
|
||||
return self._device.capture()
|
||||
|
|
|
@ -3,3 +3,6 @@ DOMAIN = "abode"
|
|||
ATTRIBUTION = "Data provided by goabode.com"
|
||||
|
||||
DEFAULT_CACHEDB = "abodepy_cache.pickle"
|
||||
|
||||
SIGNAL_CAPTURE_IMAGE = "abode_camera_capture_{}"
|
||||
SIGNAL_TRIGGER_QUICK_ACTION = "abode_trigger_quick_action_{}"
|
||||
|
|
|
@ -18,14 +18,14 @@ 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 Abode cover devices."""
|
||||
|
||||
data = hass.data[DOMAIN]
|
||||
|
||||
devices = []
|
||||
for device in data.abode.get_devices(generic_type=CONST.TYPE_COVER):
|
||||
devices.append(AbodeCover(data, device))
|
||||
entities = []
|
||||
|
||||
async_add_entities(devices)
|
||||
for device in data.abode.get_devices(generic_type=CONST.TYPE_COVER):
|
||||
entities.append(AbodeCover(data, device))
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class AbodeCover(AbodeDevice, CoverDevice):
|
||||
|
|
|
@ -33,12 +33,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
"""Set up Abode light devices."""
|
||||
data = hass.data[DOMAIN]
|
||||
|
||||
devices = []
|
||||
entities = []
|
||||
|
||||
for device in data.abode.get_devices(generic_type=CONST.TYPE_LIGHT):
|
||||
devices.append(AbodeLight(data, device))
|
||||
entities.append(AbodeLight(data, device))
|
||||
|
||||
async_add_entities(devices)
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class AbodeLight(AbodeDevice, Light):
|
||||
|
|
|
@ -18,14 +18,14 @@ 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 Abode lock devices."""
|
||||
|
||||
data = hass.data[DOMAIN]
|
||||
|
||||
devices = []
|
||||
for device in data.abode.get_devices(generic_type=CONST.TYPE_LOCK):
|
||||
devices.append(AbodeLock(data, device))
|
||||
entities = []
|
||||
|
||||
async_add_entities(devices)
|
||||
for device in data.abode.get_devices(generic_type=CONST.TYPE_LOCK):
|
||||
entities.append(AbodeLock(data, device))
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class AbodeLock(AbodeDevice, LockDevice):
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/abode",
|
||||
"requirements": [
|
||||
"abodepy==0.16.6"
|
||||
"abodepy==0.16.7"
|
||||
],
|
||||
"dependencies": [],
|
||||
"codeowners": [
|
||||
|
|
|
@ -28,8 +28,9 @@ 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 sensor devices."""
|
||||
data = hass.data[DOMAIN]
|
||||
|
||||
entities = []
|
||||
|
||||
for device in data.abode.get_devices(generic_type=CONST.TYPE_SENSOR):
|
||||
|
|
|
@ -21,17 +21,17 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
"""Set up Abode switch devices."""
|
||||
data = hass.data[DOMAIN]
|
||||
|
||||
devices = []
|
||||
entities = []
|
||||
|
||||
for device in data.abode.get_devices(generic_type=CONST.TYPE_SWITCH):
|
||||
devices.append(AbodeSwitch(data, device))
|
||||
entities.append(AbodeSwitch(data, device))
|
||||
|
||||
for automation in data.abode.get_automations(generic_type=CONST.TYPE_AUTOMATION):
|
||||
devices.append(
|
||||
entities.append(
|
||||
AbodeAutomationSwitch(data, automation, TIMELINE.AUTOMATION_EDIT_GROUP)
|
||||
)
|
||||
|
||||
async_add_entities(devices)
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class AbodeSwitch(AbodeDevice, SwitchDevice):
|
||||
|
|
|
@ -106,7 +106,7 @@ WazeRouteCalculator==0.10
|
|||
YesssSMS==0.4.1
|
||||
|
||||
# homeassistant.components.abode
|
||||
abodepy==0.16.6
|
||||
abodepy==0.16.7
|
||||
|
||||
# homeassistant.components.mcp23017
|
||||
adafruit-blinka==1.2.1
|
||||
|
|
|
@ -26,7 +26,7 @@ RtmAPI==0.7.2
|
|||
YesssSMS==0.4.1
|
||||
|
||||
# homeassistant.components.abode
|
||||
abodepy==0.16.6
|
||||
abodepy==0.16.7
|
||||
|
||||
# homeassistant.components.androidtv
|
||||
adb-shell==0.0.8
|
||||
|
|
Loading…
Add table
Reference in a new issue