ESPHome 2025.5.0
Loading...
Searching...
No Matches
bedjet_codec.h
Go to the documentation of this file.
1#pragma once
6#include "bedjet_const.h"
8namespace esphome {
9namespace bedjet {
12 uint8_t data_length;
14 uint8_t data[2];
15};
17enum BedjetPacketFormat : uint8_t {
20};
21
27enum BedjetNotification : uint8_t {
35 // Note: after handling a notification, send MAGIC_NOTIFY_ACK
36};
37
40 // [0]
41 bool is_partial : 8;
45 uint8_t expecting_length : 8;
47
48 // [4]
49 uint8_t time_remaining_hrs : 8;
50 uint8_t time_remaining_mins : 8;
51 uint8_t time_remaining_secs : 8;
53 // [7]
54 uint8_t actual_temp_step : 8;
56 uint8_t target_temp_step : 8;
57
58 // [9]
60
61 // [10]
62 uint8_t fan_step : 8;
64 uint8_t max_hrs : 8;
65 uint8_t max_mins : 8;
66 uint8_t min_temp_step : 8;
67 uint8_t max_temp_step : 8;
68
69 // [15-16]
70 uint16_t turbo_time : 16;
71
72 // [17]
73 uint8_t ambient_temp_step : 8;
75 uint8_t shutdown_reason : 8;
76
77 // [19-25]; the initial partial packet cuts off here after [19]
78
79 uint8_t unused_1 : 8; // Unknown [19] = 0x01
80 uint8_t unused_2 : 8; // Unknown [20] = 0x81
81 uint8_t unused_3 : 8; // Unknown [21] = 0x01
82
83 // [22]: 0x2=is_dual_zone, ...?
84 struct {
85 int unused_1 : 1; // 0x80
86 int unused_2 : 1; // 0x40
87 int unused_3 : 1; // 0x20
88 int unused_4 : 1; // 0x10
89 int unused_5 : 1; // 0x8
90 int unused_6 : 1; // 0x4
91 bool is_dual_zone : 1;
92 int unused_7 : 1; // 0x1
93 } dual_zone_flags; // NOLINT(clang-diagnostic-unaligned-access)
94
95 uint8_t unused_4 : 8; // Unknown 23-24 = 0x1310
96 uint8_t unused_5 : 8; // Unknown 23-24 = 0x1310
97 uint8_t unused_6 : 8; // Unknown 25 = 0x00
98
99 // [26]
100 // 0x18(24) = "Connection test has completed OK"
101 // 0x1a(26) = "Firmware update is not needed"
102 uint8_t update_phase : 8;
103
104 // [27]
105 union {
107 struct {
108 /* uint8_t */
109 int unused_1 : 1; // 0x80
110 int unused_2 : 1; // 0x40
112 bool leds_enabled : 1;
113 int unused_3 : 1; // 0x08
114 bool units_setup : 1;
115 int unused_4 : 1; // 0x02
116 bool beeps_muted : 1;
117 } __attribute__((packed)) flags;
118 };
119
120 // [28] = (biorhythm?) sequence step
121 uint8_t bio_sequence_step : 8;
122 // [29] = notify_code:
124
125 uint16_t unused_7 : 16; // Unknown
126
127} __attribute__((packed));
128
164 public:
168 BedjetPacket *get_set_time_request(uint8_t hour, uint8_t minute);
170
171 bool decode_notify(const uint8_t *data, uint16_t length);
172 void decode_extra(const uint8_t *data, uint16_t length);
173 bool compare(const uint8_t *data, uint16_t length);
174
175 inline bool has_status() { return this->status_packet_ != nullptr; }
176 const BedjetStatusPacket *get_status_packet() const { return this->status_packet_; }
177 void clear_status() { this->status_packet_ = nullptr; }
178
179 protected:
181
182 uint8_t last_buffer_size_ = 0;
183
185
189
191float bedjet_temp_to_c(uint8_t temp);
192
193} // namespace bedjet
194} // namespace esphome
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
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.
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
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