Centralize august activity updates (#32197)
* Reduce August doorbell detail updates * Doorbell images now get updates from the activity feed * Tests for activity updates * py-august now provides bridge_is_online for available state * py-august now provides is_standby for available state * py-august now provides get_doorbell_image (eliminate requests) * remove debug * black after merge conflict * Centralize august activity updates * Updates appear significantly more responsive * Should address the community complaints about "lag" * Reduce detail updates (device end points) to one hour interval * Signal entities to update via dispatcher when new activity arrives * Resolves out of sync state (skipped test is now unskipped) * pylint * fix merge conflict * review comments * Remove stray * Address review items that can be done without refactor
This commit is contained in:
1 parent
d207c37c33
commit
4c5e364d90
9 files changed
+352
-117
No files matched your search
@@ -1,14 +1,22 @@
|
||||
"""Support for August camera."""
|
||||
from datetime import timedelta
|
||||
"""Support for August doorbell camera."""
|
||||
|
||||
from august.activity import ActivityType
|
||||
from august.util import update_doorbell_image_from_activity
|
||||
|
||||
from homeassistant.components.camera import Camera
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from .const import DATA_AUGUST, DEFAULT_NAME, DEFAULT_TIMEOUT, DOMAIN
|
||||
from .const import (
|
||||
AUGUST_DEVICE_UPDATE,
|
||||
DATA_AUGUST,
|
||||
DEFAULT_NAME,
|
||||
DEFAULT_TIMEOUT,
|
||||
DOMAIN,
|
||||
MIN_TIME_BETWEEN_DETAIL_UPDATES,
|
||||
)
|
||||
|
||||
SCAN_INTERVAL = timedelta(seconds=5)
|
||||
SCAN_INTERVAL = MIN_TIME_BETWEEN_DETAIL_UPDATES
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
@@ -28,6 +36,7 @@ class AugustCamera(Camera):
|
||||
def __init__(self, data, doorbell, timeout):
|
||||
"""Initialize a August security camera."""
|
||||
super().__init__()
|
||||
self._undo_dispatch_subscription = None
|
||||
self._data = data
|
||||
self._doorbell = doorbell
|
||||
self._doorbell_detail = None
|
||||
@@ -67,8 +76,8 @@ class AugustCamera(Camera):
|
||||
self._doorbell_detail = await self._data.async_get_doorbell_detail(
|
||||
self._doorbell.device_id
|
||||
)
|
||||
doorbell_activity = await self._data.async_get_latest_device_activity(
|
||||
self._doorbell.device_id, ActivityType.DOORBELL_MOTION
|
||||
doorbell_activity = self._data.activity_stream.async_get_latest_device_activity(
|
||||
self._doorbell.device_id, [ActivityType.DOORBELL_MOTION]
|
||||
)
|
||||
|
||||
if doorbell_activity is not None:
|
||||
@@ -117,3 +126,20 @@ class AugustCamera(Camera):
|
||||
"sw_version": self._firmware_version,
|
||||
"model": self._model,
|
||||
}
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
|
||||
@callback
|
||||
def update():
|
||||
"""Update the state."""
|
||||
self.async_schedule_update_ha_state(True)
|
||||
|
||||
self._undo_dispatch_subscription = async_dispatcher_connect(
|
||||
self.hass, f"{AUGUST_DEVICE_UPDATE}-{self._doorbell.device_id}", update
|
||||
)
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""Undo subscription."""
|
||||
if self._undo_dispatch_subscription:
|
||||
self._undo_dispatch_subscription()
|
||||
Reference in new issue
Block a user