ESPHome 2025.5.0
Loading...
Searching...
No Matches
bedjet_hub.cpp
Go to the documentation of this file.
1#ifdef USE_ESP32
2
3#include "bedjet_hub.h"
4#include "bedjet_child.h"
5#include "bedjet_const.h"
7#include <cinttypes>
8
9namespace esphome {
10namespace bedjet {
11
12static const LogString *bedjet_button_to_string(BedjetButton button) {
13 switch (button) {
14 case BTN_OFF:
15 return LOG_STR("OFF");
16 case BTN_COOL:
17 return LOG_STR("COOL");
18 case BTN_HEAT:
19 return LOG_STR("HEAT");
20 case BTN_EXTHT:
21 return LOG_STR("EXT HT");
22 case BTN_TURBO:
23 return LOG_STR("TURBO");
24 case BTN_DRY:
25 return LOG_STR("DRY");
26 case BTN_M1:
27 return LOG_STR("M1");
28 case BTN_M2:
29 return LOG_STR("M2");
30 case BTN_M3:
31 return LOG_STR("M3");
32 default:
33 return LOG_STR("unknown");
34 }
35}
36
37/* Public */
38
40 auto *pkt = this->codec_->get_button_request(MAGIC_UPDATE);
41 auto status = this->write_bedjet_packet_(pkt);
42
43 if (status) {
44 ESP_LOGW(TAG, "[%s] MAGIC_UPDATE button failed, status=%d", this->get_name().c_str(), status);
45 }
46}
47
52bool BedJetHub::button_dry() { return this->send_button(BTN_DRY); }
53bool BedJetHub::button_off() { return this->send_button(BTN_OFF); }
57
58bool BedJetHub::set_fan_index(uint8_t fan_speed_index) {
59 if (fan_speed_index > 19) {
60 ESP_LOGW(TAG, "Invalid fan speed index %d, expecting 0-19.", fan_speed_index);
61 return false;
62 }
63
64 auto *pkt = this->codec_->get_set_fan_speed_request(fan_speed_index);
65 auto status = this->write_bedjet_packet_(pkt);
66
67 if (status) {
68 ESP_LOGW(TAG, "[%s] writing fan speed failed, status=%d", this->get_name().c_str(), status);
69 }
70 return status == 0;
71}
72
74 auto *status = this->codec_->get_status_packet();
75 if (status != nullptr) {
76 return status->fan_step;
77 }
78 return 0;
79}
80
81bool BedJetHub::set_target_temp(float temp_c) {
82 auto *pkt = this->codec_->get_set_target_temp_request(temp_c);
83 auto status = this->write_bedjet_packet_(pkt);
84
85 if (status) {
86 ESP_LOGW(TAG, "[%s] writing target temp failed, status=%d", this->get_name().c_str(), status);
87 }
88 return status == 0;
89}
90
91bool BedJetHub::set_time_remaining(uint8_t hours, uint8_t mins) {
92 // FIXME: this may fail depending on current mode or other restrictions enforced by the unit.
93 auto *pkt = this->codec_->get_set_runtime_remaining_request(hours, mins);
94 auto status = this->write_bedjet_packet_(pkt);
95
96 if (status) {
97 ESP_LOGW(TAG, "[%s] writing remaining runtime failed, status=%d", this->get_name().c_str(), status);
98 }
99 return status == 0;
100}
101
103 auto *pkt = this->codec_->get_button_request(button);
104 auto status = this->write_bedjet_packet_(pkt);
105
106 if (status) {
107 ESP_LOGW(TAG, "[%s] writing button %s failed, status=%d", this->get_name().c_str(),
108 LOG_STR_ARG(bedjet_button_to_string(button)), status);
109 } else {
110 ESP_LOGD(TAG, "[%s] writing button %s success", this->get_name().c_str(),
111 LOG_STR_ARG(bedjet_button_to_string(button)));
112 }
113 return status == 0;
114}
115
117 auto *status = this->codec_->get_status_packet();
118 if (status != nullptr) {
119 return status->time_remaining_secs + status->time_remaining_mins * 60 + status->time_remaining_hrs * 3600;
120 }
121 return 0;
122}
123
124/* Bluetooth/GATT */
125
127 if (!this->is_connected()) {
128 if (!this->parent_->enabled) {
129 ESP_LOGI(TAG, "[%s] Cannot write packet: Not connected, enabled=false", this->get_name().c_str());
130 } else {
131 ESP_LOGW(TAG, "[%s] Cannot write packet: Not connected", this->get_name().c_str());
132 }
133 return -1;
134 }
135 auto status = esp_ble_gattc_write_char(this->parent_->get_gattc_if(), this->parent_->get_conn_id(),
136 this->char_handle_cmd_, pkt->data_length + 1, (uint8_t *) &pkt->command,
137 ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
138 return status;
139}
140
142uint8_t BedJetHub::set_notify_(const bool enable) {
143 uint8_t status;
144 if (enable) {
145 status = esp_ble_gattc_register_for_notify(this->parent_->get_gattc_if(), this->parent_->get_remote_bda(),
146 this->char_handle_status_);
147 if (status) {
148 ESP_LOGW(TAG, "[%s] esp_ble_gattc_register_for_notify failed, status=%d", this->get_name().c_str(), status);
149 }
150 } else {
151 status = esp_ble_gattc_unregister_for_notify(this->parent_->get_gattc_if(), this->parent_->get_remote_bda(),
152 this->char_handle_status_);
153 if (status) {
154 ESP_LOGW(TAG, "[%s] esp_ble_gattc_unregister_for_notify failed, status=%d", this->get_name().c_str(), status);
155 }
156 }
157 ESP_LOGV(TAG, "[%s] set_notify: enable=%d; result=%d", this->get_name().c_str(), enable, status);
158 return status;
159}
160
162 bool result = true;
164
165 if (!this->char_handle_cmd_) {
166 chr = this->parent_->get_characteristic(BEDJET_SERVICE_UUID, BEDJET_COMMAND_UUID);
167 if (chr == nullptr) {
168 ESP_LOGW(TAG, "[%s] No control service found at device, not a BedJet..?", this->get_name().c_str());
169 result = false;
170 } else {
171 this->char_handle_cmd_ = chr->handle;
172 }
173 }
174
175 if (!this->char_handle_status_) {
176 chr = this->parent_->get_characteristic(BEDJET_SERVICE_UUID, BEDJET_STATUS_UUID);
177 if (chr == nullptr) {
178 ESP_LOGW(TAG, "[%s] No status service found at device, not a BedJet..?", this->get_name().c_str());
179 result = false;
180 } else {
181 this->char_handle_status_ = chr->handle;
182 }
183 }
184
185 if (!this->config_descr_status_) {
186 // We also need to obtain the config descriptor for this handle.
187 // Otherwise once we set node_state=Established, the parent will flush all handles/descriptors, and we won't be
188 // able to look it up.
189 auto *descr = this->parent_->get_config_descriptor(this->char_handle_status_);
190 if (descr == nullptr) {
191 ESP_LOGW(TAG, "No config descriptor for status handle 0x%x. Will not be able to receive status notifications",
192 this->char_handle_status_);
193 result = false;
194 } else if (descr->uuid.get_uuid().len != ESP_UUID_LEN_16 ||
195 descr->uuid.get_uuid().uuid.uuid16 != ESP_GATT_UUID_CHAR_CLIENT_CONFIG) {
196 ESP_LOGW(TAG, "Config descriptor 0x%x (uuid %s) is not a client config char uuid", this->char_handle_status_,
197 descr->uuid.to_string().c_str());
198 result = false;
199 } else {
200 this->config_descr_status_ = descr->handle;
201 }
202 }
203
204 if (!this->char_handle_name_) {
205 chr = this->parent_->get_characteristic(BEDJET_SERVICE_UUID, BEDJET_NAME_UUID);
206 if (chr == nullptr) {
207 ESP_LOGW(TAG, "[%s] No name service found at device, not a BedJet..?", this->get_name().c_str());
208 result = false;
209 } else {
210 this->char_handle_name_ = chr->handle;
211 auto status = esp_ble_gattc_read_char(this->parent_->get_gattc_if(), this->parent_->get_conn_id(),
212 this->char_handle_name_, ESP_GATT_AUTH_REQ_NONE);
213 if (status) {
214 ESP_LOGI(TAG, "[%s] Unable to read name characteristic: %d", this->get_name().c_str(), status);
215 }
216 }
217 }
218
219 ESP_LOGI(TAG, "[%s] Discovered service characteristics: ", this->get_name().c_str());
220 ESP_LOGI(TAG, " - Command char: 0x%x", this->char_handle_cmd_);
221 ESP_LOGI(TAG, " - Status char: 0x%x", this->char_handle_status_);
222 ESP_LOGI(TAG, " - config descriptor: 0x%x", this->config_descr_status_);
223 ESP_LOGI(TAG, " - Name char: 0x%x", this->char_handle_name_);
224
225 return result;
226}
227
228void BedJetHub::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
229 esp_ble_gattc_cb_param_t *param) {
230 switch (event) {
231 case ESP_GATTC_DISCONNECT_EVT: {
232 ESP_LOGV(TAG, "Disconnected: reason=%d", param->disconnect.reason);
233 this->status_set_warning();
234 this->dispatch_state_(false);
235 break;
236 }
237 case ESP_GATTC_SEARCH_CMPL_EVT: {
238 auto result = this->discover_characteristics_();
239
240 if (result) {
241 ESP_LOGD(TAG, "[%s] Services complete: obtained char handles.", this->get_name().c_str());
242 this->node_state = espbt::ClientState::ESTABLISHED;
243 this->set_notify_(true);
244
245#ifdef USE_TIME
246 if (this->time_id_ != nullptr) {
247 this->send_local_time();
248 }
249#endif
250
251 this->dispatch_state_(true);
252 } else {
253 ESP_LOGW(TAG, "[%s] Failed discovering service characteristics.", this->get_name().c_str());
254 this->parent()->set_enabled(false);
255 this->status_set_warning();
256 this->dispatch_state_(false);
257 }
258 break;
259 }
260 case ESP_GATTC_WRITE_DESCR_EVT: {
261 if (param->write.status != ESP_GATT_OK) {
262 if (param->write.status == ESP_GATT_INVALID_ATTR_LEN) {
263 // This probably means that our hack for notify_en (8 bit vs 16 bit) didn't work right.
264 // Should we try to fall back to BLEClient's way?
265 ESP_LOGW(TAG, "[%s] Invalid attr length writing descr at handle 0x%04d, status=%d", this->get_name().c_str(),
266 param->write.handle, param->write.status);
267 } else {
268 ESP_LOGW(TAG, "[%s] Error writing descr at handle 0x%04d, status=%d", this->get_name().c_str(),
269 param->write.handle, param->write.status);
270 }
271 break;
272 }
273 ESP_LOGD(TAG, "[%s] Write to handle 0x%04x status=%d", this->get_name().c_str(), param->write.handle,
274 param->write.status);
275 break;
276 }
277 case ESP_GATTC_WRITE_CHAR_EVT: {
278 if (param->write.status != ESP_GATT_OK) {
279 ESP_LOGW(TAG, "Error writing char at handle 0x%04d, status=%d", param->write.handle, param->write.status);
280 break;
281 }
282 if (param->write.handle == this->char_handle_cmd_) {
283 if (this->force_refresh_) {
284 // Command write was successful. Publish the pending state, hoping that notify will kick in.
285 // FIXME: better to wait until we know the status has changed
286 this->dispatch_status_();
287 }
288 }
289 break;
290 }
291 case ESP_GATTC_READ_CHAR_EVT: {
292 if (param->read.conn_id != this->parent_->get_conn_id())
293 break;
294 if (param->read.status != ESP_GATT_OK) {
295 ESP_LOGW(TAG, "Error reading char at handle %d, status=%d", param->read.handle, param->read.status);
296 break;
297 }
298
299 if (param->read.handle == this->char_handle_status_) {
300 // This is the additional packet that doesn't fit in the notify packet.
301 this->codec_->decode_extra(param->read.value, param->read.value_len);
302 this->status_packet_ready_();
303 } else if (param->read.handle == this->char_handle_name_) {
304 // The data should represent the name.
305 if (param->read.status == ESP_GATT_OK && param->read.value_len > 0) {
306 std::string bedjet_name(reinterpret_cast<char const *>(param->read.value), param->read.value_len);
307 ESP_LOGV(TAG, "[%s] Got BedJet name: '%s'", this->get_name().c_str(), bedjet_name.c_str());
308 this->set_name_(bedjet_name);
309 }
310 }
311 break;
312 }
313 case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
314 // This event means that ESP received the request to enable notifications on the client side. But we also have to
315 // tell the server that we want it to send notifications. Normally BLEClient parent would handle this
316 // automatically, but as soon as we set our status to Established, the parent is going to purge all the
317 // service/char/descriptor handles, and then get_config_descriptor() won't work anymore. There's no way to disable
318 // the BLEClient parent behavior, so our only option is to write the handle anyway, and hope a double-write
319 // doesn't break anything.
320
321 if (param->reg_for_notify.handle != this->char_handle_status_) {
322 ESP_LOGW(TAG, "[%s] Register for notify on unexpected handle 0x%04x, expecting 0x%04x",
323 this->get_name().c_str(), param->reg_for_notify.handle, this->char_handle_status_);
324 break;
325 }
326
328 this->last_notify_ = 0;
329 this->force_refresh_ = true;
330 break;
331 }
332 case ESP_GATTC_UNREG_FOR_NOTIFY_EVT: {
333 // This event is not handled by the parent BLEClient, so we need to do this either way.
334 if (param->unreg_for_notify.handle != this->char_handle_status_) {
335 ESP_LOGW(TAG, "[%s] Unregister for notify on unexpected handle 0x%04x, expecting 0x%04x",
336 this->get_name().c_str(), param->unreg_for_notify.handle, this->char_handle_status_);
337 break;
338 }
339
341 this->last_notify_ = 0;
342 // Now we wait until the next update() poll to re-register notify...
343 break;
344 }
345 case ESP_GATTC_NOTIFY_EVT: {
346 if (this->processing_)
347 break;
348
349 if (param->notify.conn_id != this->parent_->get_conn_id()) {
350 ESP_LOGW(TAG, "[%s] Received notify event for unexpected parent conn: expect %x, got %x",
351 this->get_name().c_str(), this->parent_->get_conn_id(), param->notify.conn_id);
352 // FIXME: bug in BLEClient holding wrong conn_id.
353 }
354
355 if (param->notify.handle != this->char_handle_status_) {
356 ESP_LOGW(TAG, "[%s] Unexpected notify handle, wanted %04X, got %04X", this->get_name().c_str(),
357 this->char_handle_status_, param->notify.handle);
358 break;
359 }
360
361 // FIXME: notify events come in every ~200-300 ms, which is too fast to be helpful. So we
362 // throttle the updates to once every MIN_NOTIFY_THROTTLE (5 seconds).
363 // Another idea would be to keep notify off by default, and use update() as an opportunity to turn on
364 // notify to get enough data to update status, then turn off notify again.
365
366 uint32_t now = millis();
367 auto delta = now - this->last_notify_;
368
369 if (!this->force_refresh_ && this->codec_->compare(param->notify.value, param->notify.value_len)) {
370 // If the packet is meaningfully different, trigger children as well
371 this->force_refresh_ = true;
372 ESP_LOGV(TAG, "[%s] Incoming packet indicates a significant change.", this->get_name().c_str());
373 }
374
375 if (this->last_notify_ == 0 || delta > MIN_NOTIFY_THROTTLE || this->force_refresh_) {
376 // Set reentrant flag to prevent processing multiple packets.
377 this->processing_ = true;
378 ESP_LOGVV(TAG, "[%s] Decoding packet: last=%" PRId32 ", delta=%" PRId32 ", force=%s", this->get_name().c_str(),
379 this->last_notify_, delta, this->force_refresh_ ? "y" : "n");
380 bool needs_extra = this->codec_->decode_notify(param->notify.value, param->notify.value_len);
381
382 if (needs_extra) {
383 // This means the packet was partial, so read the status characteristic to get the second part.
384 // Ideally this will complete quickly. We won't process additional notification events until it does.
385 auto status = esp_ble_gattc_read_char(this->parent_->get_gattc_if(), this->parent_->get_conn_id(),
386 this->char_handle_status_, ESP_GATT_AUTH_REQ_NONE);
387 if (status) {
388 ESP_LOGI(TAG, "[%s] Unable to read extended status packet", this->get_name().c_str());
389 }
390 } else {
391 this->status_packet_ready_();
392 }
393 }
394 break;
395 }
396 default:
397 ESP_LOGVV(TAG, "[%s] gattc unhandled event: enum=%d", this->get_name().c_str(), event);
398 break;
399 }
400}
401
403 this->last_notify_ = millis();
404 this->processing_ = false;
405
406 if (this->force_refresh_) {
407 // If we requested an immediate update, do that now.
408 this->update();
409 this->force_refresh_ = false;
410 }
411}
412
421 auto handle = this->config_descr_status_;
422 if (handle == 0) {
423 ESP_LOGW(TAG, "No descriptor found for notify of handle 0x%x", this->char_handle_status_);
424 return -1;
425 }
426
427 // NOTE: BLEClient uses `uint8_t*` of length 1, but BLE spec requires 16 bits.
428 uint16_t notify_en = enable ? 1 : 0;
429 auto status = esp_ble_gattc_write_char_descr(this->parent_->get_gattc_if(), this->parent_->get_conn_id(), handle,
430 sizeof(notify_en), (uint8_t *) &notify_en, ESP_GATT_WRITE_TYPE_RSP,
431 ESP_GATT_AUTH_REQ_NONE);
432 if (status) {
433 ESP_LOGW(TAG, "esp_ble_gattc_write_char_descr error, status=%d", status);
434 return status;
435 }
436 ESP_LOGD(TAG, "[%s] wrote notify=%s to status config 0x%04x, for conn %d", this->get_name().c_str(),
437 enable ? "true" : "false", handle, this->parent_->get_conn_id());
438 return ESP_GATT_OK;
439}
440
441/* Time Component */
442
443#ifdef USE_TIME
445 if (this->time_id_ != nullptr) {
446 ESPTime now = this->time_id_->now();
447 if (now.is_valid()) {
448 this->set_clock(now.hour, now.minute);
449 ESP_LOGD(TAG, "Using time component to set BedJet clock: %d:%02d", now.hour, now.minute);
450 }
451 } else {
452 ESP_LOGI(TAG, "`time_id` is not configured: will not sync BedJet clock.");
453 }
454}
455
457 if (this->time_id_ != nullptr) {
458 this->send_local_time();
459 this->time_id_->add_on_time_sync_callback([this] { this->send_local_time(); });
460 } else {
461 ESP_LOGI(TAG, "`time_id` is not configured: will not sync BedJet clock.");
462 }
463}
464#endif
465
466void BedJetHub::set_clock(uint8_t hour, uint8_t minute) {
467 if (!this->is_connected()) {
468 ESP_LOGV(TAG, "[%s] Not connected, cannot send time.", this->get_name().c_str());
469 return;
470 }
471
472 BedjetPacket *pkt = this->codec_->get_set_time_request(hour, minute);
473 auto status = this->write_bedjet_packet_(pkt);
474 if (status) {
475 ESP_LOGW(TAG, "Failed setting BedJet clock: %d", status);
476 } else {
477 ESP_LOGD(TAG, "[%s] BedJet clock set to: %d:%02d", this->get_name().c_str(), hour, minute);
478 }
479}
480
481/* Internal */
482
485
487 ESP_LOGCONFIG(TAG, "BedJet Hub '%s'", this->get_name().c_str());
488 ESP_LOGCONFIG(TAG, " ble_client.app_id: %d", this->parent()->app_id);
489 ESP_LOGCONFIG(TAG, " ble_client.conn_id: %d", this->parent()->get_conn_id());
490 LOG_UPDATE_INTERVAL(this)
491 ESP_LOGCONFIG(TAG, " Child components (%d):", this->children_.size());
492 for (auto *child : this->children_) {
493 ESP_LOGCONFIG(TAG, " - %s", child->describe().c_str());
494 }
495}
496
497void BedJetHub::dispatch_state_(bool is_ready) {
498 for (auto *child : this->children_) {
499 child->on_bedjet_state(is_ready);
500 }
501}
502
504 auto *status = this->codec_->get_status_packet();
505
506 if (!this->is_connected()) {
507 ESP_LOGD(TAG, "[%s] Not connected, will not send status.", this->get_name().c_str());
508 } else if (status != nullptr) {
509 ESP_LOGD(TAG, "[%s] Notifying %d children of latest status @%p.", this->get_name().c_str(), this->children_.size(),
510 status);
511 for (auto *child : this->children_) {
512 child->on_status(status);
513 }
514 } else {
515 uint32_t now = millis();
516 uint32_t diff = now - this->last_notify_;
517
518 if (this->last_notify_ == 0) {
519 // This means we're connected and haven't received a notification, so it likely means that the BedJet is off.
520 // However, it could also mean that it's running, but failing to send notifications.
521 // We can try to unregister for notifications now, and then re-register, hoping to clear it up...
522 // But how do we know for sure which state we're in, and how do we actually clear out the buggy state?
523
524 ESP_LOGI(TAG, "[%s] Still waiting for first GATT notify event.", this->get_name().c_str());
525 } else if (diff > NOTIFY_WARN_THRESHOLD) {
526 ESP_LOGW(TAG, "[%s] Last GATT notify was %" PRId32 " seconds ago.", this->get_name().c_str(), diff / 1000);
527 }
528
529 if (this->timeout_ > 0 && diff > this->timeout_ && this->parent()->enabled) {
530 ESP_LOGW(TAG, "[%s] Timed out after %" PRId32 " sec. Retrying...", this->get_name().c_str(), this->timeout_);
531 // set_enabled(false) will only close the connection if state != IDLE.
532 this->parent()->set_state(espbt::ClientState::CONNECTING);
533 this->parent()->set_enabled(false);
534 this->parent()->set_enabled(true);
535 }
536 }
537}
538
540 this->children_.push_back(obj);
541 obj->set_parent(this);
542}
543
544} // namespace bedjet
545} // namespace esphome
546
547#endif
uint8_t status
Definition bl0942.h:8
bool is_ready() const
void status_set_warning(const char *message="unspecified")
void set_parent(T *parent)
Set the parent of this object.
Definition helpers.h:546
bool set_target_temp(float temp_c)
Set the target temperature to temp_c in °C.
void set_name_(const std::string &name)
Definition bedjet_hub.h:155
void dump_config() override
bool button_cool()
Press the COOL button.
void setup_time_()
Initializes time sync callbacks to support syncing current time to the BedJet.
bool button_dry()
Press the DRY button.
uint8_t write_bedjet_packet_(BedjetPacket *pkt)
Send the BedjetPacket to the device.
bool button_ext_heat()
Press the EXT HT button.
uint8_t get_fan_index()
Return the fan speed index, in the range 0-19.
std::unique_ptr< BedjetCodec > codec_
Definition bedjet_hub.h:164
void set_clock(uint8_t hour, uint8_t minute)
Attempt to set the BedJet device's clock to the specified time.
static const uint32_t MIN_NOTIFY_THROTTLE
Definition bedjet_hub.h:148
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
time::RealTimeClock * time_id_
Definition bedjet_hub.h:144
bool set_fan_index(uint8_t fan_speed_index)
Set the fan speed to a stepped index in the range 0-19.
uint16_t get_time_remaining()
Return the remaining runtime, in seconds.
bool set_time_remaining(uint8_t hours, uint8_t mins)
Set the operational runtime remaining.
void upgrade_firmware()
Attempts to check for and apply firmware updates.
void dispatch_state_(bool is_ready)
bool button_memory1()
Press the M1 (memory recall) button.
uint8_t set_notify_(bool enable)
Configures the local ESP BLE client to register (true) or unregister (false) for status notifications...
std::vector< BedJetClient * > children_
Definition bedjet_hub.h:137
bool button_turbo()
Press the TURBO button.
bool button_heat()
Press the HEAT button.
void register_child(BedJetClient *obj)
Register a BedJetClient child component.
bool send_button(BedjetButton button)
Send the button.
uint8_t write_notify_config_descriptor_(bool enable)
Reimplementation of BLEClient.gattc_event_handler() for ESP_GATTC_REG_FOR_NOTIFY_EVT.
bool button_memory3()
Press the M3 (memory recall) button.
bool button_off()
Press the OFF button.
static const uint32_t NOTIFY_WARN_THRESHOLD
Definition bedjet_hub.h:149
void send_local_time()
Attempts to sync the local time (via time_id) to the BedJet device.
bool button_memory2()
Press the M2 (memory recall) button.
void set_state(espbt::ClientState state) override
void set_enabled(bool enabled)
BLECharacteristic * get_characteristic(espbt::ESPBTUUID service, espbt::ESPBTUUID chr)
BLEDescriptor * get_config_descriptor(uint16_t handle)
void add_on_time_sync_callback(std::function< void()> callback)
ESPTime now()
Get the time in the currently defined timezone.
uint8_t minute
uint8_t hour
@ BTN_TURBO
Enter Turbo mode (high heat, limited to 10 minutes)
@ BTN_M1
Start the M1 biorhythm/preset program.
@ BTN_DRY
Enter Dry mode (high speed, no heat)
@ BTN_EXTHT
Enter Extended Heat mode (limited to 10 hours)
@ BTN_HEAT
Enter Heat mode (limited to 4 hours)
@ BTN_COOL
Enter Cool mode (fan only)
@ BTN_OFF
Turn BedJet off.
@ BTN_M2
Start the M2 biorhythm/preset program.
@ BTN_M3
Start the M3 biorhythm/preset program.
@ MAGIC_UPDATE
Request a firmware update. This will also restart the Bedjet.
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint32_t IRAM_ATTR HOT millis()
Definition core.cpp:27
A more user-friendly version of struct tm from time.h.
Definition time.h:15
uint8_t minute
minutes after the hour [0-59]
Definition time.h:21
uint8_t hour
hours since midnight [0-23]
Definition time.h:23
bool is_valid() const
Check if this ESPTime is valid (all fields in range and year is greater than 2018)
Definition time.h:59