CONF_ID, CONF_SOURCE_ID, ) from esphome.core.entity_helpers import inherit_property_from from .. import copy_ns CopySelect = copy_ns.class_("CopySelect", select.Select, cg.Component) CONFIG_SCHEMA = select.SELECT_SCHEMA.extend( { cv.GenerateID(): cv.declare_id(CopySelect), cv.Required(CONF_SOURCE_ID): cv.use_id(select.Select), } ).extend(cv.COMPONENT_SCHEMA) FINAL_VALIDATE_SCHEMA = cv.All( inherit_property_from(CONF_ICON, CONF_SOURCE_ID), inherit_property_from(CONF_ENTITY_CATEGORY, CONF_SOURCE_ID), ) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await select.register_select(var, config, options=[]) await cg.register_component(var, config) source = await cg.get_variable(config[CONF_SOURCE_ID]) cg.add(var.set_source(source))
cv.Optional(CONF_RESTORE, default=False): cv.boolean, cv.Optional(CONF_MIN_SAVE_INTERVAL, default="0s"): cv.positive_time_period_milliseconds, }).extend(cv.COMPONENT_SCHEMA) FINAL_VALIDATE_SCHEMA = cv.All( cv.Schema( { cv.Required(CONF_ID): cv.use_id(IntegrationSensor), cv.Optional(CONF_ICON): cv.icon, cv.Required(CONF_SENSOR): cv.use_id(sensor.Sensor), }, extra=cv.ALLOW_EXTRA, ), inherit_property_from(CONF_ICON, CONF_SENSOR), ) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await sensor.register_sensor(var, config) sens = await cg.get_variable(config[CONF_SENSOR]) cg.add(var.set_sensor(sens)) cg.add(var.set_time(config[CONF_TIME_UNIT])) cg.add(var.set_method(config[CONF_INTEGRATION_METHOD])) cg.add(var.set_restore(config[CONF_RESTORE])) cg.add(var.set_min_save_interval(config[CONF_MIN_SAVE_INTERVAL]))
}).extend(cv.COMPONENT_SCHEMA)) FINAL_VALIDATE_SCHEMA = cv.All( cv.Schema( { cv.Required(CONF_ID): cv.use_id(TotalDailyEnergy), cv.Optional(CONF_ICON): cv.icon, cv.Optional(CONF_UNIT_OF_MEASUREMENT): sensor.validate_unit_of_measurement, cv.Optional(CONF_ACCURACY_DECIMALS): sensor.validate_accuracy_decimals, cv.Required(CONF_POWER_ID): cv.use_id(sensor.Sensor), }, extra=cv.ALLOW_EXTRA, ), inherit_property_from(CONF_ICON, CONF_POWER_ID), inherit_property_from(CONF_UNIT_OF_MEASUREMENT, CONF_POWER_ID, transform=inherit_unit_of_measurement), inherit_property_from(CONF_ACCURACY_DECIMALS, CONF_POWER_ID, transform=inherit_accuracy_decimals), ) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await sensor.register_sensor(var, config)
}), ), cv.Optional(CONF_STD_DEV): sensor.SENSOR_SCHEMA, }) # Inherit some sensor values from the first source, for both the state and the error value properties_to_inherit = [ CONF_ACCURACY_DECIMALS, CONF_DEVICE_CLASS, CONF_ENTITY_CATEGORY, CONF_ICON, CONF_UNIT_OF_MEASUREMENT, # CONF_STATE_CLASS could also be inherited, but might lead to unexpected behaviour with "total_increasing" ] inherit_schema_for_state = [ inherit_property_from(property, [CONF_SOURCES, 0, CONF_SOURCE]) for property in properties_to_inherit ] inherit_schema_for_std_dev = [ inherit_property_from([CONF_STD_DEV, property], [CONF_SOURCES, 0, CONF_SOURCE]) for property in properties_to_inherit ] FINAL_VALIDATE_SCHEMA = cv.All( CONFIG_SCHEMA.extend( {cv.Required(CONF_ID): cv.use_id(KalmanCombinatorComponent)}, extra=cv.ALLOW_EXTRA, ), *inherit_schema_for_state, *inherit_schema_for_std_dev,
), } ) .extend(cv.COMPONENT_SCHEMA) ) FINAL_VALIDATE_SCHEMA = cv.All( cv.Schema( { cv.Required(CONF_ID): cv.use_id(TotalDailyEnergy), cv.Optional(CONF_ICON): cv.icon, cv.Required(CONF_POWER_ID): cv.use_id(sensor.Sensor), }, extra=cv.ALLOW_EXTRA, ), inherit_property_from(CONF_ICON, CONF_POWER_ID), ) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await sensor.register_sensor(var, config) sens = await cg.get_variable(config[CONF_POWER_ID]) cg.add(var.set_parent(sens)) time_ = await cg.get_variable(config[CONF_TIME_ID]) cg.add(var.set_time(time_)) cg.add(var.set_min_save_interval(config[CONF_MIN_SAVE_INTERVAL])) cg.add(var.set_method(config[CONF_METHOD]))
CONF_SOURCE_ID, CONF_UNIT_OF_MEASUREMENT, ) from esphome.core.entity_helpers import inherit_property_from from .. import copy_ns CopyNumber = copy_ns.class_("CopyNumber", number.Number, cg.Component) CONFIG_SCHEMA = number.NUMBER_SCHEMA.extend({ cv.GenerateID(): cv.declare_id(CopyNumber), cv.Required(CONF_SOURCE_ID): cv.use_id(number.Number), }).extend(cv.COMPONENT_SCHEMA) FINAL_VALIDATE_SCHEMA = cv.All( inherit_property_from(CONF_ICON, CONF_SOURCE_ID), inherit_property_from(CONF_ENTITY_CATEGORY, CONF_SOURCE_ID), inherit_property_from(CONF_UNIT_OF_MEASUREMENT, CONF_SOURCE_ID), inherit_property_from(CONF_MODE, CONF_SOURCE_ID), ) async def to_code(config): var = await number.new_number(config, min_value=0, max_value=0, step=0) await cg.register_component(var, config) source = await cg.get_variable(config[CONF_SOURCE_ID]) cg.add(var.set_source(source))