Ensure august status is current when integration loads (#64027)

pull/64068/head
J. Nick Koston 2022-01-13 07:26:47 -10:00 committed by GitHub
parent 88f4aeaa22
commit 06fd75be7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 5 deletions

View File

@ -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(

View File

@ -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": [
{

View File

@ -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

View File

@ -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

View File

@ -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):