Use sensor_schema for total_daily_energy (#2090)

Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
Jesse Hills 2021-07-29 19:46:15 +12:00
parent be4c718859
commit 62f3039d82
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A

View File

@ -1,7 +1,15 @@
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.components import sensor, time from esphome.components import sensor, time
from esphome.const import CONF_ID, CONF_TIME_ID from esphome.const import (
CONF_ID,
CONF_TIME_ID,
DEVICE_CLASS_ENERGY,
ICON_EMPTY,
LAST_RESET_TYPE_AUTO,
STATE_CLASS_MEASUREMENT,
UNIT_EMPTY,
)
DEPENDENCIES = ["time"] DEPENDENCIES = ["time"]
@ -11,13 +19,24 @@ TotalDailyEnergy = total_daily_energy_ns.class_(
"TotalDailyEnergy", sensor.Sensor, cg.Component "TotalDailyEnergy", sensor.Sensor, cg.Component
) )
CONFIG_SCHEMA = sensor.SENSOR_SCHEMA.extend( CONFIG_SCHEMA = (
{ sensor.sensor_schema(
cv.GenerateID(): cv.declare_id(TotalDailyEnergy), UNIT_EMPTY,
cv.GenerateID(CONF_TIME_ID): cv.use_id(time.RealTimeClock), ICON_EMPTY,
cv.Required(CONF_POWER_ID): cv.use_id(sensor.Sensor), 0,
} DEVICE_CLASS_ENERGY,
).extend(cv.COMPONENT_SCHEMA) STATE_CLASS_MEASUREMENT,
LAST_RESET_TYPE_AUTO,
)
.extend(
{
cv.GenerateID(): cv.declare_id(TotalDailyEnergy),
cv.GenerateID(CONF_TIME_ID): cv.use_id(time.RealTimeClock),
cv.Required(CONF_POWER_ID): cv.use_id(sensor.Sensor),
}
)
.extend(cv.COMPONENT_SCHEMA)
)
async def to_code(config): async def to_code(config):