Ensure all default MQTT subentry option values are saved (#144347)

* Ensure all default MQTT subentry option values are saved

* Apply correct filter
This commit is contained in:
Jan Bouwhuis 2025-05-06 19:30:48 +02:00 committed by GitHub
parent a673bd7a91
commit da7e9f3ab6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 3 deletions

View File

@ -1490,8 +1490,11 @@ def subentry_schema_default_data_from_fields(
return {
key: field.default
for key, field in data_schema_fields.items()
if field.is_schema_default
or (field.default is not vol.UNDEFINED and key not in component_data)
if _check_conditions(field, component_data)
and (
field.is_schema_default
or (field.default is not vol.UNDEFINED and key not in component_data)
)
}
@ -2317,7 +2320,10 @@ class MQTTSubentryFlowHandler(ConfigSubentryFlow):
for component_data in self._subentry_data["components"].values():
platform = component_data[CONF_PLATFORM]
subentry_default_data = subentry_schema_default_data_from_fields(
PLATFORM_ENTITY_FIELDS[platform] | COMMON_ENTITY_FIELDS, component_data
COMMON_ENTITY_FIELDS
| PLATFORM_ENTITY_FIELDS[platform]
| PLATFORM_MQTT_FIELDS[platform],
component_data,
)
component_data.update(subentry_default_data)

View File

@ -179,6 +179,10 @@ MOCK_SUBENTRY_LIGHT_BASIC_KELVIN_COMPONENT = {
"state_topic": "test-topic",
"color_temp_kelvin": True,
"state_value_template": "{{ value_json.value }}",
"brightness_scale": 255,
"max_kelvin": 6535,
"min_kelvin": 2000,
"white_scale": 255,
"entity_picture": "https://example.com/8131babc5e8d4f44b82e0761d39091a2",
},
}