Add min_save_interval to total_energy/integration for memory wear (#1665)

Co-authored-by: Andreas Hergert <andreas.hergert@otrs.com>
Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
Andreas Hergert
2021-08-03 16:41:34 +02:00
committed by GitHub
parent 4c8a703084
commit 6516c64e67
7 changed files with 35 additions and 1 deletions
@@ -12,6 +12,7 @@ from esphome.const import (
DEPENDENCIES = ["time"]
CONF_POWER_ID = "power_id"
CONF_MIN_SAVE_INTERVAL = "min_save_interval"
total_daily_energy_ns = cg.esphome_ns.namespace("total_daily_energy")
TotalDailyEnergy = total_daily_energy_ns.class_(
"TotalDailyEnergy", sensor.Sensor, cg.Component
@@ -29,6 +30,9 @@ CONFIG_SCHEMA = (
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),
cv.Optional(
CONF_MIN_SAVE_INTERVAL, default="0s"
): cv.positive_time_period_milliseconds,
}
)
.extend(cv.COMPONENT_SCHEMA)
@@ -45,3 +49,4 @@ async def to_code(config):
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]))