From 944d70401160ff77ccf2e6d4620f35cb82c97d57 Mon Sep 17 00:00:00 2001 From: Matrix Date: Sun, 2 Oct 2022 06:56:36 +0800 Subject: [PATCH] Fix mqtt reconnect fail when token expired (#79428) * fix mqtt reconnect fail when token expired * suggest change --- homeassistant/components/yolink/__init__.py | 14 +++++++++++++- homeassistant/components/yolink/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/yolink/__init__.py b/homeassistant/components/yolink/__init__.py index 3257d64d265..06e6fd6472a 100644 --- a/homeassistant/components/yolink/__init__.py +++ b/homeassistant/components/yolink/__init__.py @@ -12,7 +12,7 @@ from yolink.model import BRDP from yolink.mqtt_client import MqttClient from homeassistant.config_entries import ConfigEntry -from homeassistant.const import Platform +from homeassistant.const import EVENT_HOMEASSISTANT_STOP, Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.helpers import aiohttp_client, config_entry_oauth2_flow @@ -110,11 +110,23 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: device_coordinators[device.device_id] = device_coordinator hass.data[DOMAIN][entry.entry_id][ATTR_COORDINATORS] = device_coordinators await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) + + async def shutdown_subscription(event) -> None: + """Shutdown mqtt message subscription.""" + await yolink_mqtt_client.shutdown_home_subscription() + + entry.async_on_unload( + hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, shutdown_subscription) + ) + return True async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): + await hass.data[DOMAIN][entry.entry_id][ + ATTR_MQTT_CLIENT + ].shutdown_home_subscription() hass.data[DOMAIN].pop(entry.entry_id) return unload_ok diff --git a/homeassistant/components/yolink/manifest.json b/homeassistant/components/yolink/manifest.json index 0db736938f7..665b17d9f22 100644 --- a/homeassistant/components/yolink/manifest.json +++ b/homeassistant/components/yolink/manifest.json @@ -3,7 +3,7 @@ "name": "YoLink", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/yolink", - "requirements": ["yolink-api==0.0.9"], + "requirements": ["yolink-api==0.1.0"], "dependencies": ["auth", "application_credentials"], "codeowners": ["@matrixd2"], "iot_class": "cloud_push" diff --git a/requirements_all.txt b/requirements_all.txt index 3d83ae4175e..1eb0cd84056 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2580,7 +2580,7 @@ yeelight==0.7.10 yeelightsunflower==0.0.10 # homeassistant.components.yolink -yolink-api==0.0.9 +yolink-api==0.1.0 # homeassistant.components.youless youless-api==0.16 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 50a9c82c46c..7f1a98c564d 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1787,7 +1787,7 @@ yalexs==1.2.4 yeelight==0.7.10 # homeassistant.components.yolink -yolink-api==0.0.9 +yolink-api==0.1.0 # homeassistant.components.youless youless-api==0.16