hass-core/homeassistant/components/amcrest/helpers.py
Phil Bruckner 0ed7bc3b8e
Convert amcrest binary sensors from poll to stream (#32818)
* Convert amcrest binary sensors from poll to stream

- Bump amcrest package to 1.6.0.
- For online binary sensor poll camera periodically to test communications in case
  configuration & usage results in no other communication to camera.
- Start a separate thread to call camera's event_stream method since it never returns.
- Convert all received events into signals that cause corresponding sensors to update.
- Use camera's generic event_channels_happened method to update sensors at startup,
  and whenever camera comes back online after being unavailable.

* Changes per review

* Changes per review 2

* Changes per review 3

- Move event stream decoding to amcrest package.
- Change name of event processing threads so global
  counter is no longer required.
- Bump amcrest package to 1.7.0.
2020-03-19 21:07:21 -07:00

18 lines
425 B
Python

"""Helpers for amcrest component."""
from .const import DOMAIN
def service_signal(service, *args):
"""Encode signal."""
return "_".join([DOMAIN, service, *args])
def log_update_error(logger, action, name, entity_type, error):
"""Log an update error."""
logger.error(
"Could not %s %s %s due to error: %s",
action,
name,
entity_type,
error.__class__.__name__,
)