mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Fix integration sensor, add test (#619)
* Fix integration sensor, add test * Fix * Fix
This commit is contained in:
		| @@ -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])) | ||||
|  | ||||
|   | ||||
| @@ -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: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user