CSE7766 update interval (#250)

* CSE7766 update interval

* PollingComponent
This commit is contained in:
Otto Winter 2018-12-01 13:19:34 +01:00
parent f1241af91d
commit 1726c4237b
No known key found for this signature in database
GPG key ID: DB66C0BE6013F97E

View file

@ -4,12 +4,12 @@ from esphomeyaml.components import sensor, uart
from esphomeyaml.components.uart import UARTComponent from esphomeyaml.components.uart import UARTComponent
import esphomeyaml.config_validation as cv import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_CURRENT, CONF_ID, CONF_NAME, CONF_POWER, CONF_UART_ID, \ from esphomeyaml.const import CONF_CURRENT, CONF_ID, CONF_NAME, CONF_POWER, CONF_UART_ID, \
CONF_VOLTAGE CONF_UPDATE_INTERVAL, CONF_VOLTAGE
from esphomeyaml.helpers import App, Pvariable, get_variable, setup_component, Component from esphomeyaml.helpers import App, PollingComponent, Pvariable, get_variable, setup_component
DEPENDENCIES = ['uart'] DEPENDENCIES = ['uart']
CSE7766Component = sensor.sensor_ns.class_('CSE7766Component', Component, uart.UARTDevice) CSE7766Component = sensor.sensor_ns.class_('CSE7766Component', PollingComponent, uart.UARTDevice)
CSE7766VoltageSensor = sensor.sensor_ns.class_('CSE7766VoltageSensor', CSE7766VoltageSensor = sensor.sensor_ns.class_('CSE7766VoltageSensor',
sensor.EmptySensor) sensor.EmptySensor)
CSE7766CurrentSensor = sensor.sensor_ns.class_('CSE7766CurrentSensor', CSE7766CurrentSensor = sensor.sensor_ns.class_('CSE7766CurrentSensor',
@ -30,6 +30,7 @@ PLATFORM_SCHEMA = vol.All(sensor.PLATFORM_SCHEMA.extend({
vol.Optional(CONF_POWER): cv.nameable(sensor.SENSOR_SCHEMA.extend({ vol.Optional(CONF_POWER): cv.nameable(sensor.SENSOR_SCHEMA.extend({
cv.GenerateID(): cv.declare_variable_id(CSE7766PowerSensor), cv.GenerateID(): cv.declare_variable_id(CSE7766PowerSensor),
})), })),
vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval,
}).extend(cv.COMPONENT_SCHEMA.schema), cv.has_at_least_one_key(CONF_VOLTAGE, CONF_CURRENT, }).extend(cv.COMPONENT_SCHEMA.schema), cv.has_at_least_one_key(CONF_VOLTAGE, CONF_CURRENT,
CONF_POWER)) CONF_POWER))
@ -38,7 +39,7 @@ def to_code(config):
for uart_ in get_variable(config[CONF_UART_ID]): for uart_ in get_variable(config[CONF_UART_ID]):
yield yield
rhs = App.make_cse7766(uart_) rhs = App.make_cse7766(uart_, config.get(CONF_UPDATE_INTERVAL))
cse = Pvariable(config[CONF_ID], rhs) cse = Pvariable(config[CONF_ID], rhs)
if CONF_VOLTAGE in config: if CONF_VOLTAGE in config: