1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-10 05:43:48 +01:00

Deprecate virtual methods to set entity properties (#3021)

This commit is contained in:
Oxan van Leeuwen
2022-01-10 13:32:39 +01:00
committed by GitHub
parent 41bcc8c0f4
commit 073828235f
12 changed files with 76 additions and 32 deletions

View File

@@ -3,7 +3,7 @@ import esphome.final_validate as fv
from esphome.const import CONF_ID
def inherit_property_from(property_to_inherit, parent_id_property):
def inherit_property_from(property_to_inherit, parent_id_property, transform=None):
"""Validator that inherits a configuration property from another entity, for use with FINAL_VALIDATE_SCHEMA.
If a property is already set, it will not be inherited.
Keyword arguments:
@@ -47,7 +47,10 @@ def inherit_property_from(property_to_inherit, parent_id_property):
this_config = _walk_config(
fconf.get_config_for_path(path), property_path
)
this_config[property] = parent_config[property]
value = parent_config[property]
if transform:
value = transform(value, config)
this_config[property] = value
return config