-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathsensor.py
47 lines (42 loc) · 1.33 KB
/
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
42
43
44
45
46
47
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import sensor
from esphome.const import (
CONF_HUMIDITY,
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE,
STATE_CLASS_MEASUREMENT,
UNIT_CELSIUS,
UNIT_PERCENT,
)
from .. import miot # pylint: disable=relative-beyond-top-level
CODEOWNERS = ["@dentra"]
AUTO_LOAD = ["miot"]
miot_th_ns = cg.esphome_ns.namespace("miot_th")
MiotThermoGigro = miot_th_ns.class_("MiotTH", miot.MiotComponent, sensor.Sensor)
CONFIG_SCHEMA = (
sensor.sensor_schema(
MiotThermoGigro,
unit_of_measurement=UNIT_CELSIUS,
accuracy_decimals=1,
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
)
.extend(
{
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
unit_of_measurement=UNIT_PERCENT,
accuracy_decimals=1,
device_class=DEVICE_CLASS_HUMIDITY,
state_class=STATE_CLASS_MEASUREMENT,
),
},
)
.extend(miot.MIOT_BLE_DEVICE_SCHEMA)
)
async def to_code(config):
"""Code generation entry point"""
var = await miot.new_sensor_device(config)
if CONF_HUMIDITY in config:
sens = await sensor.new_sensor(config[CONF_HUMIDITY])
cg.add(var.set_humidity(sens))