diff --git a/homeassistant/components/august/activity.py b/homeassistant/components/august/activity.py index c7a7d68d959..d972fbf5281 100644 --- a/homeassistant/components/august/activity.py +++ b/homeassistant/components/august/activity.py @@ -11,7 +11,7 @@ from .subscriber import AugustSubscriberMixin _LOGGER = logging.getLogger(__name__) ACTIVITY_STREAM_FETCH_LIMIT = 10 -ACTIVITY_CATCH_UP_FETCH_LIMIT = 1000 +ACTIVITY_CATCH_UP_FETCH_LIMIT = 2500 class ActivityStream(AugustSubscriberMixin): @@ -102,11 +102,14 @@ class ActivityStream(AugustSubscriberMixin): def _process_newer_device_activities(self, activities): updated_device_ids = set() 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[ - activity.device_id - ].get(activity.activity_type) + self._latest_activities_by_id_type.setdefault(device_id, {}) + + lastest_activity = self._latest_activities_by_id_type[device_id].get( + activity_type + ) # Ignore activities that are older than the latest one if ( @@ -115,10 +118,8 @@ class ActivityStream(AugustSubscriberMixin): ): continue - self._latest_activities_by_id_type[activity.device_id][ - activity.activity_type - ] = activity + self._latest_activities_by_id_type[device_id][activity_type] = activity - updated_device_ids.add(activity.device_id) + updated_device_ids.add(device_id) return updated_device_ids diff --git a/homeassistant/components/august/sensor.py b/homeassistant/components/august/sensor.py index c3f5f05ceef..6004a07f605 100644 --- a/homeassistant/components/august/sensor.py +++ b/homeassistant/components/august/sensor.py @@ -4,7 +4,7 @@ import logging from august.activity import ActivityType 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.helpers.entity import Entity 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._available = True if lock_activity is not None: - self._available = True self._state = lock_activity.operated_by self._operated_remote = lock_activity.operated_remote self._operated_keypad = lock_activity.operated_keypad @@ -193,7 +193,7 @@ class AugustOperatorSensor(AugustEntityMixin, RestoreEntity, Entity): await super().async_added_to_hass() last_state = await self.async_get_last_state() - if not last_state: + if not last_state or last_state.state == STATE_UNAVAILABLE: return self._state = last_state.state diff --git a/tests/components/august/test_lock.py b/tests/components/august/test_lock.py index f36a5e3f180..8baefa68271 100644 --- a/tests/components/august/test_lock.py +++ b/tests/components/august/test_lock.py @@ -6,7 +6,6 @@ from homeassistant.const import ( SERVICE_LOCK, SERVICE_UNLOCK, STATE_LOCKED, - STATE_UNAVAILABLE, STATE_UNKNOWN, STATE_UNLOCKED, ) @@ -98,7 +97,7 @@ async def test_one_lock_operation(hass): assert lock_operator_sensor assert ( hass.states.get("sensor.online_with_doorsense_name_operator").state - == STATE_UNAVAILABLE + == STATE_UNKNOWN ) diff --git a/tests/components/august/test_sensor.py b/tests/components/august/test_sensor.py index 51e00b9d09f..fb7ddfde979 100644 --- a/tests/components/august/test_sensor.py +++ b/tests/components/august/test_sensor.py @@ -1,6 +1,6 @@ """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 ( _create_august_with_devices, @@ -120,7 +120,7 @@ async def test_create_lock_with_low_battery_linked_keypad(hass): ) assert ( hass.states.get("sensor.a6697750d607098bae8d6baa11ef8063_name_operator").state - == STATE_UNAVAILABLE + == STATE_UNKNOWN )