-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
miot_th.cpp
102 lines (84 loc) · 2.71 KB
/
miot_th.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "esphome/core/log.h"
#include "miot_th.h"
namespace esphome {
namespace miot_th {
static const char *const TAG = "miot_th";
constexpr uint16_t PRODUCT_ID_XMWSDJ04MMC = 0x1203;
constexpr uint16_t PRODUCT_ID_LYWSD02MMC = 0x16E4;
void MiotTH::dump_config() {
this->dump_config_(TAG, "TH");
LOG_SENSOR(" ", "Temperature", this);
LOG_SENSOR(" ", "Humidity", this->humidity_);
}
void MiotTH::process_temperature_(const miot::BLEObject &obj) {
const auto temperature = obj.get_temperature();
if (temperature.has_value()) {
this->publish_state(*temperature);
}
}
void MiotTH::process_humidity_(const miot::BLEObject &obj) {
if (this->humidity_ != nullptr) {
const auto humidity = obj.get_humidity();
if (humidity.has_value()) {
this->humidity_->publish_state(*humidity);
}
}
}
void MiotTH::process_temperature_humidity_(const miot::BLEObject &obj) {
const auto temperature_humidity = obj.get_temperature_humidity();
if (temperature_humidity != nullptr) {
this->publish_state(temperature_humidity->get_temperature());
if (this->humidity_ != nullptr) {
this->humidity_->publish_state(temperature_humidity->get_humidity());
}
}
}
void MiotTH::process_miaomiaoce_temperature_1001_(const miot::BLEObject &obj) {
const auto temperature = obj.get_miaomiaoce_temperature_1001();
if (temperature.has_value()) {
this->publish_state(*temperature);
}
}
void MiotTH::process_miaomiaoce_humidity_1008_(const miot::BLEObject &obj) {
if (this->humidity_ != nullptr) {
const auto humidity = obj.get_miaomiaoce_humidity_1008();
if (humidity.has_value()) {
this->humidity_->publish_state(*humidity);
}
}
}
void MiotTH::process_miaomiaoce_humidity_1002_(const miot::BLEObject &obj) {
if (this->humidity_ != nullptr) {
const auto humidity = obj.get_miaomiaoce_humidity_1002();
if (humidity.has_value()) {
this->humidity_->publish_state(*humidity);
}
}
}
bool MiotTH::process_object_(const miot::BLEObject &obj) {
switch (obj.id) {
case miot::MIID_TEMPERATURE:
this->process_temperature_(obj);
break;
case miot::MIID_HUMIDITY:
this->process_humidity_(obj);
break;
case miot::MIID_TEMPERATURE_HUMIDITY:
this->process_temperature_humidity_(obj);
break;
case miot::MIID_MIAOMIAOCE_TEMPERATURE_1001:
this->process_miaomiaoce_temperature_1001_(obj);
break;
case miot::MIID_MIAOMIAOCE_HUMIDITY_1008:
this->process_miaomiaoce_humidity_1008_(obj);
break;
case miot::MIID_MIAOMIAOCE_HUMIDITY_1002:
this->process_miaomiaoce_humidity_1002_(obj);
break;
default:
return this->process_default_(obj);
}
return true;
}
} // namespace miot_th
} // namespace esphome