From 5a9c3fea70ba1edb14f989211164b38bb25bce1f Mon Sep 17 00:00:00 2001 From: "Julien \"_FrnchFrgg_\" Rivaud" Date: Tue, 13 Apr 2021 21:33:46 +0200 Subject: [PATCH] Enable passing Amcrest/Dahua signals through as HA events (#49004) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some of the compatible hardware sends event signals that wouldn't map well to entities, e.g. NTP sync notifications, SIP registering information, or « doorbell button pressed » events with no « return to rest state » matching event to have a properly behaved binary sensor. Instead of only monitoring specific events, subscribe to all of them, and pass them through (in addition to handling them as before if they correspond to a configured binary sensor). Also bump python-amcrest to 1.7.2. Digest of the changes: * The library now passes through the event data instead of just presence of a "Start" member in in. * Connection to some devices has been fixed by not throwing the towel on minor errors. https://github.com/tchellomello/python-amcrest/compare/1.7.1...1.7.2 --- homeassistant/components/amcrest/__init__.py | 18 +++++++++++------- homeassistant/components/amcrest/manifest.json | 2 +- requirements_all.txt | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/amcrest/__init__.py b/homeassistant/components/amcrest/__init__.py index 71c277e578c..f6ddc210415 100644 --- a/homeassistant/components/amcrest/__init__.py +++ b/homeassistant/components/amcrest/__init__.py @@ -197,14 +197,17 @@ class AmcrestChecker(Http): def _monitor_events(hass, name, api, event_codes): - event_codes = ",".join(event_codes) + event_codes = set(event_codes) while True: api.available_flag.wait() try: - for code, start in api.event_actions(event_codes, retries=5): - signal = service_signal(SERVICE_EVENT, name, code) - _LOGGER.debug("Sending signal: '%s': %s", signal, start) - dispatcher_send(hass, signal, start) + for code, start in api.event_actions("All", retries=5): + event_data = {"camera": name, "event": code, "payload": start} + hass.bus.fire("amcrest", event_data) + if code in event_codes: + signal = service_signal(SERVICE_EVENT, name, code) + _LOGGER.debug("Sending signal: '%s': %s", signal, start) + dispatcher_send(hass, signal, start) except AmcrestError as error: _LOGGER.warning( "Error while processing events from %s camera: %r", name, error @@ -259,6 +262,7 @@ def setup(hass, config): discovery.load_platform(hass, CAMERA, DOMAIN, {CONF_NAME: name}, config) + event_codes = [] if binary_sensors: discovery.load_platform( hass, @@ -272,8 +276,8 @@ def setup(hass, config): for sensor_type in binary_sensors if sensor_type not in BINARY_POLLED_SENSORS ] - if event_codes: - _start_event_monitor(hass, name, api, event_codes) + + _start_event_monitor(hass, name, api, event_codes) if sensors: discovery.load_platform( diff --git a/homeassistant/components/amcrest/manifest.json b/homeassistant/components/amcrest/manifest.json index 869b65658d6..c4d719d3166 100644 --- a/homeassistant/components/amcrest/manifest.json +++ b/homeassistant/components/amcrest/manifest.json @@ -2,7 +2,7 @@ "domain": "amcrest", "name": "Amcrest", "documentation": "https://www.home-assistant.io/integrations/amcrest", - "requirements": ["amcrest==1.7.1"], + "requirements": ["amcrest==1.7.2"], "dependencies": ["ffmpeg"], "codeowners": [] } diff --git a/requirements_all.txt b/requirements_all.txt index 95c521ec872..58497938086 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -251,7 +251,7 @@ alpha_vantage==2.3.1 ambiclimate==0.2.1 # homeassistant.components.amcrest -amcrest==1.7.1 +amcrest==1.7.2 # homeassistant.components.androidtv androidtv[async]==0.0.57