From 06fd75be7e4c45aaff5b52fa18efccae3813a9bc Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 13 Jan 2022 07:26:47 -1000 Subject: [PATCH] Ensure august status is current when integration loads (#64027) --- homeassistant/components/august/__init__.py | 14 ++++++++++++++ homeassistant/components/august/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/august/mocks.py | 12 ++++++++++-- 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/august/__init__.py b/homeassistant/components/august/__init__.py index d521cf559a0..dc3ffc90843 100644 --- a/homeassistant/components/august/__init__.py +++ b/homeassistant/components/august/__init__.py @@ -140,6 +140,11 @@ class AugustData(AugustSubscriberMixin): pubnub.subscribe(self.async_pubnub_message) self._pubnub_unsub = async_create_pubnub(user_data["UserID"], pubnub) + if self._locks_by_id: + await asyncio.gather( + *[self.async_status_async(lock_id) for lock_id in self._locks_by_id] + ) + @callback def async_pubnub_message(self, device_id, date_time, message): """Process a pubnub message.""" @@ -247,6 +252,15 @@ class AugustData(AugustSubscriberMixin): device_id, ) + async def async_status_async(self, device_id): + """Request status of the the device but do not wait for a response since it will come via pubnub.""" + return await self._async_call_api_op_requires_bridge( + device_id, + self._api.async_status_async, + self._august_gateway.access_token, + device_id, + ) + async def async_lock_async(self, device_id): """Lock the device but do not wait for a response since it will come via pubnub.""" return await self._async_call_api_op_requires_bridge( diff --git a/homeassistant/components/august/manifest.json b/homeassistant/components/august/manifest.json index c08f25177cc..15b31edcce4 100644 --- a/homeassistant/components/august/manifest.json +++ b/homeassistant/components/august/manifest.json @@ -2,7 +2,7 @@ "domain": "august", "name": "August", "documentation": "https://www.home-assistant.io/integrations/august", - "requirements": ["yalexs==1.1.17"], + "requirements": ["yalexs==1.1.18"], "codeowners": ["@bdraco"], "dhcp": [ { diff --git a/requirements_all.txt b/requirements_all.txt index b1b2532e71e..1247ba4b56f 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2503,7 +2503,7 @@ xs1-api-client==3.0.0 yalesmartalarmclient==0.3.7 # homeassistant.components.august -yalexs==1.1.17 +yalexs==1.1.18 # homeassistant.components.yeelight yeelight==0.7.8 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 720cad7978f..efea8a032f4 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1525,7 +1525,7 @@ xmltodict==0.12.0 yalesmartalarmclient==0.3.7 # homeassistant.components.august -yalexs==1.1.17 +yalexs==1.1.18 # homeassistant.components.yeelight yeelight==0.7.8 diff --git a/tests/components/august/mocks.py b/tests/components/august/mocks.py index 7075eb84d72..2d572b886f3 100644 --- a/tests/components/august/mocks.py +++ b/tests/components/august/mocks.py @@ -162,10 +162,17 @@ async def _create_august_with_devices( # noqa: C901 "unlock_return_activities" ] = unlock_return_activities_side_effect - return await _mock_setup_august_with_api_side_effects( + api_instance, entry = await _mock_setup_august_with_api_side_effects( hass, api_call_side_effects, pubnub ) + if device_data["locks"]: + # Ensure we sync status when the integration is loaded if there + # are any locks + assert api_instance.async_status_async.mock_calls + + return entry + async def _mock_setup_august_with_api_side_effects(hass, api_call_side_effects, pubnub): api_instance = MagicMock(name="Api") @@ -207,9 +214,10 @@ async def _mock_setup_august_with_api_side_effects(hass, api_call_side_effects, api_instance.async_unlock_async = AsyncMock() api_instance.async_lock_async = AsyncMock() + api_instance.async_status_async = AsyncMock() api_instance.async_get_user = AsyncMock(return_value={"UserID": "abc"}) - return await _mock_setup_august(hass, api_instance, pubnub) + return api_instance, await _mock_setup_august(hass, api_instance, pubnub) def _mock_august_authentication(token_text, token_timestamp, state):