mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 05:24:53 +01:00
Use sensor_schema for total_daily_energy (#2090)
Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
parent
316777f757
commit
513066ba52
1 changed files with 27 additions and 8 deletions
|
@ -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):
|
||||||
|
|
Loading…
Reference in a new issue