Fix state saving when sharing topics for MQTT entities (#79421)

* Do not write old state sharing availability topic

* Add a test

* Support for all availability topics

* delay async_write_ha_state till last callback

* Process write req after processing callback jobs

* Do not count subscription callbacks

* Simplify

* Stale docsting

* No topic needed for delays state write

* No need to clear when reloading

* Move test to test_mixins.py

* Only set up sensor platform for test
This commit is contained in:
Jan Bouwhuis 2022-10-11 10:49:54 +02:00 committed by GitHub
parent 6f7cb158d8
commit 8aa30cce26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 164 additions and 56 deletions

View file

@ -435,7 +435,9 @@ class MqttAttributes(Entity):
and k not in self._attributes_extra_blocked
}
self._attributes = filtered_dict
self.async_write_ha_state()
get_mqtt_data(self.hass).state_write_requests.write_state_request(
self
)
else:
_LOGGER.warning("JSON result was not a dictionary")
self._attributes = None
@ -547,7 +549,7 @@ class MqttAvailability(Entity):
self._available[topic] = False
self._available_latest = False
self.async_write_ha_state()
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)
self._available = {
topic: (self._available[topic] if topic in self._available else False)