17 static const std::string *bedjet_fan_step_to_fan_mode(
const uint8_t
fan_step) {
18 if (fan_step < BEDJET_FAN_SPEED_COUNT)
19 return &BEDJET_FAN_STEP_NAME_STRINGS[
fan_step];
23 static uint8_t bedjet_fan_speed_to_step(
const std::string &fan_step_percent) {
24 for (
int i = 0; i < BEDJET_FAN_SPEED_COUNT; i++) {
25 if (fan_step_percent == BEDJET_FAN_STEP_NAME_STRINGS[i]) {
39 LOG_CLIMATE(
"",
"BedJet Climate",
this);
40 auto traits = this->get_traits();
42 ESP_LOGCONFIG(TAG,
" Supported modes:");
43 for (
auto mode : traits.get_supported_modes()) {
47 ESP_LOGCONFIG(TAG,
" - BedJet heating mode: EXT HT");
49 ESP_LOGCONFIG(TAG,
" - BedJet heating mode: HEAT");
52 ESP_LOGCONFIG(TAG,
" Supported fan modes:");
53 for (
const auto &mode : traits.get_supported_fan_modes()) {
56 for (
const auto &mode : traits.get_supported_custom_fan_modes()) {
57 ESP_LOGCONFIG(TAG,
" - %s (c)", mode.c_str());
60 ESP_LOGCONFIG(TAG,
" Supported presets:");
61 for (
auto preset : traits.get_supported_presets()) {
64 for (
const auto &
preset : traits.get_supported_custom_presets()) {
65 ESP_LOGCONFIG(TAG,
" - %s (c)",
preset.c_str());
71 auto restore = this->restore_state_();
72 if (restore.has_value()) {
73 ESP_LOGI(TAG,
"Restored previous saved state.");
86 this->current_temperature = NAN;
89 this->publish_state();
95 ESP_LOGD(TAG,
"Received BedJetClimate::control");
96 if (!this->parent_->is_connected()) {
97 ESP_LOGW(TAG,
"Not connected, cannot handle control call yet.");
106 button_result = this->parent_->button_off();
109 button_result = this->parent_->send_button(heat_button(this->heating_mode_));
112 button_result = this->parent_->button_cool();
115 button_result = this->parent_->button_dry();
118 ESP_LOGW(TAG,
"Unsupported mode: %d", mode);
132 auto result = this->parent_->set_target_temp(target_temp);
145 result = this->parent_->button_turbo();
155 result = this->parent_->send_button(heat_button(this->heating_mode_));
157 this->preset.reset();
161 ESP_LOGD(TAG,
"Ignoring preset '%s' call; with current mode '%s' and preset '%s'",
166 ESP_LOGW(TAG,
"Unsupported preset: %d", preset);
173 if (preset ==
"M1") {
174 result = this->parent_->button_memory1();
175 }
else if (preset ==
"M2") {
176 result = this->parent_->button_memory2();
177 }
else if (preset ==
"M3") {
178 result = this->parent_->button_memory3();
179 }
else if (preset ==
"LTD HT") {
180 result = this->parent_->button_heat();
181 }
else if (preset ==
"EXT HT") {
182 result = this->parent_->button_ext_heat();
184 ESP_LOGW(TAG,
"Unsupported preset: %s", preset.c_str());
190 this->preset.reset();
200 result = this->parent_->set_fan_speed(20);
202 result = this->parent_->set_fan_speed(50);
204 result = this->parent_->set_fan_speed(75);
206 ESP_LOGW(TAG,
"[%s] Unsupported fan mode: %s", this->get_name().c_str(),
217 auto fan_index = bedjet_fan_speed_to_step(
fan_mode);
218 if (fan_index <= 19) {
219 ESP_LOGV(TAG,
"[%s] Converted fan mode %s to bedjet fan step %d", this->get_name().c_str(),
fan_mode.c_str(),
221 bool result = this->parent_->set_fan_index(fan_index);
233 ESP_LOGV(TAG,
"[%s] Handling on_status with data=%p", this->get_name().c_str(), (
void *) data);
236 if (converted_temp > 0)
240 if (converted_temp > 0)
241 this->current_temperature = converted_temp;
243 const auto *fan_mode_name = bedjet_fan_step_to_fan_mode(data->fan_step);
244 if (fan_mode_name !=
nullptr) {
249 switch (data->mode) {
264 this->set_custom_preset_(
"LTD HT");
277 this->set_custom_preset_(
"EXT HT");
303 ESP_LOGW(TAG,
"[%s] Unexpected mode: 0x%02X", this->get_name().c_str(), data->mode);
307 ESP_LOGV(TAG,
"[%s] After on_status, new mode=%s", this->get_name().c_str(),
310 this->publish_state();
321 if (!this->parent_->is_connected())
323 if (!this->parent_->has_status())
326 auto *
status = this->parent_->get_status_packet();
333 if (this->is_valid_()) {
335 this->publish_state();
336 this->status_clear_warning();
344 ESP_LOGD(TAG,
"[%s] update()", this->get_name().c_str());
347 auto result = this->update_status_();
348 ESP_LOGD(TAG,
"[%s] update_status result=%s", this->get_name().c_str(), result ?
"true" :
"false");
void on_bedjet_state(bool is_ready) override
This class is used to encode all control actions on a climate device.
ClimatePreset
Enum for all preset modes.
void reset_state_()
Resets states to defaults.
const optional< ClimateMode > & get_mode() const
Enter Extended Heat mode (limited to 10 hours)
const LogString * climate_mode_to_string(ClimateMode mode)
Convert the given ClimateMode to a human-readable string.
BedJet is in Extended Heat mode (limited to 10 hours)
Enter Heat mode (limited to 4 hours)
BedJet is in "wait" mode, a step during a biorhythm program.
The format of a BedJet V3 status packet.
BedJet is in Dry mode (high speed, no heat)
BedJet is in Cool mode (actually "Fan only" mode)
bool update_status_()
Attempts to update the climate device from the last received BedjetStatusPacket.
float bedjet_temp_to_c(const uint8_t temp)
Converts a BedJet temp step into degrees Celsius.
std::string describe() override
HVACMode.HEAT is handled using BTN_EXTHT.
const optional< std::string > & get_custom_preset() const
const optional< ClimatePreset > & get_preset() const
void control(const climate::ClimateCall &call) override
BedJet is in Heat mode (limited to 4 hours)
BedjetMode mode
BedJet operating mode.
const LogString * climate_preset_to_string(ClimatePreset preset)
Convert the given PresetMode to a human-readable string.
const optional< std::string > & get_custom_fan_mode() const
const optional< float > & get_target_temperature() const
ClimateMode
Enum for all modes a climate device can be in.
const LogString * climate_fan_mode_to_string(ClimateFanMode fan_mode)
Convert the given ClimateFanMode to a human-readable string.
const optional< ClimateFanMode > & get_fan_mode() const
BedJet is in Turbo mode (high heat, limited time)
BedjetHeatMode
Optional heating strategies to use for climate::CLIMATE_MODE_HEAT.
uint8_t fan_step
BedJet fan speed; value is in the 0-19 range, representing 5% increments (5%-100%): `5 + 5...
void dump_config() override
void on_status(const BedjetStatusPacket *data) override