From ed286fc223b9d41b48ddd8d0523e2c8a92e7d126 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 30 Apr 2023 11:08:12 -0500 Subject: [PATCH] Fix august lock state when API reports locking and locked with the same timestamp (#92276) --- homeassistant/components/august/activity.py | 10 +++---- homeassistant/components/august/lock.py | 27 ++++++++++++------- homeassistant/components/august/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/august/activity.py b/homeassistant/components/august/activity.py index 687afdab4c7..ad9045a3d0d 100644 --- a/homeassistant/components/august/activity.py +++ b/homeassistant/components/august/activity.py @@ -3,6 +3,7 @@ import asyncio import logging from aiohttp import ClientError +from yalexs.util import get_latest_activity from homeassistant.core import callback from homeassistant.helpers.debounce import Debouncer @@ -169,12 +170,11 @@ class ActivityStream(AugustSubscriberMixin): device_id = activity.device_id activity_type = activity.activity_type device_activities = self._latest_activities.setdefault(device_id, {}) - lastest_activity = device_activities.get(activity_type) - - # Ignore activities that are older than the latest one + # Ignore activities that are older than the latest one unless it is a non + # locking or unlocking activity with the exact same start time. if ( - lastest_activity - and lastest_activity.activity_start_time >= activity.activity_start_time + get_latest_activity(activity, device_activities.get(activity_type)) + != activity ): continue diff --git a/homeassistant/components/august/lock.py b/homeassistant/components/august/lock.py index d77a61a0659..b11550dccd7 100644 --- a/homeassistant/components/august/lock.py +++ b/homeassistant/components/august/lock.py @@ -5,7 +5,7 @@ from typing import Any from aiohttp import ClientResponseError from yalexs.activity import SOURCE_PUBNUB, ActivityType from yalexs.lock import LockStatus -from yalexs.util import update_lock_detail_from_activity +from yalexs.util import get_latest_activity, update_lock_detail_from_activity from homeassistant.components.lock import ATTR_CHANGED_BY, LockEntity from homeassistant.config_entries import ConfigEntry @@ -90,17 +90,26 @@ class AugustLock(AugustEntityMixin, RestoreEntity, LockEntity): @callback def _update_from_data(self): """Get the latest state of the sensor and update activity.""" - lock_activity = self._data.activity_stream.get_latest_device_activity( - self._device_id, - {ActivityType.LOCK_OPERATION, ActivityType.LOCK_OPERATION_WITHOUT_OPERATOR}, + activity_stream = self._data.activity_stream + device_id = self._device_id + if lock_activity := activity_stream.get_latest_device_activity( + device_id, + {ActivityType.LOCK_OPERATION}, + ): + self._attr_changed_by = lock_activity.operated_by + + lock_activity_without_operator = activity_stream.get_latest_device_activity( + device_id, + {ActivityType.LOCK_OPERATION_WITHOUT_OPERATOR}, ) - if lock_activity is not None: - self._attr_changed_by = lock_activity.operated_by - update_lock_detail_from_activity(self._detail, lock_activity) - # If the source is pubnub the lock must be online since its a live update - if lock_activity.source == SOURCE_PUBNUB: + if latest_activity := get_latest_activity( + lock_activity_without_operator, lock_activity + ): + if latest_activity.source == SOURCE_PUBNUB: + # If the source is pubnub the lock must be online since its a live update self._detail.set_online(True) + update_lock_detail_from_activity(self._detail, latest_activity) bridge_activity = self._data.activity_stream.get_latest_device_activity( self._device_id, {ActivityType.BRIDGE_OPERATION} diff --git a/homeassistant/components/august/manifest.json b/homeassistant/components/august/manifest.json index 1233cf07c22..4e5f8354a4c 100644 --- a/homeassistant/components/august/manifest.json +++ b/homeassistant/components/august/manifest.json @@ -28,5 +28,5 @@ "documentation": "https://www.home-assistant.io/integrations/august", "iot_class": "cloud_push", "loggers": ["pubnub", "yalexs"], - "requirements": ["yalexs==1.3.2", "yalexs-ble==2.1.16"] + "requirements": ["yalexs==1.3.3", "yalexs-ble==2.1.16"] } diff --git a/requirements_all.txt b/requirements_all.txt index 20d6c9ba787..ea12f37e032 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2679,7 +2679,7 @@ yalesmartalarmclient==0.3.9 yalexs-ble==2.1.16 # homeassistant.components.august -yalexs==1.3.2 +yalexs==1.3.3 # homeassistant.components.yeelight yeelight==0.7.10 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 5312ba76ba4..94a06d59d89 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1943,7 +1943,7 @@ yalesmartalarmclient==0.3.9 yalexs-ble==2.1.16 # homeassistant.components.august -yalexs==1.3.2 +yalexs==1.3.3 # homeassistant.components.yeelight yeelight==0.7.10