-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathdevice.h
More file actions
85 lines (63 loc) · 2.35 KB
/
Copy pathdevice.h
File metadata and controls
85 lines (63 loc) · 2.35 KB
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
#pragma once
#include "esphome/components/ble_client/ble_client.h"
#include "esphome/components/climate/climate.h"
#include "esphome/core/preferences.h"
#include "helpers.h"
#include "command.h"
#include "properties.h"
#include "my_component.h"
#include "xxtea.h"
#ifdef USE_ESP32
#include <esp_gattc_api.h>
#include <set>
namespace esphome
{
namespace danfoss_eco
{
using namespace std;
using namespace climate;
class Device : public MyComponent, public esphome::ble_client::BLEClientNode
{
public:
Device() : xxtea(make_shared<Xxtea>()){};
void dump_config() override
{
LOG_CLIMATE("", "Danfoss Eco eTRV", this);
ESP_LOGCONFIG(TAG, " MAC Address: %s", this->parent()->address_str().c_str());
LOG_SENSOR("", "Battery Level", this->battery_level_);
LOG_SENSOR("", "Room Temperature", this->temperature_);
LOG_BINARY_SENSOR("", "Problems", this->problems_);
LOG_TEXT_SENSOR("", "Problems (Detail)", this->problems_detail_);
}
void setup() override;
void loop() override;
void update() override;
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override;
void set_secret_key(uint8_t *, bool) override;
void set_secret_key(const string &);
void set_pin_code(const string &);
protected:
void control(const ClimateCall &call) override;
void connect();
void disconnect();
void write_pin();
void on_write_pin(esp_ble_gattc_cb_param_t::gattc_write_evt_param);
void on_read(esp_ble_gattc_cb_param_t::gattc_read_char_evt_param);
void on_write(esp_ble_gattc_cb_param_t::gattc_write_evt_param);
shared_ptr<Xxtea> xxtea;
shared_ptr<WritableProperty> p_pin{nullptr};
shared_ptr<BatteryProperty> p_battery{nullptr};
shared_ptr<TemperatureProperty> p_temperature{nullptr};
shared_ptr<SettingsProperty> p_settings{nullptr};
shared_ptr<ErrorsProperty> p_errors{nullptr};
shared_ptr<SecretKeyProperty> p_secret_key{nullptr};
set<shared_ptr<DeviceProperty>> properties{nullptr};
private:
ESPPreferenceObject secret_pref_;
uint32_t pin_code_ = 0;
uint8_t request_counter_ = 0;
CommandQueue commands_;
};
} // namespace danfoss_eco
} // namespace esphome
#endif // USE_ESP32