Fix integration sensor, add test (#619)

* Fix integration sensor, add test

* Fix

* Fix
This commit is contained in:
Otto Winter 2019-06-06 15:06:02 +02:00
parent 373f75253c
commit 2e6db39173
No known key found for this signature in database
GPG Key ID: DB66C0BE6013F97E
2 changed files with 6 additions and 3 deletions

View File

@ -2,7 +2,7 @@ import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome import automation from esphome import automation
from esphome.components import sensor from esphome.components import sensor
from esphome.const import CONF_ID, CONF_TIME_ID, CONF_SENSOR, CONF_RESTORE from esphome.const import CONF_ID, CONF_SENSOR, CONF_RESTORE
integration_ns = cg.esphome_ns.namespace('integration') integration_ns = cg.esphome_ns.namespace('integration')
IntegrationSensor = integration_ns.class_('IntegrationSensor', sensor.Sensor, cg.Component) IntegrationSensor = integration_ns.class_('IntegrationSensor', sensor.Sensor, cg.Component)
@ -26,7 +26,6 @@ INTEGRATION_METHODS = {
CONF_TIME_UNIT = 'time_unit' CONF_TIME_UNIT = 'time_unit'
CONF_INTEGRATION_METHOD = 'integration_method' CONF_INTEGRATION_METHOD = 'integration_method'
CONFIG_SCHEMA = sensor.SENSOR_SCHEMA.extend({ CONFIG_SCHEMA = sensor.SENSOR_SCHEMA.extend({
cv.GenerateID(): cv.declare_id(IntegrationSensor), cv.GenerateID(): cv.declare_id(IntegrationSensor),
cv.Required(CONF_SENSOR): cv.use_id(sensor.Sensor), cv.Required(CONF_SENSOR): cv.use_id(sensor.Sensor),
@ -45,7 +44,7 @@ def to_code(config):
sens = yield cg.get_variable(config[CONF_SENSOR]) sens = yield cg.get_variable(config[CONF_SENSOR])
cg.add(var.set_sensor(sens)) cg.add(var.set_sensor(sens))
cg.add(var.set_time(config[CONF_TIME_ID])) cg.add(var.set_time(config[CONF_TIME_UNIT]))
cg.add(var.set_method(config[CONF_INTEGRATION_METHOD])) cg.add(var.set_method(config[CONF_INTEGRATION_METHOD]))
cg.add(var.set_restore(config[CONF_RESTORE])) cg.add(var.set_restore(config[CONF_RESTORE]))

View File

@ -350,6 +350,10 @@ sensor:
- platform: total_daily_energy - platform: total_daily_energy
power_id: hlw8012_power power_id: hlw8012_power
name: "HLW8012 Total Daily Energy" name: "HLW8012 Total Daily Energy"
- platform: integration
sensor: hlw8012_power
name: "Integration Sensor"
time_unit: s
- platform: hmc5883l - platform: hmc5883l
address: 0x68 address: 0x68
field_strength_x: field_strength_x: