1
0
mirror of https://github.com/esphome/esphome.git synced 2025-04-14 14:50:32 +01:00
Oleg Tarasov 58d028ac13
Add OpenTherm component (part 3: rest of the sensors) (#7676)
Co-authored-by: FreeBear <freebear@tuxcnc.org>
Co-authored-by: FreeBear-nc <67865163+FreeBear-nc@users.noreply.github.com>
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2024-11-12 16:19:42 +13:00

52 lines
1.3 KiB
Python

from typing import Any
import esphome.config_validation as cv
from esphome.components import sensor
from .. import const, schema, validate, generate
DEPENDENCIES = [const.OPENTHERM]
COMPONENT_TYPE = const.SENSOR
MSG_DATA_TYPES = {
"u8_lb",
"u8_hb",
"s8_lb",
"s8_hb",
"u8_lb_60",
"u8_hb_60",
"u16",
"s16",
"f88",
}
def get_entity_validation_schema(entity: schema.SensorSchema) -> cv.Schema:
return sensor.sensor_schema(
unit_of_measurement=entity.unit_of_measurement
or sensor._UNDEF, # pylint: disable=protected-access
accuracy_decimals=entity.accuracy_decimals,
device_class=entity.device_class
or sensor._UNDEF, # pylint: disable=protected-access
icon=entity.icon or sensor._UNDEF, # pylint: disable=protected-access
state_class=entity.state_class,
).extend(
{
cv.Optional(const.CONF_DATA_TYPE): cv.one_of(*MSG_DATA_TYPES),
}
)
CONFIG_SCHEMA = validate.create_component_schema(
schema.SENSORS, get_entity_validation_schema
)
async def to_code(config: dict[str, Any]) -> None:
await generate.component_to_code(
COMPONENT_TYPE,
schema.SENSORS,
sensor.Sensor,
generate.create_only_conf(sensor.new_sensor),
config,
)