mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-06 21:09:53 +02:00
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:
@@ -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]))
|
||||
|
||||
Reference in New Issue
Block a user