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

@ -47,6 +47,7 @@ from .mixins import (
warn_for_legacy_schema,
)
from .models import MqttValueTemplate
from .util import get_mqtt_data
_LOGGER = logging.getLogger(__name__)
@ -260,7 +261,7 @@ class MqttBinarySensor(MqttEntity, BinarySensorEntity, RestoreEntity):
self.hass, off_delay, off_delay_listener
)
self.async_write_ha_state()
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)
self._sub_state = subscription.async_prepare_subscribe_topics(
self.hass,