9 static const char *
const TAG =
"anova";
16 this->codec_ = make_unique<AnovaCodec>();
17 this->current_request_ = 0;
28 pkt = this->codec_->get_stop_request();
31 pkt = this->codec_->get_start_request();
34 ESP_LOGW(TAG,
"Unsupported mode: %d", mode);
38 esp_ble_gattc_write_char(this->parent_->get_gattc_if(), this->parent_->get_conn_id(), this->char_handle_,
39 pkt->
length, pkt->
data, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
41 ESP_LOGW(TAG,
"[%s] esp_ble_gattc_write_char failed, status=%d", this->parent_->address_str().c_str(),
status);
47 esp_ble_gattc_write_char(this->parent_->get_gattc_if(), this->parent_->get_conn_id(), this->char_handle_,
48 pkt->length, pkt->data, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
50 ESP_LOGW(TAG,
"[%s] esp_ble_gattc_write_char failed, status=%d", this->parent_->address_str().c_str(),
status);
57 case ESP_GATTC_DISCONNECT_EVT: {
58 this->current_temperature = NAN;
60 this->publish_state();
63 case ESP_GATTC_SEARCH_CMPL_EVT: {
64 auto *chr = this->parent_->get_characteristic(ANOVA_SERVICE_UUID, ANOVA_CHARACTERISTIC_UUID);
66 ESP_LOGW(TAG,
"[%s] No control service found at device, not an Anova..?", this->get_name().c_str());
67 ESP_LOGW(TAG,
"[%s] Note, this component does not currently support Anova Nano.", this->get_name().c_str());
70 this->char_handle_ = chr->handle;
72 auto status = esp_ble_gattc_register_for_notify(this->parent_->get_gattc_if(), this->parent_->get_remote_bda(),
75 ESP_LOGW(TAG,
"[%s] esp_ble_gattc_register_for_notify failed, status=%d", this->get_name().c_str(),
status);
79 case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
80 this->node_state = espbt::ClientState::ESTABLISHED;
81 this->current_request_ = 0;
85 case ESP_GATTC_NOTIFY_EVT: {
86 if (param->notify.handle != this->char_handle_)
88 this->codec_->decode(param->notify.value, param->notify.value_len);
89 if (this->codec_->has_target_temp()) {
92 if (this->codec_->has_current_temp()) {
93 this->current_temperature = this->codec_->current_temp_;
95 if (this->codec_->has_running()) {
98 if (this->codec_->has_unit()) {
99 this->fahrenheit_ = (this->codec_->unit_ ==
'f');
100 ESP_LOGD(TAG,
"Anova units is %s", this->fahrenheit_ ?
"fahrenheit" :
"celsius");
101 this->current_request_++;
103 this->publish_state();
105 if (this->current_request_ > 1) {
107 switch (this->current_request_++) {
109 pkt = this->codec_->get_read_target_temp_request();
112 pkt = this->codec_->get_read_current_temp_request();
115 this->current_request_ = 1;
118 if (pkt !=
nullptr) {
120 esp_ble_gattc_write_char(this->parent_->get_gattc_if(), this->parent_->get_conn_id(), this->char_handle_,
121 pkt->
length, pkt->
data, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
123 ESP_LOGW(TAG,
"[%s] esp_ble_gattc_write_char failed, status=%d", this->parent_->address_str().c_str(),
138 if (this->node_state != espbt::ClientState::ESTABLISHED)
141 if (this->current_request_ < 2) {
142 auto *pkt = this->codec_->get_read_device_status_request();
143 if (this->current_request_ == 0)
144 this->codec_->get_set_unit_request(this->fahrenheit_ ?
'f' :
'c');
146 esp_ble_gattc_write_char(this->parent_->get_gattc_if(), this->parent_->get_conn_id(), this->char_handle_,
147 pkt->length, pkt->data, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
149 ESP_LOGW(TAG,
"[%s] esp_ble_gattc_write_char failed, status=%d", this->parent_->address_str().c_str(),
status);
151 this->current_request_++;
This class is used to encode all control actions on a climate device.
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
void control(const climate::ClimateCall &call) override
const optional< ClimateMode > & get_mode() const
The climate device is set to heat to reach the target temperature.
BedjetMode mode
BedJet operating mode.
void dump_config() override
const optional< float > & get_target_temperature() const
ClimateMode
Enum for all modes a climate device can be in.
The climate device is off.
Implementation of SPI Controller mode.
void set_unit_of_measurement(const char *unit)