From 12510b0c979b754432f050ba2dd6607960e7c2d3 Mon Sep 17 00:00:00 2001 From: definitio <37266727+definitio@users.noreply.github.com> Date: Tue, 30 Jun 2020 02:36:52 +0400 Subject: [PATCH] Fixes after PR #36479 (#37230) --- homeassistant/components/mqtt/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/mqtt/__init__.py b/homeassistant/components/mqtt/__init__.py index 69d84705088..bb2ec7a8bcb 100644 --- a/homeassistant/components/mqtt/__init__.py +++ b/homeassistant/components/mqtt/__init__.py @@ -994,6 +994,9 @@ class MqttAvailability(Entity): await self._availability_subscribe_topics() async_dispatcher_connect(self.hass, MQTT_CONNECTED, self.async_mqtt_connect) async_dispatcher_connect(self.hass, MQTT_DISCONNECTED, self.async_mqtt_connect) + self.async_on_remove( + async_dispatcher_connect(self.hass, MQTT_CONNECTED, self.async_mqtt_connect) + ) async def availability_discovery_update(self, config: dict): """Handle updated discovery message.""" @@ -1029,7 +1032,8 @@ class MqttAvailability(Entity): @callback def async_mqtt_connect(self): """Update state on connection/disconnection to MQTT broker.""" - self.async_write_ha_state() + if self.hass.is_running: + self.async_write_ha_state() async def async_will_remove_from_hass(self): """Unsubscribe when removed."""