-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathsensor.py
88 lines (80 loc) · 3.3 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import automation
from esphome.const import CONF_TRIGGER_ID
from .. import miot # pylint: disable=relative-beyond-top-level
CONF_ON_SHORT_PRESS = "on_short_press"
CONF_ON_LONG_PRESS = "on_long_press"
CONF_ON_ROTATE_LEFT = "on_rotate_left"
CONF_ON_ROTATE_RIGHT = "on_rotate_right"
CONF_ON_ROTATE_LEFT_PRESSED = "on_rotate_left_pressed"
CONF_ON_ROTATE_RIGHT_PRESSED = "on_rotate_right_pressed"
CODEOWNERS = ["@dentra"]
AUTO_LOAD = ["miot", "sensor"]
miot_ylkg0xyl_ns = cg.esphome_ns.namespace("miot_ylkg0xyl")
MiotYLKG0XYL = miot_ylkg0xyl_ns.class_("MiotYLKG0XYL", miot.MiotComponent)
MiotYLKG0XYLTrigger = miot_ylkg0xyl_ns.class_(
"MiotYLKG0XYLTrigger", automation.Trigger.template(), miot.MiotListener
)
MiotYLKG0XYLEvent = miot_ylkg0xyl_ns.enum("MiotYLKG0XYLEvent")
CONFIG_SCHEMA = cv.Schema(
{
# cv.GenerateID(): cv.declare_id(MiotYLKG0XYL),
cv.Optional(CONF_ON_SHORT_PRESS): automation.validate_automation(
cv.Schema(
{cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(MiotYLKG0XYLTrigger)}
),
),
cv.Optional(CONF_ON_LONG_PRESS): automation.validate_automation(
cv.Schema(
{cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(MiotYLKG0XYLTrigger)}
),
),
cv.Optional(CONF_ON_ROTATE_LEFT): automation.validate_automation(
cv.Schema(
{cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(MiotYLKG0XYLTrigger)}
),
),
cv.Optional(CONF_ON_ROTATE_RIGHT): automation.validate_automation(
cv.Schema(
{cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(MiotYLKG0XYLTrigger)}
),
),
cv.Optional(CONF_ON_ROTATE_LEFT_PRESSED): automation.validate_automation(
cv.Schema(
{cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(MiotYLKG0XYLTrigger)}
),
),
cv.Optional(CONF_ON_ROTATE_RIGHT_PRESSED): automation.validate_automation(
cv.Schema(
{cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(MiotYLKG0XYLTrigger)}
),
),
},
).extend(miot.MIOT_BLE_DEVICE_SCHEMA)
async def configure_event_trigger_(config, param, enum):
for conf in config.get(param, []):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], enum)
await miot.register_miot_device(trigger, config)
await miot.setup_device_core_(trigger, config)
await automation.build_automation(trigger, [(cg.uint8, "x")], conf)
async def to_code(config):
"""Code generation entry point"""
await configure_event_trigger_(
config, CONF_ON_SHORT_PRESS, MiotYLKG0XYLEvent.ON_SHORT_PRESS
)
await configure_event_trigger_(
config, CONF_ON_LONG_PRESS, MiotYLKG0XYLEvent.ON_LONG_PRESS
)
await configure_event_trigger_(
config, CONF_ON_ROTATE_LEFT, MiotYLKG0XYLEvent.ON_ROTATE_LEFT
)
await configure_event_trigger_(
config, CONF_ON_ROTATE_RIGHT, MiotYLKG0XYLEvent.ON_ROTATE_RIGHT
)
await configure_event_trigger_(
config, CONF_ON_ROTATE_LEFT_PRESSED, MiotYLKG0XYLEvent.ON_ROTATE_LEFT_PRESSED
)
await configure_event_trigger_(
config, CONF_ON_ROTATE_RIGHT_PRESSED, MiotYLKG0XYLEvent.ON_ROTATE_RIGHT_PRESSED
)