Do not restore unavailable state for august locks (#44722)
This commit is contained in:
parent
681f76b99d
commit
94825b3e15
4 changed files with 16 additions and 16 deletions
|
@ -11,7 +11,7 @@ from .subscriber import AugustSubscriberMixin
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ACTIVITY_STREAM_FETCH_LIMIT = 10
|
ACTIVITY_STREAM_FETCH_LIMIT = 10
|
||||||
ACTIVITY_CATCH_UP_FETCH_LIMIT = 1000
|
ACTIVITY_CATCH_UP_FETCH_LIMIT = 2500
|
||||||
|
|
||||||
|
|
||||||
class ActivityStream(AugustSubscriberMixin):
|
class ActivityStream(AugustSubscriberMixin):
|
||||||
|
@ -102,11 +102,14 @@ class ActivityStream(AugustSubscriberMixin):
|
||||||
def _process_newer_device_activities(self, activities):
|
def _process_newer_device_activities(self, activities):
|
||||||
updated_device_ids = set()
|
updated_device_ids = set()
|
||||||
for activity in activities:
|
for activity in activities:
|
||||||
self._latest_activities_by_id_type.setdefault(activity.device_id, {})
|
device_id = activity.device_id
|
||||||
|
activity_type = activity.activity_type
|
||||||
|
|
||||||
lastest_activity = self._latest_activities_by_id_type[
|
self._latest_activities_by_id_type.setdefault(device_id, {})
|
||||||
activity.device_id
|
|
||||||
].get(activity.activity_type)
|
lastest_activity = self._latest_activities_by_id_type[device_id].get(
|
||||||
|
activity_type
|
||||||
|
)
|
||||||
|
|
||||||
# Ignore activities that are older than the latest one
|
# Ignore activities that are older than the latest one
|
||||||
if (
|
if (
|
||||||
|
@ -115,10 +118,8 @@ class ActivityStream(AugustSubscriberMixin):
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self._latest_activities_by_id_type[activity.device_id][
|
self._latest_activities_by_id_type[device_id][activity_type] = activity
|
||||||
activity.activity_type
|
|
||||||
] = activity
|
|
||||||
|
|
||||||
updated_device_ids.add(activity.device_id)
|
updated_device_ids.add(device_id)
|
||||||
|
|
||||||
return updated_device_ids
|
return updated_device_ids
|
||||||
|
|
|
@ -4,7 +4,7 @@ import logging
|
||||||
from august.activity import ActivityType
|
from august.activity import ActivityType
|
||||||
|
|
||||||
from homeassistant.components.sensor import DEVICE_CLASS_BATTERY
|
from homeassistant.components.sensor import DEVICE_CLASS_BATTERY
|
||||||
from homeassistant.const import ATTR_ENTITY_PICTURE, PERCENTAGE
|
from homeassistant.const import ATTR_ENTITY_PICTURE, PERCENTAGE, STATE_UNAVAILABLE
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.entity_registry import async_get_registry
|
from homeassistant.helpers.entity_registry import async_get_registry
|
||||||
|
@ -157,8 +157,8 @@ class AugustOperatorSensor(AugustEntityMixin, RestoreEntity, Entity):
|
||||||
self._device_id, [ActivityType.LOCK_OPERATION]
|
self._device_id, [ActivityType.LOCK_OPERATION]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._available = True
|
||||||
if lock_activity is not None:
|
if lock_activity is not None:
|
||||||
self._available = True
|
|
||||||
self._state = lock_activity.operated_by
|
self._state = lock_activity.operated_by
|
||||||
self._operated_remote = lock_activity.operated_remote
|
self._operated_remote = lock_activity.operated_remote
|
||||||
self._operated_keypad = lock_activity.operated_keypad
|
self._operated_keypad = lock_activity.operated_keypad
|
||||||
|
@ -193,7 +193,7 @@ class AugustOperatorSensor(AugustEntityMixin, RestoreEntity, Entity):
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
|
|
||||||
last_state = await self.async_get_last_state()
|
last_state = await self.async_get_last_state()
|
||||||
if not last_state:
|
if not last_state or last_state.state == STATE_UNAVAILABLE:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._state = last_state.state
|
self._state = last_state.state
|
||||||
|
|
|
@ -6,7 +6,6 @@ from homeassistant.const import (
|
||||||
SERVICE_LOCK,
|
SERVICE_LOCK,
|
||||||
SERVICE_UNLOCK,
|
SERVICE_UNLOCK,
|
||||||
STATE_LOCKED,
|
STATE_LOCKED,
|
||||||
STATE_UNAVAILABLE,
|
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
STATE_UNLOCKED,
|
STATE_UNLOCKED,
|
||||||
)
|
)
|
||||||
|
@ -98,7 +97,7 @@ async def test_one_lock_operation(hass):
|
||||||
assert lock_operator_sensor
|
assert lock_operator_sensor
|
||||||
assert (
|
assert (
|
||||||
hass.states.get("sensor.online_with_doorsense_name_operator").state
|
hass.states.get("sensor.online_with_doorsense_name_operator").state
|
||||||
== STATE_UNAVAILABLE
|
== STATE_UNKNOWN
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""The sensor tests for the august platform."""
|
"""The sensor tests for the august platform."""
|
||||||
|
|
||||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, PERCENTAGE, STATE_UNAVAILABLE
|
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, PERCENTAGE, STATE_UNKNOWN
|
||||||
|
|
||||||
from tests.components.august.mocks import (
|
from tests.components.august.mocks import (
|
||||||
_create_august_with_devices,
|
_create_august_with_devices,
|
||||||
|
@ -120,7 +120,7 @@ async def test_create_lock_with_low_battery_linked_keypad(hass):
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
hass.states.get("sensor.a6697750d607098bae8d6baa11ef8063_name_operator").state
|
hass.states.get("sensor.a6697750d607098bae8d6baa11ef8063_name_operator").state
|
||||||
== STATE_UNAVAILABLE
|
== STATE_UNKNOWN
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue