ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
bedjet_codec.h
Go to the documentation of this file.
1#pragma once
6#include "bedjet_const.h"
8namespace esphome::bedjet {
11 uint8_t data_length;
13 uint8_t data[2];
14};
15
16enum BedjetPacketFormat : uint8_t {
19};
20
26enum BedjetNotification : uint8_t {
34 // Note: after handling a notification, send MAGIC_NOTIFY_ACK
35};
36
39 // [0]
40 bool is_partial : 8;
44 uint8_t expecting_length : 8;
46
47 // [4]
48 uint8_t time_remaining_hrs : 8;
49 uint8_t time_remaining_mins : 8;
50 uint8_t time_remaining_secs : 8;
52 // [7]
53 uint8_t actual_temp_step : 8;
55 uint8_t target_temp_step : 8;
56
57 // [9]
59
60 // [10]
61 uint8_t fan_step : 8;
63 uint8_t max_hrs : 8;
64 uint8_t max_mins : 8;
65 uint8_t min_temp_step : 8;
66 uint8_t max_temp_step : 8;
67
68 // [15-16]
69 uint16_t turbo_time : 16;
70
71 // [17]
72 uint8_t ambient_temp_step : 8;
74 uint8_t shutdown_reason : 8;
75
76 // [19-25]; the initial partial packet cuts off here after [19]
77
78 uint8_t unused_1 : 8; // Unknown [19] = 0x01
79 uint8_t unused_2 : 8; // Unknown [20] = 0x81
80 uint8_t unused_3 : 8; // Unknown [21] = 0x01
82 // [22]: 0x2=is_dual_zone, ...?
83 struct {
84 int unused_1 : 1; // 0x80
85 int unused_2 : 1; // 0x40
86 int unused_3 : 1; // 0x20
87 int unused_4 : 1; // 0x10
88 int unused_5 : 1; // 0x8
89 int unused_6 : 1; // 0x4
90 bool is_dual_zone : 1;
91 int unused_7 : 1; // 0x1
92 } dual_zone_flags; // NOLINT(clang-diagnostic-unaligned-access)
93
94 uint8_t unused_4 : 8; // Unknown 23-24 = 0x1310
95 uint8_t unused_5 : 8; // Unknown 23-24 = 0x1310
96 uint8_t unused_6 : 8; // Unknown 25 = 0x00
97
98 // [26]
99 // 0x18(24) = "Connection test has completed OK"
100 // 0x1a(26) = "Firmware update is not needed"
101 uint8_t update_phase : 8;
102
103 // [27]
104 union {
106 struct {
107 /* uint8_t */
108 int unused_1 : 1; // 0x80
109 int unused_2 : 1; // 0x40
111 bool leds_enabled : 1;
112 int unused_3 : 1; // 0x08
113 bool units_setup : 1;
114 int unused_4 : 1; // 0x02
115 bool beeps_muted : 1;
116 } __attribute__((packed)) flags;
117 };
118
119 // [28] = (biorhythm?) sequence step
120 uint8_t bio_sequence_step : 8;
121 // [29] = notify_code:
123
124 uint16_t unused_7 : 16; // Unknown
125
126} __attribute__((packed));
127
163 public:
167 BedjetPacket *get_set_time_request(uint8_t hour, uint8_t minute);
169
170 bool decode_notify(const uint8_t *data, uint16_t length);
171 void decode_extra(const uint8_t *data, uint16_t length);
172 bool compare(const uint8_t *data, uint16_t length);
173
174 inline bool has_status() { return this->status_packet_ != nullptr; }
175 const BedjetStatusPacket *get_status_packet() const { return this->status_packet_; }
176 void clear_status() { this->status_packet_ = nullptr; }
177
178 protected:
180
181 uint8_t last_buffer_size_ = 0;
182
184
188
190float bedjet_temp_to_c(uint8_t temp);
191
192} // namespace esphome::bedjet
uint8_t fan_step
BedJet fan speed; value is in the 0-19 range, representing 5% increments (5%-100%): 5 + 5 /< * fan_st...
This class is responsible for encoding command packets and decoding status packets.
BedjetPacket * get_set_target_temp_request(float temperature)
Returns a BedjetPacket that will set the device's target temperature.
bool compare(const uint8_t *data, uint16_t length)
void decode_extra(const uint8_t *data, uint16_t length)
Decodes the extra bytes that were received after being notified with a partial packet.
BedjetPacket * clean_packet_()
Cleans up the packet before sending.
BedjetStatusPacket * status_packet_
bool decode_notify(const uint8_t *data, uint16_t length)
Decodes the incoming status packet received on the BEDJET_STATUS_UUID.
const BedjetStatusPacket * get_status_packet() const
BedjetPacket * get_set_runtime_remaining_request(uint8_t hour, uint8_t minute)
Returns a BedjetPacket that will set the device's remaining runtime.
BedjetPacket * get_button_request(BedjetButton button)
Returns a BedjetPacket that will initiate a BedjetButton press.
BedjetPacket * get_set_time_request(uint8_t hour, uint8_t minute)
Returns a BedjetPacket that will set the device's current time.
BedjetPacket * get_set_fan_speed_request(uint8_t fan_step)
Returns a BedjetPacket that will set the device's target fan speed.
uint8_t minute
uint8_t hour
uint16_t flags
float bedjet_temp_to_c(uint8_t temp)
Converts a BedJet temp step into degrees Celsius.
class esphome::bedjet::BedjetCodec __attribute__
@ NOTIFY_FILTER
Clean Filter / Please check BedJet air filter and clean if necessary.
@ NOTIFY_BIO_FAIL_TOO_LONG
The specified sequence cannot be run because it contains steps that would be too long running from th...
@ NOTIFY_NONE
No notification pending.
@ NOTIFY_UPDATE_FAIL
Firmware Update / Unable to connect to the firmware update server.
@ NOTIFY_BIO_FAIL_CLOCK_NOT_SET
The specified sequence cannot be run because the clock is not set.
@ NOTIFY_UPDATE
Firmware Update / A newer version of firmware is available.
The format of a BedJet V3 status packet.
uint8_t target_temp_step
Target temp that the BedJet will try to heat to. See actual_temp_step.
uint8_t time_remaining_mins
Minutes remaining in program runtime.
uint8_t actual_temp_step
Actual temp of the air blown by the BedJet fan; value represents 2 * /< degrees_celsius.
uint16_t unused_7
See BedjetNotification.
uint8_t time_remaining_secs
Seconds remaining in program runtime.
uint8_t max_temp_step
Max temp allowed in mode. See actual_temp_step.
uint8_t update_phase
The current status/phase of a firmware update.
uint8_t fan_step
BedJet fan speed; value is in the 0-19 range, representing 5% increments (5%-100%): 5 + 5 /< * fan_st...
uint16_t turbo_time
Time remaining in BedjetMode::MODE_TURBO.
bool units_setup
(0x04) Bit is set 1 if the device's units have been configured.
int unused_7
Is part of a Dual Zone configuration.
bool is_partial
1 indicates that this is a partial packet, and more data can be read directly from the characteristic...
bool conn_test_passed
(0x20) Bit is set 1 if the last connection test passed.
uint8_t min_temp_step
Min temp allowed in mode. See actual_temp_step.
uint8_t max_mins
Max minutes of mode runtime.
uint8_t max_hrs
Max hours of mode runtime.
BedjetMode mode
BedJet operating mode.
uint8_t time_remaining_hrs
Hours remaining in program runtime.
struct esphome::bedjet::BedjetStatusPacket::@5 dual_zone_flags
BedjetPacketFormat packet_format
BedjetPacketFormat::PACKET_FORMAT_V3_HOME for BedJet V3 status packet format.
bool leds_enabled
(0x10) Bit is set 1 if the LEDs on the device are enabled.
uint8_t ambient_temp_step
Current ambient air temp.
BedjetNotification notify_code
Biorhythm sequence step number.
uint8_t shutdown_reason
The reason for the last device shutdown.
BedjetPacketType packet_type
Typically BedjetPacketType::PACKET_TYPE_STATUS for BedJet V3 status packet.
uint8_t expecting_length
The expected total length of the status packet after merging the extra packet.
bool beeps_muted
(0x01) Bit is set 1 if the device's sound output is muted.
uint16_t temperature
Definition sun_gtil2.cpp:12
uint16_t length
Definition tt21100.cpp:0