Enable passing Amcrest/Dahua signals through as HA events (#49004)

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
This commit is contained in:
Julien "_FrnchFrgg_" Rivaud 2021-04-13 21:33:46 +02:00 committed by GitHub
parent 5d57e5c06c
commit 5a9c3fea70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 9 deletions

View File

@ -197,11 +197,14 @@ 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):
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)
@ -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,7 +276,7 @@ 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)
if sensors:

View File

@ -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": []
}

View File

@ -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