1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-21 12:42:21 +01:00

Add class as first positional arg to sensor_schema (#3216)

This commit is contained in:
Jesse Hills
2022-02-18 10:27:20 +13:00
committed by GitHub
parent 140db85d21
commit 3b8bb09ae3
62 changed files with 506 additions and 629 deletions

View File

@@ -5,7 +5,6 @@ import esphome.codegen as cg
from esphome.components import sensor
from esphome.const import (
CONF_CALIBRATION,
CONF_ID,
CONF_REFERENCE_RESISTANCE,
CONF_REFERENCE_TEMPERATURE,
CONF_SENSOR,
@@ -117,6 +116,7 @@ def process_calibration(value):
CONFIG_SCHEMA = (
sensor.sensor_schema(
NTC,
unit_of_measurement=UNIT_CELSIUS,
accuracy_decimals=1,
device_class=DEVICE_CLASS_TEMPERATURE,
@@ -124,7 +124,6 @@ CONFIG_SCHEMA = (
)
.extend(
{
cv.GenerateID(): cv.declare_id(NTC),
cv.Required(CONF_SENSOR): cv.use_id(sensor.Sensor),
cv.Required(CONF_CALIBRATION): process_calibration,
}
@@ -134,9 +133,8 @@ CONFIG_SCHEMA = (
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
var = await sensor.new_sensor(config)
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))