-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
text_sensor.py
41 lines (35 loc) · 1.28 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
from esphome.const import CONF_NAME
from esphome.components.esp32_ble_tracker import CONF_ESP32_BLE_ID
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import miot, text_sensor, sensor
from esphome.const import (
ENTITY_CATEGORY_DIAGNOSTIC,
STATE_CLASS_MEASUREMENT,
UNIT_PERCENT,
)
CODEOWNERS = ["@dentra"]
AUTO_LOAD = ["miot", "sensor", "text_sensor", "switch"]
CONF_CONSUMABLE = "consumable"
miot_explorer_ns = cg.esphome_ns.namespace("miot_explorer")
MiotExplorer = miot_explorer_ns.class_(
"MiotExplorer", miot.MiotComponent, text_sensor.TextSensor
)
CONFIG_SCHEMA = text_sensor.TEXT_SENSOR_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(MiotExplorer),
cv.Required(CONF_NAME): cv.string,
cv.Optional(CONF_CONSUMABLE): sensor.sensor_schema(
unit_of_measurement=UNIT_PERCENT,
accuracy_decimals=0,
state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
}
).extend(miot.MIOT_BLE_DEVICE_SCHEMA)
async def to_code(config):
var = await miot.new_text_sensor_device(config)
if CONF_CONSUMABLE in config:
conf = config[CONF_CONSUMABLE]
sens = await sensor.new_sensor(conf)
cg.add(var.set_consumable(sens))