mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Fix august lock state when API reports locking and locked with the same timestamp (#92276)
This commit is contained in:
parent
4fcf05c202
commit
ed286fc223
@ -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
|
||||
|
||||
|
@ -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}
|
||||
|
@ -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"]
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user