From 59c81a504c9d01e71701b40e4cea61783a0f8d27 Mon Sep 17 00:00:00 2001 From: Philipp Harms Date: Fri, 18 Oct 2024 23:31:42 +0200 Subject: [PATCH] fix sensor.py --- esphome/components/mcp3221/sensor.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/esphome/components/mcp3221/sensor.py b/esphome/components/mcp3221/sensor.py index df04d1e72e..2080a3cf5e 100644 --- a/esphome/components/mcp3221/sensor.py +++ b/esphome/components/mcp3221/sensor.py @@ -1,8 +1,7 @@ import esphome.codegen as cg -from esphome.components import i2c, sensor +from esphome.components import i2c, sensor, voltage_sampler import esphome.config_validation as cv from esphome.const import ( - CONF_RAW, CONF_REFERENCE_VOLTAGE, DEVICE_CLASS_VOLTAGE, ICON_SCALE, @@ -17,7 +16,11 @@ DEPENDENCIES = ["i2c"] mcp3221_ns = cg.esphome_ns.namespace("mcp3221") MCP3221Sensor = mcp3221_ns.class_( - "MCP3221Sensor", sensor.Sensor, cg.PollingComponent, i2c.I2CDevice + "MCP3221Sensor", + sensor.Sensor, + voltage_sampler.VoltageSampler, + cg.PollingComponent, + i2c.I2CDevice, ) @@ -33,7 +36,6 @@ CONFIG_SCHEMA = ( .extend( { cv.Optional(CONF_REFERENCE_VOLTAGE, default="3.3V"): cv.voltage, - cv.Optional(CONF_RAW, default=False): cv.boolean, } ) .extend(cv.polling_component_schema("60s")) @@ -43,5 +45,6 @@ CONFIG_SCHEMA = ( async def to_code(config): var = await sensor.new_sensor(config) + cg.add(var.set_reference_voltage(config[CONF_REFERENCE_VOLTAGE])) await cg.register_component(var, config) await i2c.register_i2c_device(var, config)