10 static const char *
const TAG =
"am43";
13 ESP_LOGCONFIG(TAG,
"AM43");
14 LOG_SENSOR(
" ",
"Battery", this->
battery_);
19 this->
encoder_ = make_unique<Am43Encoder>();
20 this->
decoder_ = make_unique<Am43Decoder>();
28 case ESP_GATTC_OPEN_EVT: {
29 if (param->open.status == ESP_GATT_OK) {
34 case ESP_GATTC_DISCONNECT_EVT: {
43 case ESP_GATTC_SEARCH_CMPL_EVT: {
47 ESP_LOGE(TAG,
"[%s] Detected a Tuya AM43 which is not supported, sorry.",
50 ESP_LOGE(TAG,
"[%s] No control service found at device, not an AM43..?",
58 case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
59 this->
node_state = espbt::ClientState::ESTABLISHED;
63 case ESP_GATTC_NOTIFY_EVT: {
64 if (param->notify.handle != this->char_handle_)
66 this->
decoder_->decode(param->notify.value, param->notify.value_len);
80 auto *packet = this->
encoder_->get_light_level_request();
83 ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
85 ESP_LOGW(TAG,
"[%s] esp_ble_gattc_write_char failed, status=%d", this->
parent_->
address_str().c_str(),
99 if (this->
node_state != espbt::ClientState::ESTABLISHED) {
100 ESP_LOGW(TAG,
"[%s] Cannot poll, not connected", this->
parent_->
address_str().c_str());
105 auto *packet = this->
encoder_->get_battery_level_request();
108 packet->length, packet->data, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
std::unique_ptr< Am43Decoder > decoder_
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
uint16_t get_conn_id() const
std::string address_str() const
uint32_t IRAM_ATTR HOT millis()
void publish_state(float state)
Publish a new state to the front-end.
uint8_t last_battery_update_
void dump_config() override
sensor::Sensor * battery_
sensor::Sensor * illuminance_
BLECharacteristic * get_characteristic(espbt::ESPBTUUID service, espbt::ESPBTUUID chr)
Implementation of SPI Controller mode.
std::unique_ptr< Am43Encoder > encoder_
espbt::ClientState node_state