2018-11-09 20:27:19 +01:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2018-11-12 23:30:31 +01:00
|
|
|
from esphomeyaml.components import sensor, time
|
2018-11-09 20:27:19 +01:00
|
|
|
import esphomeyaml.config_validation as cv
|
|
|
|
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_TIME_ID
|
2018-11-12 23:30:31 +01:00
|
|
|
from esphomeyaml.helpers import App, Application, Component, get_variable, setup_component, variable
|
2018-11-09 20:27:19 +01:00
|
|
|
|
|
|
|
DEPENDENCIES = ['time']
|
|
|
|
|
|
|
|
CONF_POWER_ID = 'power_id'
|
2018-11-12 23:30:31 +01:00
|
|
|
MakeTotalDailyEnergySensor = Application.struct('MakeTotalDailyEnergySensor')
|
|
|
|
TotalDailyEnergy = sensor.sensor_ns.class_('TotalDailyEnergy', sensor.Sensor, Component)
|
2018-11-09 20:27:19 +01:00
|
|
|
|
|
|
|
PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
|
|
|
|
cv.GenerateID(): cv.declare_variable_id(TotalDailyEnergy),
|
|
|
|
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeTotalDailyEnergySensor),
|
2018-11-12 23:30:31 +01:00
|
|
|
cv.GenerateID(CONF_TIME_ID): cv.use_variable_id(time.RealTimeClockComponent),
|
|
|
|
vol.Required(CONF_POWER_ID): cv.use_variable_id(sensor.Sensor),
|
|
|
|
}).extend(cv.COMPONENT_SCHEMA.schema))
|
2018-11-09 20:27:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
def to_code(config):
|
2018-11-12 23:30:31 +01:00
|
|
|
for time_ in get_variable(config[CONF_TIME_ID]):
|
2018-11-09 20:27:19 +01:00
|
|
|
yield
|
|
|
|
for sens in get_variable(config[CONF_POWER_ID]):
|
|
|
|
yield
|
2018-11-12 23:30:31 +01:00
|
|
|
rhs = App.make_total_daily_energy_sensor(config[CONF_NAME], time_, sens)
|
2018-11-09 20:27:19 +01:00
|
|
|
make = variable(config[CONF_MAKE_ID], rhs)
|
2018-11-12 23:30:31 +01:00
|
|
|
total_energy = make.Ptotal_energy
|
|
|
|
|
|
|
|
sensor.setup_sensor(total_energy, make.Pmqtt, config)
|
|
|
|
setup_component(total_energy, config)
|
2018-11-09 20:27:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
BUILD_FLAGS = '-DUSE_TOTAL_DAILY_ENERGY_SENSOR'
|
|
|
|
|
|
|
|
|
|
|
|
def to_hass_config(data, config):
|
|
|
|
return sensor.core_to_hass_config(data, config)
|