Improve lists for MQTT integration (#113184)

* Improve lists for MQTT integration

* Extra diagnostics tests

* Revert changes where the original version was probably faster

* Revert change to gather and await in series
This commit is contained in:
Jan Bouwhuis 2024-03-13 11:04:59 +01:00 committed by GitHub
parent b1346f3ccd
commit 488dae43d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 144 additions and 116 deletions

View file

@ -661,15 +661,12 @@ class MqttClimate(MqttTemperatureControlEntity, ClimateEntity):
self._optimistic or CONF_PRESET_MODE_STATE_TOPIC not in config
)
value_templates: dict[str, Template | None] = {}
for key in VALUE_TEMPLATE_KEYS:
value_templates[key] = None
if CONF_VALUE_TEMPLATE in config:
value_templates = {
key: config.get(CONF_VALUE_TEMPLATE) for key in VALUE_TEMPLATE_KEYS
}
for key in VALUE_TEMPLATE_KEYS & config.keys():
value_templates[key] = config[key]
value_templates: dict[str, Template | None] = {
key: config.get(CONF_VALUE_TEMPLATE) for key in VALUE_TEMPLATE_KEYS
}
value_templates.update(
{key: config[key] for key in VALUE_TEMPLATE_KEYS & config.keys()}
)
self._value_templates = {
key: MqttValueTemplate(
template,
@ -678,11 +675,10 @@ class MqttClimate(MqttTemperatureControlEntity, ClimateEntity):
for key, template in value_templates.items()
}
self._command_templates = {}
for key in COMMAND_TEMPLATE_KEYS:
self._command_templates[key] = MqttCommandTemplate(
config.get(key), entity=self
).async_render
self._command_templates = {
key: MqttCommandTemplate(config.get(key), entity=self).async_render
for key in COMMAND_TEMPLATE_KEYS
}
support = ClimateEntityFeature.TURN_ON | ClimateEntityFeature.TURN_OFF
if (self._topic[CONF_TEMP_STATE_TOPIC] is not None) or (