-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
text_sensor.py
67 lines (57 loc) · 2.35 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from esphome.const import (
CONF_ICON,
CONF_ID,
CONF_VERSION,
)
from esphome.cpp_types import Component
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import miot, miot_client, text_sensor, ble_client
CODEOWNERS = ["@dentra"]
AUTO_LOAD = ["miot", "miot_client", "text_sensor", "ble_client"]
ICON_VERSION = "mdi:cellphone-arrow-down"
miot_ylxx0xyl_ns = cg.esphome_ns.namespace("miot_ylxx0xyl")
MiotYLxx0xYLPair = miot_ylxx0xyl_ns.class_(
"MiotYLxx0xYLPair", Component, miot.MiotListener, text_sensor.TextSensor
)
MiotYLxx0xYLNode = miot_ylxx0xyl_ns.class_(
"MiotYLxx0xYLNode", miot_client.MiotClient, miot_client.AuthClientListener
)
CONFIG_SCHEMA = (
text_sensor.TEXT_SENSOR_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(MiotYLxx0xYLPair),
cv.GenerateID(miot.CONF_MIOT_ID): cv.use_id(miot.MiBeaconTracker),
cv.Optional(CONF_VERSION): text_sensor.TEXT_SENSOR_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(text_sensor.TextSensor),
cv.Optional(CONF_ICON, default=ICON_VERSION): cv.icon,
}
),
cv.Optional(miot.CONF_PRODUCT_ID): cv.uint16_t,
}
)
.extend(ble_client.BLE_CLIENT_SCHEMA)
.extend(cv.COMPONENT_SCHEMA)
.extend(miot_client.client_schema(MiotYLxx0xYLNode))
.extend(miot_client.legacy_auth_schema())
)
async def to_code(config):
# var = await miot.new_text_sensor_device(config)
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await miot.register_miot_device(var, config)
await text_sensor.register_text_sensor(var, config)
auth = await miot_client.register_legacy_auth_client(config)
node = await miot_client.register_client(config, var)
cg.add(auth.add_auth_listener(node))
cg.add(node.set_auth_client(auth))
cg.add(var.set_auth_client(auth))
blec = await cg.get_variable(config[ble_client.CONF_BLE_CLIENT_ID])
cg.add(var.set_address(blec.get_address()))
if CONF_VERSION in config:
sens = cg.new_Pvariable(config[CONF_VERSION][CONF_ID])
await text_sensor.register_text_sensor(sens, config[CONF_VERSION])
cg.add(var.set_version(sens))
if miot.CONF_PRODUCT_ID in config:
cg.add(var.set_product_id(config[miot.CONF_PRODUCT_ID]))