diff --git a/homeassistant/components/abode/__init__.py b/homeassistant/components/abode/__init__.py index 76c14d7917f..1689576bc7f 100644 --- a/homeassistant/components/abode/__init__.py +++ b/homeassistant/components/abode/__init__.py @@ -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): diff --git a/homeassistant/components/abode/alarm_control_panel.py b/homeassistant/components/abode/alarm_control_panel.py index f774e773cb5..f1ff08f3a0a 100644 --- a/homeassistant/components/abode/alarm_control_panel.py +++ b/homeassistant/components/abode/alarm_control_panel.py @@ -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))] ) diff --git a/homeassistant/components/abode/binary_sensor.py b/homeassistant/components/abode/binary_sensor.py index 31f74448496..56c7bbcc1ff 100644 --- a/homeassistant/components/abode/binary_sensor.py +++ b/homeassistant/components/abode/binary_sensor.py @@ -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() diff --git a/homeassistant/components/abode/camera.py b/homeassistant/components/abode/camera.py index e98a59a985c..c6f366e0e51 100644 --- a/homeassistant/components/abode/camera.py +++ b/homeassistant/components/abode/camera.py @@ -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() diff --git a/homeassistant/components/abode/const.py b/homeassistant/components/abode/const.py index 092843ba212..267eb04f72e 100644 --- a/homeassistant/components/abode/const.py +++ b/homeassistant/components/abode/const.py @@ -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_{}" diff --git a/homeassistant/components/abode/cover.py b/homeassistant/components/abode/cover.py index ebe59ee45c7..a4fce7e7b8a 100644 --- a/homeassistant/components/abode/cover.py +++ b/homeassistant/components/abode/cover.py @@ -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): diff --git a/homeassistant/components/abode/light.py b/homeassistant/components/abode/light.py index 163982d040e..f29270d264c 100644 --- a/homeassistant/components/abode/light.py +++ b/homeassistant/components/abode/light.py @@ -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): diff --git a/homeassistant/components/abode/lock.py b/homeassistant/components/abode/lock.py index 11f792f88fd..e7ed40849de 100644 --- a/homeassistant/components/abode/lock.py +++ b/homeassistant/components/abode/lock.py @@ -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): diff --git a/homeassistant/components/abode/manifest.json b/homeassistant/components/abode/manifest.json index b54120c7cbd..0a4307ff737 100644 --- a/homeassistant/components/abode/manifest.json +++ b/homeassistant/components/abode/manifest.json @@ -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": [ diff --git a/homeassistant/components/abode/sensor.py b/homeassistant/components/abode/sensor.py index 6ee0cf59cbf..d84bfe52441 100644 --- a/homeassistant/components/abode/sensor.py +++ b/homeassistant/components/abode/sensor.py @@ -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): diff --git a/homeassistant/components/abode/switch.py b/homeassistant/components/abode/switch.py index 7bd7f394d30..c092c1ef3f0 100644 --- a/homeassistant/components/abode/switch.py +++ b/homeassistant/components/abode/switch.py @@ -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): diff --git a/requirements_all.txt b/requirements_all.txt index 29b94d40644..a34191c4a5c 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index ceb63df9896..691e8d413d5 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -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