Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@
*.exe
*.out
*.app
.esphome
30 changes: 18 additions & 12 deletions components/neewerlight/neewer_light_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@ namespace esphome {
namespace neewerlight {

void NeewerBLEOutput::dump_config() {
char service_uuid_str[esp32_ble::UUID_STR_LEN];
char char_uuid_str[esp32_ble::UUID_STR_LEN];
ESP_LOGCONFIG(TAG, "Neewer BLE Output:");
ESP_LOGCONFIG(TAG, " MAC address : %s", this->parent_->address_str().c_str());
ESP_LOGCONFIG(TAG, " Service UUID : %s", this->service_uuid_.to_string().c_str());
ESP_LOGCONFIG(TAG, " Characteristic UUID: %s", this->char_uuid_.to_string().c_str());
ESP_LOGCONFIG(TAG, " MAC address : %s", this->parent_->address_str());
ESP_LOGCONFIG(TAG, " Service UUID : %s", this->service_uuid_.to_str(service_uuid_str));
ESP_LOGCONFIG(TAG, " Characteristic UUID: %s", this->char_uuid_.to_str(char_uuid_str));
LOG_BINARY_OUTPUT(this);
};

void NeewerBLEOutput::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
esp_ble_gattc_cb_param_t *param) {
char char_uuid_str[esp32_ble::UUID_STR_LEN];
switch (event) {
case ESP_GATTC_OPEN_EVT:
this->client_state_ = espbt::ClientState::ESTABLISHED;
ESP_LOGW(TAG, "[%s] Connected successfully!", this->char_uuid_.to_string().c_str());
ESP_LOGW(TAG, "[%s] Connected successfully!", this->char_uuid_.to_str(char_uuid_str));
break;
case ESP_GATTC_DISCONNECT_EVT:
ESP_LOGW(TAG, "[%s] Disconnected", this->char_uuid_.to_string().c_str());
ESP_LOGW(TAG, "[%s] Disconnected", this->char_uuid_.to_str(char_uuid_str));
this->client_state_ = espbt::ClientState::IDLE;
break;
case ESP_GATTC_WRITE_CHAR_EVT: {
Expand All @@ -31,11 +34,11 @@ void NeewerBLEOutput::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_i

auto *chr = this->parent()->get_characteristic(this->service_uuid_, this->char_uuid_);
if (chr == nullptr) {
ESP_LOGW(TAG, "[%s] Characteristic not found.", this->char_uuid_.to_string().c_str());
ESP_LOGW(TAG, "[%s] Characteristic not found.", this->char_uuid_.to_str(char_uuid_str));
break;
}
if (param->write.handle == chr->handle) {
ESP_LOGW(TAG, "[%s] Write error, status=%d", this->char_uuid_.to_string().c_str(), param->write.status);
ESP_LOGW(TAG, "[%s] Write error, status=%d", this->char_uuid_.to_str(char_uuid_str), param->write.status);
}
break;
}
Expand All @@ -45,16 +48,17 @@ void NeewerBLEOutput::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_i
};

void NeewerBLEOutput::write_state(float state) {
char char_uuid_str[esp32_ble::UUID_STR_LEN];
if (this->client_state_ != espbt::ClientState::ESTABLISHED) {
ESP_LOGW(TAG, "[%s] Not connected to BLE client. State update can not be written.",
this->char_uuid_.to_string().c_str());
this->char_uuid_.to_str(char_uuid_str));
return;
}

auto *chr = this->parent()->get_characteristic(this->service_uuid_, this->char_uuid_);
if (chr == nullptr) {
ESP_LOGW(TAG, "[%s] Characteristic not found. State update can not be written.",
this->char_uuid_.to_string().c_str());
this->char_uuid_.to_str(char_uuid_str));
return;
}

Expand Down Expand Up @@ -111,10 +115,12 @@ NeewerBLEOutput::NeewerBLEOutput() {
};

void NeewerRGBCTLightOutput::dump_config() {
char service_uuid_str[esp32_ble::UUID_STR_LEN];
char char_uuid_str[esp32_ble::UUID_STR_LEN];
ESP_LOGCONFIG(TAG, "Neewer RGBCT Light Output:");
ESP_LOGCONFIG(TAG, " MAC address : %s", this->parent_->address_str().c_str());
ESP_LOGCONFIG(TAG, " Service UUID : %s", this->service_uuid_.to_string().c_str());
ESP_LOGCONFIG(TAG, " Characteristic UUID: %s", this->char_uuid_.to_string().c_str());
ESP_LOGCONFIG(TAG, " MAC address : %s", this->parent_->address_str());
ESP_LOGCONFIG(TAG, " Service UUID : %s", this->service_uuid_.to_str(service_uuid_str));
ESP_LOGCONFIG(TAG, " Characteristic UUID: %s", this->char_uuid_.to_str(char_uuid_str));
ESP_LOGCONFIG(TAG, " Require Response : %s", this->require_response_ ? "True" : "False");
ESP_LOGCONFIG(TAG, " Colour Temperatures: %.2f - %.2f",
this->cold_white_temperature_, this->warm_white_temperature_);
Expand Down
30 changes: 30 additions & 0 deletions test-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
esphome:
name: esp32-1
friendly_name: ESP32-1

esp32:
board: esp32dev
framework:
type: esp-idf

# Enable logging
logger:

# captive_portal:

external_components:
- source: components
components: [neewerlight_ble, neewerlight]

esp32_ble_tracker:

ble_client:
- mac_address: DD:FF:FF:FF:FF:FF
id: test

light:
- platform: neewerlight
name: "Test"
ble_client_id: test
gamma_correct: 1.0
default_transition_length: 0s