diff --git a/esphome/automation.py b/esphome/automation.py index 32f423d2a34..42731118c94 100644 --- a/esphome/automation.py +++ b/esphome/automation.py @@ -338,8 +338,9 @@ class ApplyField: Double a literal brace in a template. ``conf_key`` may be a path into nested sections. ``type_`` may be a C++ type string using ``{parent}`` when the type is only known per instance. ``const_fn(config, value)`` renders a constant's argument text when ``cg.safe_exp`` - is not the right spelling (unit conversion belongs in the validator); a lambda or an id - bypasses it, so the target must also take a plain ``type_``. An absent key emits nothing. + is not the right spelling, or the value depends on another entity's config, such as the unit + a climate reports in; a lambda or an id bypasses it, so the target must also take a plain + ``type_``. An absent key emits nothing. """ conf_key: str | tuple[str, ...] diff --git a/esphome/components/climate/__init__.py b/esphome/components/climate/__init__.py index 10c901d63dc..c195c86bd12 100644 --- a/esphome/components/climate/__init__.py +++ b/esphome/components/climate/__init__.py @@ -167,10 +167,8 @@ def temperature_unit_of(config: ConfigType) -> str: def temperature_unit_of_id(climate_id: ID) -> str: """The unit of the climate with this id, for actions that take static temperatures.""" - for conf in CORE.config.get(DOMAIN, []): - if conf[CONF_ID] == climate_id: - return temperature_unit_of(conf) - raise KeyError(f"No climate with id {climate_id}") + path = CORE.config.get_path_for_id(climate_id)[:-1] + return temperature_unit_of(CORE.config.get_config_for_path(path)) def temperature_in_entity_unit( diff --git a/esphome/components/water_heater/__init__.py b/esphome/components/water_heater/__init__.py index a54bb35b6c4..028648d7bcf 100644 --- a/esphome/components/water_heater/__init__.py +++ b/esphome/components/water_heater/__init__.py @@ -54,10 +54,8 @@ def temperature_unit_of(config: ConfigType) -> str: def temperature_unit_of_id(water_heater_id: ID) -> str: """The unit of the water heater with this id, for actions that take static temperatures.""" - for conf in CORE.config.get(DOMAIN, []): - if conf[CONF_ID] == water_heater_id: - return temperature_unit_of(conf) - raise KeyError(f"No water heater with id {water_heater_id}") + path = CORE.config.get_path_for_id(water_heater_id)[:-1] + return temperature_unit_of(CORE.config.get_config_for_path(path)) def _visual_temperatures_in_entity_unit(config: ConfigType) -> ConfigType: