mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 15:38:11 +01:00
fix sensor.py
This commit is contained in:
parent
77f1c0ab43
commit
59c81a504c
1 changed files with 7 additions and 4 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue