mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Fix default entity name not the device default entity when no name set on MQTT subentry entity (#144263)
This commit is contained in:
parent
1879b8c27f
commit
0bf807b96e
@ -465,7 +465,7 @@ class PlatformField:
|
|||||||
required: bool
|
required: bool
|
||||||
validator: Callable[..., Any]
|
validator: Callable[..., Any]
|
||||||
error: str | None = None
|
error: str | None = None
|
||||||
default: str | int | bool | vol.Undefined = vol.UNDEFINED
|
default: str | int | bool | None | vol.Undefined = vol.UNDEFINED
|
||||||
is_schema_default: bool = False
|
is_schema_default: bool = False
|
||||||
exclude_from_reconfig: bool = False
|
exclude_from_reconfig: bool = False
|
||||||
conditions: tuple[dict[str, Any], ...] | None = None
|
conditions: tuple[dict[str, Any], ...] | None = None
|
||||||
@ -515,6 +515,7 @@ COMMON_ENTITY_FIELDS = {
|
|||||||
required=False,
|
required=False,
|
||||||
validator=str,
|
validator=str,
|
||||||
exclude_from_reconfig=True,
|
exclude_from_reconfig=True,
|
||||||
|
default=None,
|
||||||
),
|
),
|
||||||
CONF_ENTITY_PICTURE: PlatformField(
|
CONF_ENTITY_PICTURE: PlatformField(
|
||||||
selector=TEXT_SELECTOR, required=False, validator=cv.url, error="invalid_url"
|
selector=TEXT_SELECTOR, required=False, validator=cv.url, error="invalid_url"
|
||||||
@ -1324,7 +1325,10 @@ def data_schema_from_fields(
|
|||||||
vol.Required(field_name, default=field_details.default)
|
vol.Required(field_name, default=field_details.default)
|
||||||
if field_details.required
|
if field_details.required
|
||||||
else vol.Optional(
|
else vol.Optional(
|
||||||
field_name, default=field_details.default
|
field_name,
|
||||||
|
default=field_details.default
|
||||||
|
if field_details.default is not None
|
||||||
|
else vol.UNDEFINED,
|
||||||
): field_details.selector(component_data_with_user_input) # type: ignore[operator]
|
): field_details.selector(component_data_with_user_input) # type: ignore[operator]
|
||||||
if field_details.custom_filtering
|
if field_details.custom_filtering
|
||||||
else field_details.selector
|
else field_details.selector
|
||||||
@ -1375,12 +1379,14 @@ def data_schema_from_fields(
|
|||||||
@callback
|
@callback
|
||||||
def subentry_schema_default_data_from_fields(
|
def subentry_schema_default_data_from_fields(
|
||||||
data_schema_fields: dict[str, PlatformField],
|
data_schema_fields: dict[str, PlatformField],
|
||||||
|
component_data: dict[str, Any],
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Generate custom data schema from platform fields or device data."""
|
"""Generate custom data schema from platform fields or device data."""
|
||||||
return {
|
return {
|
||||||
key: field.default
|
key: field.default
|
||||||
for key, field in data_schema_fields.items()
|
for key, field in data_schema_fields.items()
|
||||||
if field.is_schema_default
|
if field.is_schema_default
|
||||||
|
or (field.default is not vol.UNDEFINED and key not in component_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2206,7 +2212,7 @@ class MQTTSubentryFlowHandler(ConfigSubentryFlow):
|
|||||||
for component_data in self._subentry_data["components"].values():
|
for component_data in self._subentry_data["components"].values():
|
||||||
platform = component_data[CONF_PLATFORM]
|
platform = component_data[CONF_PLATFORM]
|
||||||
subentry_default_data = subentry_schema_default_data_from_fields(
|
subentry_default_data = subentry_schema_default_data_from_fields(
|
||||||
PLATFORM_ENTITY_FIELDS[platform]
|
PLATFORM_ENTITY_FIELDS[platform] | COMMON_ENTITY_FIELDS, component_data
|
||||||
)
|
)
|
||||||
component_data.update(subentry_default_data)
|
component_data.update(subentry_default_data)
|
||||||
|
|
||||||
|
@ -87,6 +87,7 @@ MOCK_SUBENTRY_NOTIFY_COMPONENT2 = {
|
|||||||
MOCK_SUBENTRY_NOTIFY_COMPONENT_NO_NAME = {
|
MOCK_SUBENTRY_NOTIFY_COMPONENT_NO_NAME = {
|
||||||
"5269352dd9534c908d22812ea5d714cd": {
|
"5269352dd9534c908d22812ea5d714cd": {
|
||||||
"platform": "notify",
|
"platform": "notify",
|
||||||
|
"name": None,
|
||||||
"command_topic": "test-topic",
|
"command_topic": "test-topic",
|
||||||
"command_template": "{{ value }}",
|
"command_template": "{{ value }}",
|
||||||
"entity_picture": "https://example.com/5269352dd9534c908d22812ea5d714cd",
|
"entity_picture": "https://example.com/5269352dd9534c908d22812ea5d714cd",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user