From 714328d2ca77ecfbbcbd9458f006680e393c97b1 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 18 Feb 2023 03:40:51 -0600 Subject: [PATCH] Handle key change in Yale Access Bluetooth after first connect (#88282) --- homeassistant/components/august/manifest.json | 2 +- .../components/yalexs_ble/__init__.py | 19 ++++++++++++++++++- homeassistant/components/yalexs_ble/entity.py | 2 +- .../components/yalexs_ble/manifest.json | 2 +- requirements_all.txt | 4 ++-- requirements_test_all.txt | 4 ++-- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/august/manifest.json b/homeassistant/components/august/manifest.json index b01e1bf3664..e8b00ac921a 100644 --- a/homeassistant/components/august/manifest.json +++ b/homeassistant/components/august/manifest.json @@ -28,5 +28,5 @@ "documentation": "https://www.home-assistant.io/integrations/august", "iot_class": "cloud_push", "loggers": ["pubnub", "yalexs"], - "requirements": ["yalexs==1.2.7", "yalexs_ble==2.0.0"] + "requirements": ["yalexs==1.2.7", "yalexs_ble==2.0.1"] } diff --git a/homeassistant/components/yalexs_ble/__init__.py b/homeassistant/components/yalexs_ble/__init__.py index c2bde758668..f3d086afed0 100644 --- a/homeassistant/components/yalexs_ble/__init__.py +++ b/homeassistant/components/yalexs_ble/__init__.py @@ -1,7 +1,15 @@ """The Yale Access Bluetooth integration.""" from __future__ import annotations -from yalexs_ble import AuthError, PushLock, YaleXSBLEError, local_name_is_unique +from yalexs_ble import ( + AuthError, + ConnectionInfo, + LockInfo, + LockState, + PushLock, + YaleXSBLEError, + local_name_is_unique, +) from homeassistant.components import bluetooth from homeassistant.config_entries import ConfigEntry @@ -76,6 +84,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: ) ) + @callback + def _async_state_changed( + new_state: LockState, lock_info: LockInfo, connection_info: ConnectionInfo + ) -> None: + """Handle state changed.""" + if new_state.auth and not new_state.auth.successful: + entry.async_start_reauth(hass) + + entry.async_on_unload(push_lock.register_callback(_async_state_changed)) await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) entry.async_on_unload(entry.add_update_listener(_async_update_listener)) return True diff --git a/homeassistant/components/yalexs_ble/entity.py b/homeassistant/components/yalexs_ble/entity.py index d2395f3e39e..18f1e28ece6 100644 --- a/homeassistant/components/yalexs_ble/entity.py +++ b/homeassistant/components/yalexs_ble/entity.py @@ -45,7 +45,7 @@ class YALEXSBLEEntity(Entity): self, new_state: LockState, lock_info: LockInfo, connection_info: ConnectionInfo ) -> None: """Update the state.""" - self._attr_available = True + self._attr_available = bool(not new_state.auth or new_state.auth.successful) @callback def _async_state_changed( diff --git a/homeassistant/components/yalexs_ble/manifest.json b/homeassistant/components/yalexs_ble/manifest.json index 73d79499b65..2953e33f199 100644 --- a/homeassistant/components/yalexs_ble/manifest.json +++ b/homeassistant/components/yalexs_ble/manifest.json @@ -12,5 +12,5 @@ "dependencies": ["bluetooth_adapters"], "documentation": "https://www.home-assistant.io/integrations/yalexs_ble", "iot_class": "local_push", - "requirements": ["yalexs-ble==2.0.0"] + "requirements": ["yalexs-ble==2.0.1"] } diff --git a/requirements_all.txt b/requirements_all.txt index 042621d9529..33a89f05923 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2667,13 +2667,13 @@ xs1-api-client==3.0.0 yalesmartalarmclient==0.3.9 # homeassistant.components.yalexs_ble -yalexs-ble==2.0.0 +yalexs-ble==2.0.1 # homeassistant.components.august yalexs==1.2.7 # homeassistant.components.august -yalexs_ble==2.0.0 +yalexs_ble==2.0.1 # homeassistant.components.yeelight yeelight==0.7.10 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index bb45e3e8893..af0165e03e2 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1889,13 +1889,13 @@ xmltodict==0.13.0 yalesmartalarmclient==0.3.9 # homeassistant.components.yalexs_ble -yalexs-ble==2.0.0 +yalexs-ble==2.0.1 # homeassistant.components.august yalexs==1.2.7 # homeassistant.components.august -yalexs_ble==2.0.0 +yalexs_ble==2.0.1 # homeassistant.components.yeelight yeelight==0.7.10