mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-19 12:43:28 +02:00
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
import esphome.codegen as cg
|
|
import esphome.config_validation as cv
|
|
from esphome.components import sensor
|
|
from esphome.const import (
|
|
CONF_DEVICE_CLASS,
|
|
CONF_ENTITY_CATEGORY,
|
|
CONF_ICON,
|
|
CONF_SOURCE_ID,
|
|
CONF_STATE_CLASS,
|
|
CONF_UNIT_OF_MEASUREMENT,
|
|
CONF_ACCURACY_DECIMALS,
|
|
)
|
|
from esphome.core.entity_helpers import inherit_property_from
|
|
|
|
from .. import copy_ns
|
|
|
|
CopySensor = copy_ns.class_("CopySensor", sensor.Sensor, cg.Component)
|
|
|
|
|
|
CONFIG_SCHEMA = (
|
|
sensor.sensor_schema(CopySensor)
|
|
.extend(
|
|
{
|
|
cv.Required(CONF_SOURCE_ID): cv.use_id(sensor.Sensor),
|
|
}
|
|
)
|
|
.extend(cv.COMPONENT_SCHEMA)
|
|
)
|
|
|
|
FINAL_VALIDATE_SCHEMA = cv.All(
|
|
inherit_property_from(CONF_UNIT_OF_MEASUREMENT, CONF_SOURCE_ID),
|
|
inherit_property_from(CONF_ICON, CONF_SOURCE_ID),
|
|
inherit_property_from(CONF_ACCURACY_DECIMALS, CONF_SOURCE_ID),
|
|
inherit_property_from(CONF_DEVICE_CLASS, CONF_SOURCE_ID),
|
|
inherit_property_from(CONF_STATE_CLASS, CONF_SOURCE_ID),
|
|
inherit_property_from(CONF_ENTITY_CATEGORY, CONF_SOURCE_ID),
|
|
)
|
|
|
|
|
|
async def to_code(config):
|
|
var = await sensor.new_sensor(config)
|
|
await cg.register_component(var, config)
|
|
|
|
source = await cg.get_variable(config[CONF_SOURCE_ID])
|
|
cg.add(var.set_source(source))
|