35 lines
989 B
Python
35 lines
989 B
Python
import esphome.codegen as cg
|
|
import esphome.config_validation as cv
|
|
from esphome.components import i2c, sensor
|
|
from esphome.const import (
|
|
CONF_ID,
|
|
DEVICE_CLASS_DISTANCE,
|
|
STATE_CLASS_MEASUREMENT,
|
|
UNIT_CENTIMETER,
|
|
ICON_ARROW_EXPAND_HORIZONTAL,
|
|
)
|
|
|
|
DEPENDENCIES = ["i2c"]
|
|
|
|
sen0590_ns = cg.esphome_ns.namespace("sen0590")
|
|
SEN0590Component = sen0590_ns.class_(
|
|
"SEN0590Component", sensor.Sensor, cg.PollingComponent, i2c.I2CDevice
|
|
)
|
|
|
|
CONFIG_SCHEMA = (
|
|
sensor.sensor_schema(
|
|
SEN0590Component,
|
|
unit_of_measurement=UNIT_CENTIMETER,
|
|
icon=ICON_ARROW_EXPAND_HORIZONTAL,
|
|
accuracy_decimals=1,
|
|
device_class=DEVICE_CLASS_DISTANCE,
|
|
state_class=STATE_CLASS_MEASUREMENT,
|
|
)
|
|
.extend(cv.polling_component_schema("100ms"))
|
|
.extend(i2c.i2c_device_schema(0x74))
|
|
)
|
|
|
|
async def to_code(config):
|
|
var = await sensor.new_sensor(config)
|
|
await cg.register_component(var, config)
|
|
await i2c.register_i2c_device(var, config) |