-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtext_sensor.py
41 lines (36 loc) · 1.14 KB
/
text_sensor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import text_sensor
from . import (
DlmsCosem,
dlms_cosem_ns,
obis_code,
CONF_DLMS_COSEM_ID,
CONF_OBIS_CODE,
CONF_DONT_PUBLISH,
CONF_CLASS,
)
AUTO_LOAD = ["dlms_cosem"]
DlmsCosemTextSensor = dlms_cosem_ns.class_(
"DlmsCosemTextSensor", text_sensor.TextSensor
)
CONFIG_SCHEMA = cv.All(
text_sensor.text_sensor_schema(
DlmsCosemTextSensor,
).extend(
{
cv.GenerateID(CONF_DLMS_COSEM_ID): cv.use_id(DlmsCosem),
cv.Required(CONF_OBIS_CODE): obis_code,
cv.Optional(CONF_DONT_PUBLISH, default=False): cv.boolean,
cv.Optional(CONF_CLASS, default=1): cv.int_,
}
),
cv.has_exactly_one_key(CONF_OBIS_CODE),
)
async def to_code(config):
component = await cg.get_variable(config[CONF_DLMS_COSEM_ID])
var = await text_sensor.new_text_sensor(config)
cg.add(var.set_obis_code(config[CONF_OBIS_CODE]))
cg.add(var.set_dont_publish(config.get(CONF_DONT_PUBLISH)))
cg.add(var.set_obis_class(config[CONF_CLASS]))
cg.add(component.register_sensor(var))