-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathautomation.cpp
71 lines (67 loc) · 1.83 KB
/
automation.cpp
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
#include "esphome/core/log.h"
#include "automation.h"
namespace esphome {
namespace miot_ylkg0xyl {
static const char *const TAG = "miot_ylkg0xyl.automation";
bool MiotYLKG0XYLTrigger::process_object_(const miot::BLEObject &obj) {
switch (obj.id) {
case miot::MIID_BUTTON_EVENT: {
const auto button_event = obj.get_typed<miot::ButtonEvent>();
if (button_event != nullptr) {
uint8_t value = this->process_button_event_(*button_event);
if (value != 0) {
button_event->dump(TAG);
this->trigger(value);
return true;
}
}
return false;
}
default:
return this->process_unhandled_(obj);
}
return false;
}
uint8_t MiotYLKG0XYLTrigger::process_button_event_(const miot::ButtonEvent &button_event) {
switch (this->event_) {
case ON_SHORT_PRESS: {
if (button_event.type == miot::ButtonEvent::KNOB) {
return button_event.knob.short_press();
}
break;
}
case ON_LONG_PRESS: {
if (button_event.type == miot::ButtonEvent::KNOB) {
return button_event.knob.long_press();
}
break;
}
case ON_ROTATE_LEFT: {
if (button_event.type == miot::ButtonEvent::DIMMER) {
return button_event.dimmer.left();
}
break;
}
case ON_ROTATE_RIGHT: {
if (button_event.type == miot::ButtonEvent::DIMMER) {
return button_event.dimmer.right();
}
break;
}
case ON_ROTATE_LEFT_PRESSED: {
if (button_event.type == miot::ButtonEvent::DIMMER) {
return button_event.dimmer.left_pressed();
}
break;
}
case ON_ROTATE_RIGHT_PRESSED: {
if (button_event.type == miot::ButtonEvent::DIMMER) {
return button_event.dimmer.right_pressed();
}
break;
}
}
return 0;
}
} // namespace miot_ylkg0xyl
} // namespace esphome