-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
sensor.py
52 lines (45 loc) · 1.58 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
48
49
50
51
52
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import automation
from esphome.components import miot
from esphome.const import (
CONF_TRIGGER_ID,
)
CONF_BUTTON = "button"
CONF_ON_TWIST = "on_twist"
CODEOWNERS = ["@dentra"]
AUTO_LOAD = ["miot", "sensor"]
miot_xmmfo1jqd_ns = cg.esphome_ns.namespace("miot_xmmfo1jqd")
MiotXMMFO1JQD = miot_xmmfo1jqd_ns.class_("MiotXMMFO1JQD", miot.MiotComponent)
MiotXMMFO1JQDTrigger = miot_xmmfo1jqd_ns.class_(
"MiotXMMFO1JQDTrigger", automation.Trigger.template(), miot.MiotListener
)
ButtonEventType = miot.miot_ns.namespace("ButtonEvent").enum("Type")
BUTTON_NAMES = {
"clockwise": 0,
"counterclockwise": 1,
}
CONFIG_SCHEMA = cv.Schema(
{
cv.GenerateID(): cv.declare_id(MiotXMMFO1JQD),
cv.Optional(CONF_ON_TWIST): automation.validate_automation(
cv.Schema(
{
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(MiotXMMFO1JQDTrigger),
cv.Required(CONF_BUTTON): cv.one_of(*BUTTON_NAMES, lower=True),
}
),
),
},
).extend(miot.MIOT_BLE_DEVICE_SCHEMA)
async def to_code(config):
"""Code generation entry point"""
for conf in config.get(CONF_ON_TWIST, []):
trigger = cg.new_Pvariable(
conf[CONF_TRIGGER_ID],
ButtonEventType.BUTTON_CLICK,
BUTTON_NAMES[conf[CONF_BUTTON]],
)
await miot.register_miot_device(trigger, config)
await miot.setup_device_core_(trigger, config)
await automation.build_automation(trigger, [], conf)