[schema] Get component name if available for deprecation warning (#8785)

This commit is contained in:
Jesse Hills 2025-05-14 13:25:21 +12:00
parent ea31122979
commit c30ffd0098
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A

View File

@ -2077,14 +2077,20 @@ def rename_key(old_key, new_key):
# Remove before 2025.11.0 # Remove before 2025.11.0
def deprecated_schema_constant(entity_type: str): def deprecated_schema_constant(entity_type: str):
def validator(config): def validator(config):
type: str = "unknown"
if (id := config.get(CONF_ID)) is not None and isinstance(id, core.ID):
type = str(id.type).split("::", maxsplit=1)[0]
_LOGGER.warning( _LOGGER.warning(
"Using `%s.%s_SCHEMA` is deprecated and will be removed in ESPHome 2025.11.0. " "Using `%s.%s_SCHEMA` is deprecated and will be removed in ESPHome 2025.11.0. "
"Please use `%s.%s_schema(...)` instead. " "Please use `%s.%s_schema(...)` instead. "
"If you are seeing this, report an issue to the external_component author and ask them to update it.", "If you are seeing this, report an issue to the external_component author and ask them to update it. "
"https://developers.esphome.io/blog/2025/05/14/_schema-deprecations/. "
"Component using this schema: %s",
entity_type, entity_type,
entity_type.upper(), entity_type.upper(),
entity_type, entity_type,
entity_type, entity_type,
type,
) )
return config return config