ESPHome 2026.1.4
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 char uuid_buf[espbt::UUID_STR_LEN];
197 ESP_LOGW(TAG, "Config descriptor 0x%x (uuid %s) is not a client config char uuid", this->char_handle_status_,
198 descr->uuid.to_str(uuid_buf));
199 result = false;
200 } else {
201 this->config_descr_status_ = descr->handle;
202 }
203 }
204
205 if (!this->char_handle_name_) {
206 chr = this->parent_->get_characteristic(BEDJET_SERVICE_UUID, BEDJET_NAME_UUID);
207 if (chr == nullptr) {
208 ESP_LOGW(TAG, "[%s] No name service found at device, not a BedJet..?", this->get_name().c_str());
209 result = false;
210 } else {
211 this->char_handle_name_ = chr->handle;
212 auto status = esp_ble_gattc_read_char(this->parent_->get_gattc_if(), this->parent_->get_conn_id(),
213 this->char_handle_name_, ESP_GATT_AUTH_REQ_NONE);
214 if (status) {
215 ESP_LOGI(TAG, "[%s] Unable to read name characteristic: %d", this->get_name().c_str(), status);
216 }
217 }
218 }
219
220 ESP_LOGI(TAG,
221 "[%s] Discovered service characteristics:\n"
222 " - Command char: 0x%x\n"
223 " - Status char: 0x%x\n"
224 " - config descriptor: 0x%x\n"
225 " - Name char: 0x%x",
226 this->get_name().c_str(), this->char_handle_cmd_, this->char_handle_status_, this->config_descr_status_,
227 this->char_handle_name_);
228
229 return result;
230}
231
232void BedJetHub::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
233 esp_ble_gattc_cb_param_t *param) {
234 switch (event) {
235 case ESP_GATTC_DISCONNECT_EVT: {
236 ESP_LOGV(TAG, "Disconnected: reason=%d", param->disconnect.reason);
237 this->status_set_warning();
238 this->dispatch_state_(false);
239 break;
240 }
241 case ESP_GATTC_SEARCH_CMPL_EVT: {
242 auto result = this->discover_characteristics_();
243
244 if (result) {
245 ESP_LOGD(TAG, "[%s] Services complete: obtained char handles.", this->get_name().c_str());
246 this->node_state = espbt::ClientState::ESTABLISHED;
247 this->set_notify_(true);
248
249#ifdef USE_TIME
250 if (this->time_id_ != nullptr) {
251 this->send_local_time();
252 }
253#endif
254
255 this->dispatch_state_(true);
256 } else {
257 ESP_LOGW(TAG, "[%s] Failed discovering service characteristics.", this->get_name().c_str());
258 this->parent()->set_enabled(false);
259 this->status_set_warning();
260 this->dispatch_state_(false);
261 }
262 break;
263 }
264 case ESP_GATTC_WRITE_DESCR_EVT: {
265 if (param->write.status != ESP_GATT_OK) {
266 if (param->write.status == ESP_GATT_INVALID_ATTR_LEN) {
267 // This probably means that our hack for notify_en (8 bit vs 16 bit) didn't work right.
268 // Should we try to fall back to BLEClient's way?
269 ESP_LOGW(TAG, "[%s] Invalid attr length writing descr at handle 0x%04d, status=%d", this->get_name().c_str(),
270 param->write.handle, param->write.status);
271 } else {
272 ESP_LOGW(TAG, "[%s] Error writing descr at handle 0x%04d, status=%d", this->get_name().c_str(),
273 param->write.handle, param->write.status);
274 }
275 break;
276 }
277 ESP_LOGD(TAG, "[%s] Write to handle 0x%04x status=%d", this->get_name().c_str(), param->write.handle,
278 param->write.status);
279 break;
280 }
281 case ESP_GATTC_WRITE_CHAR_EVT: {
282 if (param->write.status != ESP_GATT_OK) {
283 ESP_LOGW(TAG, "Error writing char at handle 0x%04d, status=%d", param->write.handle, param->write.status);
284 break;
285 }
286 if (param->write.handle == this->char_handle_cmd_) {
287 if (this->force_refresh_) {
288 // Command write was successful. Publish the pending state, hoping that notify will kick in.
289 // FIXME: better to wait until we know the status has changed
290 this->dispatch_status_();
291 }
292 }
293 break;
294 }
295 case ESP_GATTC_READ_CHAR_EVT: {
296 if (param->read.conn_id != this->parent_->get_conn_id())
297 break;
298 if (param->read.status != ESP_GATT_OK) {
299 ESP_LOGW(TAG, "Error reading char at handle %d, status=%d", param->read.handle, param->read.status);
300 break;
301 }
302
303 if (param->read.handle == this->char_handle_status_) {
304 // This is the additional packet that doesn't fit in the notify packet.
305 this->codec_->decode_extra(param->read.value, param->read.value_len);
306 this->status_packet_ready_();
307 } else if (param->read.handle == this->char_handle_name_) {
308 // The data should represent the name.
309 if (param->read.status == ESP_GATT_OK && param->read.value_len > 0) {
310 std::string bedjet_name(reinterpret_cast<char const *>(param->read.value), param->read.value_len);
311 ESP_LOGV(TAG, "[%s] Got BedJet name: '%s'", this->get_name().c_str(), bedjet_name.c_str());
312 this->set_name_(bedjet_name);
313 }
314 }
315 break;
316 }
317 case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
318 // This event means that ESP received the request to enable notifications on the client side. But we also have to
319 // tell the server that we want it to send notifications. Normally BLEClient parent would handle this
320 // automatically, but as soon as we set our status to Established, the parent is going to purge all the
321 // service/char/descriptor handles, and then get_config_descriptor() won't work anymore. There's no way to disable
322 // the BLEClient parent behavior, so our only option is to write the handle anyway, and hope a double-write
323 // doesn't break anything.
324
325 if (param->reg_for_notify.handle != this->char_handle_status_) {
326 ESP_LOGW(TAG, "[%s] Register for notify on unexpected handle 0x%04x, expecting 0x%04x",
327 this->get_name().c_str(), param->reg_for_notify.handle, this->char_handle_status_);
328 break;
329 }
330
332 this->last_notify_ = 0;
333 this->force_refresh_ = true;
334 break;
335 }
336 case ESP_GATTC_UNREG_FOR_NOTIFY_EVT: {
337 // This event is not handled by the parent BLEClient, so we need to do this either way.
338 if (param->unreg_for_notify.handle != this->char_handle_status_) {
339 ESP_LOGW(TAG, "[%s] Unregister for notify on unexpected handle 0x%04x, expecting 0x%04x",
340 this->get_name().c_str(), param->unreg_for_notify.handle, this->char_handle_status_);
341 break;
342 }
343
345 this->last_notify_ = 0;
346 // Now we wait until the next update() poll to re-register notify...
347 break;
348 }
349 case ESP_GATTC_NOTIFY_EVT: {
350 if (this->processing_)
351 break;
352
353 if (param->notify.conn_id != this->parent_->get_conn_id()) {
354 ESP_LOGW(TAG, "[%s] Received notify event for unexpected parent conn: expect %x, got %x",
355 this->get_name().c_str(), this->parent_->get_conn_id(), param->notify.conn_id);
356 // FIXME: bug in BLEClient holding wrong conn_id.
357 }
358
359 if (param->notify.handle != this->char_handle_status_) {
360 ESP_LOGW(TAG, "[%s] Unexpected notify handle, wanted %04X, got %04X", this->get_name().c_str(),
361 this->char_handle_status_, param->notify.handle);
362 break;
363 }
364
365 // FIXME: notify events come in every ~200-300 ms, which is too fast to be helpful. So we
366 // throttle the updates to once every MIN_NOTIFY_THROTTLE (5 seconds).
367 // Another idea would be to keep notify off by default, and use update() as an opportunity to turn on
368 // notify to get enough data to update status, then turn off notify again.
369
370 uint32_t now = millis();
371 auto delta = now - this->last_notify_;
372
373 if (!this->force_refresh_ && this->codec_->compare(param->notify.value, param->notify.value_len)) {
374 // If the packet is meaningfully different, trigger children as well
375 this->force_refresh_ = true;
376 ESP_LOGV(TAG, "[%s] Incoming packet indicates a significant change.", this->get_name().c_str());
377 }
378
379 if (this->last_notify_ == 0 || delta > MIN_NOTIFY_THROTTLE || this->force_refresh_) {
380 // Set reentrant flag to prevent processing multiple packets.
381 this->processing_ = true;
382 ESP_LOGVV(TAG, "[%s] Decoding packet: last=%" PRId32 ", delta=%" PRId32 ", force=%s", this->get_name().c_str(),
383 this->last_notify_, delta, this->force_refresh_ ? "y" : "n");
384 bool needs_extra = this->codec_->decode_notify(param->notify.value, param->notify.value_len);
385
386 if (needs_extra) {
387 // This means the packet was partial, so read the status characteristic to get the second part.
388 // Ideally this will complete quickly. We won't process additional notification events until it does.
389 auto status = esp_ble_gattc_read_char(this->parent_->get_gattc_if(), this->parent_->get_conn_id(),
390 this->char_handle_status_, ESP_GATT_AUTH_REQ_NONE);
391 if (status) {
392 ESP_LOGI(TAG, "[%s] Unable to read extended status packet", this->get_name().c_str());
393 }
394 } else {
395 this->status_packet_ready_();
396 }
397 }
398 break;
399 }
400 default:
401 ESP_LOGVV(TAG, "[%s] gattc unhandled event: enum=%d", this->get_name().c_str(), event);
402 break;
403 }
404}
405
407 this->last_notify_ = millis();
408 this->processing_ = false;
409
410 if (this->force_refresh_) {
411 // If we requested an immediate update, do that now.
412 this->update();
413 this->force_refresh_ = false;
414 }
415}
416
425 auto handle = this->config_descr_status_;
426 if (handle == 0) {
427 ESP_LOGW(TAG, "No descriptor found for notify of handle 0x%x", this->char_handle_status_);
428 return -1;
429 }
430
431 // NOTE: BLEClient uses `uint8_t*` of length 1, but BLE spec requires 16 bits.
432 uint16_t notify_en = enable ? 1 : 0;
433 auto status = esp_ble_gattc_write_char_descr(this->parent_->get_gattc_if(), this->parent_->get_conn_id(), handle,
434 sizeof(notify_en), (uint8_t *) &notify_en, ESP_GATT_WRITE_TYPE_RSP,
435 ESP_GATT_AUTH_REQ_NONE);
436 if (status) {
437 ESP_LOGW(TAG, "esp_ble_gattc_write_char_descr error, status=%d", status);
438 return status;
439 }
440 ESP_LOGD(TAG, "[%s] wrote notify=%s to status config 0x%04x, for conn %d", this->get_name().c_str(),
441 enable ? "true" : "false", handle, this->parent_->get_conn_id());
442 return ESP_GATT_OK;
443}
444
445/* Time Component */
446
447#ifdef USE_TIME
449 if (this->time_id_ != nullptr) {
450 ESPTime now = this->time_id_->now();
451 if (now.is_valid()) {
452 this->set_clock(now.hour, now.minute);
453 ESP_LOGD(TAG, "Using time component to set BedJet clock: %d:%02d", now.hour, now.minute);
454 }
455 } else {
456 ESP_LOGI(TAG, "`time_id` is not configured: will not sync BedJet clock.");
457 }
458}
459
461 if (this->time_id_ != nullptr) {
462 this->send_local_time();
463 this->time_id_->add_on_time_sync_callback([this] { this->send_local_time(); });
464 } else {
465 ESP_LOGI(TAG, "`time_id` is not configured: will not sync BedJet clock.");
466 }
467}
468#endif
469
470void BedJetHub::set_clock(uint8_t hour, uint8_t minute) {
471 if (!this->is_connected()) {
472 ESP_LOGV(TAG, "[%s] Not connected, cannot send time.", this->get_name().c_str());
473 return;
474 }
475
476 BedjetPacket *pkt = this->codec_->get_set_time_request(hour, minute);
477 auto status = this->write_bedjet_packet_(pkt);
478 if (status) {
479 ESP_LOGW(TAG, "Failed setting BedJet clock: %d", status);
480 } else {
481 ESP_LOGD(TAG, "[%s] BedJet clock set to: %d:%02d", this->get_name().c_str(), hour, minute);
482 }
483}
484
485/* Internal */
486
488 // Parent BLEClientNode has a loop() method, but this component uses
489 // polling via update() and BLE callbacks so loop isn't needed
490 this->disable_loop();
491}
493
495 ESP_LOGCONFIG(TAG,
496 "BedJet Hub '%s'\n"
497 " ble_client.app_id: %d\n"
498 " ble_client.conn_id: %d",
499 this->get_name().c_str(), this->parent()->app_id, this->parent()->get_conn_id());
500 LOG_UPDATE_INTERVAL(this);
501 ESP_LOGCONFIG(TAG, " Child components (%d):", this->children_.size());
502 for (auto *child : this->children_) {
503 ESP_LOGCONFIG(TAG, " - %s", child->describe().c_str());
504 }
505}
506
507void BedJetHub::dispatch_state_(bool is_ready) {
508 for (auto *child : this->children_) {
509 child->on_bedjet_state(is_ready);
510 }
511}
512
514 auto *status = this->codec_->get_status_packet();
515
516 if (!this->is_connected()) {
517 ESP_LOGD(TAG, "[%s] Not connected, will not send status.", this->get_name().c_str());
518 } else if (status != nullptr) {
519 ESP_LOGD(TAG, "[%s] Notifying %d children of latest status @%p.", this->get_name().c_str(), this->children_.size(),
520 status);
521 for (auto *child : this->children_) {
522 child->on_status(status);
523 }
524 } else {
525 uint32_t now = millis();
526 uint32_t diff = now - this->last_notify_;
527
528 if (this->last_notify_ == 0) {
529 // This means we're connected and haven't received a notification, so it likely means that the BedJet is off.
530 // However, it could also mean that it's running, but failing to send notifications.
531 // We can try to unregister for notifications now, and then re-register, hoping to clear it up...
532 // But how do we know for sure which state we're in, and how do we actually clear out the buggy state?
533
534 ESP_LOGI(TAG, "[%s] Still waiting for first GATT notify event.", this->get_name().c_str());
535 } else if (diff > NOTIFY_WARN_THRESHOLD) {
536 ESP_LOGW(TAG, "[%s] Last GATT notify was %" PRId32 " seconds ago.", this->get_name().c_str(), diff / 1000);
537 }
538
539 if (this->timeout_ > 0 && diff > this->timeout_ && this->parent()->enabled) {
540 ESP_LOGW(TAG, "[%s] Timed out after %" PRId32 " sec. Retrying", this->get_name().c_str(), this->timeout_);
541 // set_enabled(false) will only close the connection if state != IDLE.
542 this->parent()->set_state(espbt::ClientState::CONNECTING);
543 this->parent()->set_enabled(false);
544 this->parent()->set_enabled(true);
545 }
546 }
547}
548
550 this->children_.push_back(obj);
551 obj->set_parent(this);
552}
553
554} // namespace bedjet
555} // namespace esphome
556
557#endif
uint8_t status
Definition bl0942.h:8
void status_set_warning(const char *message=nullptr)
bool is_ready() const
void disable_loop()
Disable this component's loop.
void set_parent(T *parent)
Set the parent of this object.
Definition helpers.h:1254
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:25
A more user-friendly version of struct tm from time.h.
Definition time.h:16
uint8_t minute
minutes after the hour [0-59]
Definition time.h:25
uint8_t hour
hours since midnight [0-23]
Definition time.h:27
bool is_valid() const
Check if this ESPTime is valid (all fields in range and year is greater than 2018)
Definition time.h:73