-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmiot_mccgq02hl.cpp
76 lines (67 loc) · 1.78 KB
/
miot_mccgq02hl.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
72
73
74
75
76
#include "inttypes.h"
#include "esphome/core/log.h"
#include "miot_mccgq02hl.h"
namespace esphome {
namespace miot_mccgq02hl {
static const char *const TAG = "miot_mccgq02hl";
void MiotMCCGQ02HL::dump_config() {
this->dump_config_(TAG, "MCCGQ02HL");
LOG_BINARY_SENSOR(" ", "Opening", this);
LOG_BINARY_SENSOR(" ", "Light", this->light_);
LOG_BINARY_SENSOR(" ", "Alert", this->alert_);
}
void MiotMCCGQ02HL::process_door_sensor_(const miot::BLEObject &obj) {
const auto opening = obj.get_door_sensor();
if (!opening.has_value()) {
return;
}
switch (*opening) {
case 0x01: { // closed
this->publish_state(false);
if (this->alert_ != nullptr) {
this->alert_->publish_state(false);
}
break;
}
case 0x00: { // opened
this->publish_state(true);
if (this->alert_ != nullptr) {
this->alert_->publish_state(false);
}
break;
}
case 0x02: { // not closed over time
this->publish_state(true);
if (this->alert_ != nullptr) {
this->alert_->publish_state(true);
}
break;
}
case 0x03: // device reset
// do nothing
break;
}
}
void MiotMCCGQ02HL::process_light_intensity_(const miot::BLEObject &obj) {
if (this->light_ != nullptr) {
const auto light = obj.get_light_intensity();
if (light.has_value()) {
this->light_->publish_state(*light);
}
}
}
bool MiotMCCGQ02HL::process_object_(const miot::BLEObject &obj) {
switch (obj.id) {
case miot::MIID_DOOR_SENSOR:
this->process_door_sensor_(obj);
break;
case miot::MIID_LIGHT_INTENSITY:
this->process_light_intensity_(obj);
break;
default:
return this->process_default_(obj);
}
return true;
}
} // namespace miot_mccgq02hl
} // namespace esphome