mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Tweak MQTT availability (#37719)
This commit is contained in:
parent
67b18aef5b
commit
383db60dff
@ -1045,11 +1045,14 @@ class MqttAvailability(Entity):
|
|||||||
"""Subscribe MQTT events."""
|
"""Subscribe MQTT events."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
await self._availability_subscribe_topics()
|
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(
|
self.async_on_remove(
|
||||||
async_dispatcher_connect(self.hass, MQTT_CONNECTED, self.async_mqtt_connect)
|
async_dispatcher_connect(self.hass, MQTT_CONNECTED, self.async_mqtt_connect)
|
||||||
)
|
)
|
||||||
|
self.async_on_remove(
|
||||||
|
async_dispatcher_connect(
|
||||||
|
self.hass, MQTT_DISCONNECTED, self.async_mqtt_connect
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
async def availability_discovery_update(self, config: dict):
|
async def availability_discovery_update(self, config: dict):
|
||||||
"""Handle updated discovery message."""
|
"""Handle updated discovery message."""
|
||||||
@ -1116,7 +1119,7 @@ class MqttAvailability(Entity):
|
|||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
"""Return if the device is available."""
|
"""Return if the device is available."""
|
||||||
if not self.hass.data[DATA_MQTT].connected:
|
if not self.hass.data[DATA_MQTT].connected and not self.hass.is_stopping:
|
||||||
return False
|
return False
|
||||||
return not self._avail_topics or self._available
|
return not self._avail_topics or self._available
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user