ESPHome  2022.6.3
Go to the documentation of this file.
1 #pragma once
7 #include "esphome/core/defines.h"
8 #include "esphome/core/hal.h"
9 #include "bedjet_base.h"
11 #ifdef USE_TIME
13 #endif
15 #ifdef USE_ESP32
17 #include <esp_gattc_api.h>
19 namespace esphome {
20 namespace bedjet {
24 static const espbt::ESPBTUUID BEDJET_SERVICE_UUID = espbt::ESPBTUUID::from_raw("00001000-bed0-0080-aa55-4265644a6574");
25 static const espbt::ESPBTUUID BEDJET_STATUS_UUID = espbt::ESPBTUUID::from_raw("00002000-bed0-0080-aa55-4265644a6574");
26 static const espbt::ESPBTUUID BEDJET_COMMAND_UUID = espbt::ESPBTUUID::from_raw("00002004-bed0-0080-aa55-4265644a6574");
27 static const espbt::ESPBTUUID BEDJET_NAME_UUID = espbt::ESPBTUUID::from_raw("00002001-bed0-0080-aa55-4265644a6574");
30  public:
31  void setup() override;
32  void loop() override;
33  void update() override;
34  void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
35  esp_ble_gattc_cb_param_t *param) override;
36  void dump_config() override;
37  float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
39 #ifdef USE_TIME
40  void set_time_id(time::RealTimeClock *time_id) { this->time_id_ = time_id; }
41  void send_local_time();
42 #endif
43  void set_clock(uint8_t hour, uint8_t minute);
44  void set_status_timeout(uint32_t timeout) { this->timeout_ = timeout; }
49  void upgrade_firmware();
58  // climate::CLIMATE_MODE_TURBO // Not supported by Climate: see presets instead
61  });
63  // It would be better if we had a slider for the fan modes.
64  traits.set_supported_custom_fan_modes(BEDJET_FAN_STEP_NAMES_SET);
66  // If we support NONE, then have to decide what happens if the user switches to it (turn off?)
67  // climate::CLIMATE_PRESET_NONE,
68  // Climate doesn't have a "TURBO" mode, but we can use the BOOST preset instead.
70  });
72  // We could fetch biodata from bedjet and set these names that way.
73  // But then we have to invert the lookup in order to send the right preset.
74  // For now, we can leave them as M1-3 to match the remote buttons.
75  // EXT HT added to match remote button.
76  "EXT HT",
77  "M1",
78  "M2",
79  "M3",
80  });
81  if (this->heating_mode_ == HEAT_MODE_EXTENDED) {
83  } else {
85  }
89  return traits;
90  }
92  protected:
93  void control(const climate::ClimateCall &call) override;
95 #ifdef USE_TIME
96  void setup_time_();
98 #endif
103  static const uint32_t MIN_NOTIFY_THROTTLE = 5000;
104  static const uint32_t NOTIFY_WARN_THRESHOLD = 300000;
105  static const uint32_t DEFAULT_STATUS_TIMEOUT = 900000;
107  uint8_t set_notify_(bool enable);
108  uint8_t write_bedjet_packet_(BedjetPacket *pkt);
109  void reset_state_();
110  bool update_status_();
112  bool is_valid_() {
113  // FIXME: find a better way to check this?
114  return !std::isnan(this->current_temperature) && !std::isnan(this->target_temperature) &&
115  this->current_temperature > 1 && this->target_temperature > 1;
116  }
118  uint32_t last_notify_ = 0;
119  bool force_refresh_ = false;
121  std::unique_ptr<BedjetCodec> codec_;
127  uint8_t write_notify_config_descriptor_(bool enable);
128 };
130 } // namespace bedjet
131 } // namespace esphome
133 #endif
This class is used to encode all control actions on a climate device.
Definition: climate.h:33
void set_supported_custom_presets(std::set< std::string > supported_custom_presets)
void set_time_id(time::RealTimeClock *time_id)
Definition: bedjet.h:40
void set_visual_temperature_step(float temperature_step)
uint16_t config_descr_status_
Definition: bedjet.h:125
BedjetHeatMode heating_mode_
Definition: bedjet.h:101
void update() override
Definition: bedjet.cpp:633
float target_temperature
The target temperature of the climate device.
Definition: climate.h:183
const float AFTER_WIFI
For components that should be initialized after WiFi is connected.
Definition: component.cpp:24
float get_setup_priority() const override
Definition: bedjet.h:37
void loop() override
Definition: bedjet.cpp:111
The RealTimeClock class exposes common timekeeping functions via the device&#39;s local real-time clock...
This class contains all static data for climate devices.
void upgrade_firmware()
Attempts to check for and apply firmware updates.
Definition: bedjet.cpp:47
void add_supported_custom_preset(const std::string &preset)
void set_visual_min_temperature(float visual_min_temperature)
The climate device is set to heat to reach the target temperature.
Definition: climate_mode.h:18
climate::ClimateTraits traits() override
Definition: bedjet.h:51
ClimateMode mode
The active mode of the climate device.
Definition: climate.h:175
uint16_t char_handle_status_
Definition: bedjet.h:124
void send_local_time()
Attempts to sync the local time (via time_id) to the BedJet device.
Definition: bedjet.cpp:466
float current_temperature
The current temperature of the climate device, as reported from the integration.
Definition: climate.h:179
This class simplifies creating components that periodically check a state.
Definition: component.h:266
The climate device is set to dry/humidity mode.
Definition: climate_mode.h:22
void set_supported_presets(std::set< ClimatePreset > presets)
uint8_t set_notify_(bool enable)
Configures the local ESP BLE client to register (true) or unregister (false) for status notifications...
Definition: bedjet.cpp:524
static const uint32_t NOTIFY_WARN_THRESHOLD
Definition: bedjet.h:104
static ESPBTUUID from_raw(const uint8_t *data)
HVACMode.HEAT is handled using BTN_EXTHT.
Definition: bedjet_const.h:32
void setup_time_()
Initializes time sync callbacks to support syncing current time to the BedJet.
Definition: bedjet.cpp:480
void setup() override
Definition: bedjet.cpp:82
void set_status_timeout(uint32_t timeout)
Definition: bedjet.h:44
bool update_status_()
Attempts to update the climate device from the last received BedjetStatusPacket.
Definition: bedjet.cpp:547
void dump_config() override
Definition: bedjet.cpp:56
void set_supported_modes(std::set< ClimateMode > modes)
static const uint32_t DEFAULT_STATUS_TIMEOUT
Definition: bedjet.h:105
void set_visual_max_temperature(float visual_max_temperature)
uint8_t write_notify_config_descriptor_(bool enable)
Reimplementation of BLEClient.gattc_event_handler() for ESP_GATTC_REG_FOR_NOTIFY_EVT.
Definition: bedjet.cpp:442
The climate device is off.
Definition: climate_mode.h:12
void set_supports_action(bool supports_action)
void reset_state_()
Resets states to defaults.
Definition: bedjet.cpp:101
void set_heating_mode(BedjetHeatMode mode)
Sets the default strategy to use for climate::CLIMATE_MODE_HEAT.
Definition: bedjet.h:46
uint8_t write_bedjet_packet_(BedjetPacket *pkt)
Writes one BedjetPacket to the BLE client on the BEDJET_COMMAND_UUID.
Definition: bedjet.cpp:508
Device is in boost preset.
Definition: climate_mode.h:88
static const uint32_t MIN_NOTIFY_THROTTLE
Definition: bedjet.h:103
uint16_t char_handle_name_
Definition: bedjet.h:123
Optional heating strategies to use for climate::CLIMATE_MODE_HEAT.
Definition: bedjet_const.h:28
void set_clock(uint8_t hour, uint8_t minute)
Attempt to set the BedJet device&#39;s clock to the specified time.
Definition: bedjet.cpp:492
Definition: a4988.cpp:4
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
Definition: bedjet.cpp:257
void set_supports_current_temperature(bool supports_current_temperature)
void set_supported_custom_fan_modes(std::set< std::string > supported_custom_fan_modes)
void control(const climate::ClimateCall &call) override
Definition: bedjet.cpp:113
The climate device only has the fan enabled, no heating or cooling is taking place.
Definition: climate_mode.h:20
uint16_t char_handle_cmd_
Definition: bedjet.h:122
optional< time::RealTimeClock * > time_id_
Definition: bedjet.h:97
ClimateDevice - This is the base class for all climate integrations.
Definition: climate.h:167
HVACMode.HEAT is handled using BTN_HEAT (default)
Definition: bedjet_const.h:30
std::unique_ptr< BedjetCodec > codec_
Definition: bedjet.h:121
uint32_t last_notify_
Definition: bedjet.h:118