2019-04-17 12:06:00 +02:00
|
|
|
import esphome.codegen as cg
|
|
|
|
import esphome.config_validation as cv
|
|
|
|
from esphome.components import i2c
|
|
|
|
from esphome.const import CONF_ID
|
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
DEPENDENCIES = ["i2c"]
|
|
|
|
AUTO_LOAD = ["sensor", "voltage_sampler"]
|
2019-04-17 12:06:00 +02:00
|
|
|
MULTI_CONF = True
|
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
ads1115_ns = cg.esphome_ns.namespace("ads1115")
|
|
|
|
ADS1115Component = ads1115_ns.class_("ADS1115Component", cg.Component, i2c.I2CDevice)
|
2019-04-17 12:06:00 +02:00
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
CONF_CONTINUOUS_MODE = "continuous_mode"
|
|
|
|
CONFIG_SCHEMA = (
|
|
|
|
cv.Schema(
|
|
|
|
{
|
|
|
|
cv.GenerateID(): cv.declare_id(ADS1115Component),
|
|
|
|
cv.Optional(CONF_CONTINUOUS_MODE, default=False): cv.boolean,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.extend(cv.COMPONENT_SCHEMA)
|
|
|
|
.extend(i2c.i2c_device_schema(None))
|
|
|
|
)
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
|
2021-05-24 10:58:29 +02:00
|
|
|
async def to_code(config):
|
2019-04-17 12:06:00 +02:00
|
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
2021-05-24 10:58:29 +02:00
|
|
|
await cg.register_component(var, config)
|
|
|
|
await i2c.register_i2c_device(var, config)
|
2019-07-02 13:02:46 +02:00
|
|
|
|
|
|
|
cg.add(var.set_continuous_mode(config[CONF_CONTINUOUS_MODE]))
|