13 LOG_COVER(
"",
"AM43 Cover",
this);
16 " Invert Position: %d",
24 ESP_LOGI(TAG,
"[%s] Logging into AM43", LOG_STR_ARG(this->
get_log_name()));
31 traits.set_supports_stop(
true);
32 traits.set_supports_position(
true);
33 traits.set_supports_tilt(
false);
34 traits.set_is_assumed_state(
false);
39 if (this->
node_state != espbt::ClientState::ESTABLISHED) {
40 ESP_LOGW(TAG,
"[%s] Cannot send cover control, not connected", LOG_STR_ARG(this->
get_log_name()));
45 auto opt_pos =
call.get_position();
46 if (opt_pos.has_value()) {
56 esp_ble_gattc_cb_param_t *param) {
58 case ESP_GATTC_DISCONNECT_EVT: {
62 case ESP_GATTC_SEARCH_CMPL_EVT: {
66 ESP_LOGE(TAG,
"[%s] Detected a Tuya AM43 which is not supported, sorry.", LOG_STR_ARG(this->
get_log_name()));
68 ESP_LOGE(TAG,
"[%s] No control service found at device, not an AM43..?", LOG_STR_ARG(this->
get_log_name()));
77 ESP_LOGW(TAG,
"[%s] esp_ble_gattc_register_for_notify failed, status=%d", LOG_STR_ARG(this->
get_log_name()),
82 case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
83 this->
node_state = espbt::ClientState::ESTABLISHED;
86 case ESP_GATTC_NOTIFY_EVT: {
87 if (param->notify.handle != this->char_handle_)
90 decoder.
decode(param->notify.value, param->notify.value_len);
105 ESP_LOGI(TAG,
"[%s] AM43 pin accepted.", LOG_STR_ARG(this->
get_log_name()));
108 ESP_LOGW(TAG,
"[%s] AM43 pin rejected!", LOG_STR_ARG(this->
get_log_name()));
113 ESP_LOGW(TAG,
"[%s] Got nack after sending set_position. Bad pin?", LOG_STR_ARG(this->
get_log_name()));
117 ESP_LOGW(TAG,
"[%s] Got nack after sending set_state. Bad pin?", LOG_STR_ARG(this->
get_log_name()));
129 this->char_handle_, packet.
length,
const_cast<uint8_t *
>(packet.
data),
130 ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
132 ESP_LOGW(TAG,
"[%s] Error writing %s to device, error = %d", LOG_STR_ARG(this->
get_log_name()), LOG_STR_ARG(what),
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
bool write_packet_(const Am43Packet &packet, const LogString *what)
Writes a request to the control characteristic; logs and returns false on failure.
void dump_config() override
cover::CoverTraits get_traits() override
void control(const cover::CoverCall &call) override
Decodes one notification; construct it on the stack for each frame.
bool has_position() const
bool has_set_position_response() const
bool has_set_state_response() const
bool has_pin_response() const
void decode(const uint8_t *data, uint16_t length)
static Am43Packet get_set_position_request(uint8_t position)
static Am43Packet get_stop_request()
static Am43Packet get_send_pin_request(uint16_t pin)
static Am43Packet get_position_request()
espbt::ClientState node_state
void publish_state(bool save=true)
Publish the current state of the cover.
float position
The position of the cover from 0.0 (fully closed) to 1.0 (fully open).
BLECharacteristic * get_characteristic(espbt::ESPBTUUID service, espbt::ESPBTUUID chr)
ESPHOME_LOG_TAG(TAG, "am43")