mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-01 02:28:28 +02:00
Updated Mcp3008 to support reference_voltage and voltage_sampler::VoltageSampler (#1387)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
@@ -1,23 +1,29 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import sensor
|
||||
from esphome.components import sensor, voltage_sampler
|
||||
from esphome.const import CONF_ID, CONF_NUMBER, CONF_NAME
|
||||
from . import mcp3008_ns, MCP3008
|
||||
|
||||
AUTO_LOAD = ['voltage_sampler']
|
||||
|
||||
DEPENDENCIES = ['mcp3008']
|
||||
|
||||
MCP3008Sensor = mcp3008_ns.class_('MCP3008Sensor', sensor.Sensor, cg.PollingComponent)
|
||||
|
||||
MCP3008Sensor = mcp3008_ns.class_('MCP3008Sensor', sensor.Sensor, cg.PollingComponent,
|
||||
voltage_sampler.VoltageSampler)
|
||||
CONF_REFERENCE_VOLTAGE = 'reference_voltage'
|
||||
CONF_MCP3008_ID = 'mcp3008_id'
|
||||
|
||||
CONFIG_SCHEMA = sensor.SENSOR_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_id(MCP3008Sensor),
|
||||
cv.GenerateID(CONF_MCP3008_ID): cv.use_id(MCP3008),
|
||||
cv.Required(CONF_NUMBER): cv.int_,
|
||||
cv.Optional(CONF_REFERENCE_VOLTAGE, default='3.3V'): cv.voltage,
|
||||
}).extend(cv.polling_component_schema('1s'))
|
||||
|
||||
|
||||
def to_code(config):
|
||||
parent = yield cg.get_variable(config[CONF_MCP3008_ID])
|
||||
var = cg.new_Pvariable(config[CONF_ID], parent, config[CONF_NAME], config[CONF_NUMBER])
|
||||
var = cg.new_Pvariable(config[CONF_ID], parent, config[CONF_NAME],
|
||||
config[CONF_NUMBER], config[CONF_REFERENCE_VOLTAGE])
|
||||
yield cg.register_component(var, config)
|
||||
yield sensor.register_sensor(var, config)
|
||||
|
||||
Reference in New Issue
Block a user