From 2e6db3917380fad5756065a142c8f0707670087b Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Thu, 6 Jun 2019 15:06:02 +0200 Subject: [PATCH] Fix integration sensor, add test (#619) * Fix integration sensor, add test * Fix * Fix --- esphome/components/integration/sensor.py | 5 ++--- tests/test1.yaml | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/esphome/components/integration/sensor.py b/esphome/components/integration/sensor.py index 9e4dc0847f..a354ab7433 100644 --- a/esphome/components/integration/sensor.py +++ b/esphome/components/integration/sensor.py @@ -2,7 +2,7 @@ import esphome.codegen as cg import esphome.config_validation as cv from esphome import automation 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') IntegrationSensor = integration_ns.class_('IntegrationSensor', sensor.Sensor, cg.Component) @@ -26,7 +26,6 @@ INTEGRATION_METHODS = { CONF_TIME_UNIT = 'time_unit' CONF_INTEGRATION_METHOD = 'integration_method' - CONFIG_SCHEMA = sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_id(IntegrationSensor), 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]) 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_restore(config[CONF_RESTORE])) diff --git a/tests/test1.yaml b/tests/test1.yaml index d47773c6b8..47b6aaeab5 100644 --- a/tests/test1.yaml +++ b/tests/test1.yaml @@ -350,6 +350,10 @@ sensor: - platform: total_daily_energy power_id: hlw8012_power name: "HLW8012 Total Daily Energy" + - platform: integration + sensor: hlw8012_power + name: "Integration Sensor" + time_unit: s - platform: hmc5883l address: 0x68 field_strength_x: