esphome/esphome/components/hrxl_maxsonar_wr/sensor.py
Otto Winter 5c65f9f9ad
Convert sensor_schema to use kwargs (#2094)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2021-08-01 12:21:32 +02:00

39 lines
1 KiB
Python

import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import sensor, uart
from esphome.const import (
CONF_ID,
STATE_CLASS_MEASUREMENT,
UNIT_METER,
ICON_ARROW_EXPAND_VERTICAL,
)
CODEOWNERS = ["@netmikey"]
DEPENDENCIES = ["uart"]
hrxlmaxsonarwr_ns = cg.esphome_ns.namespace("hrxl_maxsonar_wr")
HrxlMaxsonarWrComponent = hrxlmaxsonarwr_ns.class_(
"HrxlMaxsonarWrComponent", sensor.Sensor, cg.Component, uart.UARTDevice
)
CONFIG_SCHEMA = (
sensor.sensor_schema(
unit_of_measurement=UNIT_METER,
icon=ICON_ARROW_EXPAND_VERTICAL,
accuracy_decimals=3,
state_class=STATE_CLASS_MEASUREMENT,
)
.extend(
{
cv.GenerateID(): cv.declare_id(HrxlMaxsonarWrComponent),
}
)
.extend(uart.UART_DEVICE_SCHEMA)
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await sensor.register_sensor(var, config)
await uart.register_uart_device(var, config)