diff --git a/esphome/components/ble_client/text_sensor/ble_text_sensor.cpp b/esphome/components/ble_client/text_sensor/ble_text_sensor.cpp index 53c9a9d10e..cacf1b4835 100644 --- a/esphome/components/ble_client/text_sensor/ble_text_sensor.cpp +++ b/esphome/components/ble_client/text_sensor/ble_text_sensor.cpp @@ -11,8 +11,6 @@ namespace esphome::ble_client { static const char *const TAG = "ble_text_sensor"; -static const std::string EMPTY = ""; - void BLETextSensor::loop() { // Parent BLEClientNode has a loop() method, but this component uses // polling via update() and BLE callbacks so loop isn't needed @@ -47,7 +45,7 @@ void BLETextSensor::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_ } case ESP_GATTC_CLOSE_EVT: { this->status_set_warning(); - this->publish_state(EMPTY); + this->publish_state(""); break; } case ESP_GATTC_SEARCH_CMPL_EVT: { @@ -55,7 +53,7 @@ void BLETextSensor::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_ auto *chr = this->parent()->get_characteristic(this->service_uuid_, this->char_uuid_); if (chr == nullptr) { this->status_set_warning(); - this->publish_state(EMPTY); + this->publish_state(""); char service_buf[esp32_ble::UUID_STR_LEN]; char char_buf[esp32_ble::UUID_STR_LEN]; ESP_LOGW(TAG, "No sensor characteristic found at service %s char %s", this->service_uuid_.to_str(service_buf), @@ -67,7 +65,7 @@ void BLETextSensor::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_ auto *descr = chr->get_descriptor(this->descr_uuid_); if (descr == nullptr) { this->status_set_warning(); - this->publish_state(EMPTY); + this->publish_state(""); char service_buf[esp32_ble::UUID_STR_LEN]; char char_buf[esp32_ble::UUID_STR_LEN]; char descr_buf[esp32_ble::UUID_STR_LEN]; @@ -99,7 +97,7 @@ void BLETextSensor::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_ break; } this->status_clear_warning(); - this->publish_state(this->parse_data(param->read.value, param->read.value_len)); + this->publish_state(reinterpret_cast(param->read.value), param->read.value_len); } break; } @@ -108,7 +106,7 @@ void BLETextSensor::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_ break; ESP_LOGV(TAG, "[%s] ESP_GATTC_NOTIFY_EVT: handle=0x%x, value=0x%x", this->get_name().c_str(), param->notify.handle, param->notify.value[0]); - this->publish_state(this->parse_data(param->notify.value, param->notify.value_len)); + this->publish_state(reinterpret_cast(param->notify.value), param->notify.value_len); break; } case ESP_GATTC_REG_FOR_NOTIFY_EVT: { @@ -121,11 +119,6 @@ void BLETextSensor::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_ } } -std::string BLETextSensor::parse_data(uint8_t *value, uint16_t value_len) { - std::string text(value, value + value_len); - return text; -} - void BLETextSensor::update() { if (this->node_state != espbt::ClientState::ESTABLISHED) { ESP_LOGW(TAG, "[%s] Cannot poll, not connected", this->get_name().c_str()); @@ -140,7 +133,7 @@ void BLETextSensor::update() { ESP_GATT_AUTH_REQ_NONE); if (status) { this->status_set_warning(); - this->publish_state(EMPTY); + this->publish_state(""); ESP_LOGW(TAG, "[%s] Error sending read request for sensor, status=%d", this->get_name().c_str(), status); } } diff --git a/esphome/components/ble_client/text_sensor/ble_text_sensor.h b/esphome/components/ble_client/text_sensor/ble_text_sensor.h index 3fbd64389c..b4374e4016 100644 --- a/esphome/components/ble_client/text_sensor/ble_text_sensor.h +++ b/esphome/components/ble_client/text_sensor/ble_text_sensor.h @@ -29,7 +29,6 @@ class BLETextSensor : public text_sensor::TextSensor, public PollingComponent, p void set_descr_uuid32(uint32_t uuid) { this->descr_uuid_ = espbt::ESPBTUUID::from_uint32(uuid); } void set_descr_uuid128(uint8_t *uuid) { this->descr_uuid_ = espbt::ESPBTUUID::from_raw(uuid); } void set_enable_notify(bool notify) { this->notify_ = notify; } - std::string parse_data(uint8_t *value, uint16_t value_len); uint16_t handle; protected: