From 0bf36730960592b3ea34d68ab82cb1b9ef79eb26 Mon Sep 17 00:00:00 2001 From: raul Date: Sat, 30 Nov 2024 16:35:12 +0100 Subject: [PATCH] CI fixes --- esphome/components/zigbee/__init__.py | 36 +++++------ esphome/components/zigbee/automation.cpp | 2 +- esphome/components/zigbee/automation.h | 28 ++++----- esphome/components/zigbee/zigbee.cpp | 71 +++++++++++----------- esphome/components/zigbee/zigbee.h | 36 +++++------ esphome/components/zigbee/zigbee_helpers.h | 5 ++ 6 files changed, 89 insertions(+), 89 deletions(-) diff --git a/esphome/components/zigbee/__init__.py b/esphome/components/zigbee/__init__.py index ea7cdb8cf27c..e5b00ccb99e6 100644 --- a/esphome/components/zigbee/__init__.py +++ b/esphome/components/zigbee/__init__.py @@ -34,11 +34,11 @@ DEPENDENCIES = ["esp32"] CONF_ENDPOINTS = "endpoints" -CONF_DEVICE_ID = "device_type" -CONF_ENDPOINT_NUM = "num" +CONF_DEVICE_TYPE = "device_type" +CONF_NUM = "num" CONF_CLUSTERS = "clusters" CONF_ON_JOIN = "on_join" -CONF_IDENT = "ident time" +CONF_IDENT_TIME = "ident_time" CONF_MANUFACTURER = "manufacturer" CONF_ATTRIBUTES = "attributes" CONF_ROLE = "role" @@ -95,15 +95,15 @@ def final_validate(config): cv.Optional( CONF_DATE, default=datetime.datetime.now().strftime("%Y%m%d") ): cv.string, - cv.Optional(CONF_IDENT): cv.string, + cv.Optional(CONF_IDENT_TIME): cv.string, cv.Optional(CONF_POWER_SUPPLY, default=0): cv.int_, # make enum cv.Optional(CONF_VERSION, default=0): cv.int_, cv.Optional(CONF_AREA, default=0): cv.int_, # make enum cv.Required(CONF_ENDPOINTS): cv.ensure_list( cv.Schema( { - cv.Required(CONF_DEVICE_ID): cv.enum(DEVICE_ID, upper=True), - cv.Optional(CONF_ENDPOINT_NUM): cv.int_range(1, 240), + cv.Required(CONF_DEVICE_TYPE): cv.enum(DEVICE_ID, upper=True), + cv.Optional(CONF_NUM): cv.int_range(1, 240), cv.Optional(CONF_CLUSTERS, default={}): cv.ensure_list( cv.Schema( { @@ -200,23 +200,19 @@ async def to_code(config): config[CONF_AREA], ) ) - if CONF_IDENT in config: - cg.add(var.set_ident_time(config[CONF_IDENT])) + if CONF_IDENT_TIME in config: + cg.add(var.set_ident_time(config[CONF_IDENT_TIME])) for ep in config[CONF_ENDPOINTS]: cg.add( - var.create_default_cluster( - ep[CONF_ENDPOINT_NUM], DEVICE_ID[ep[CONF_DEVICE_ID]] - ) + var.create_default_cluster(ep[CONF_NUM], DEVICE_ID[ep[CONF_DEVICE_TYPE]]) ) cg.add( - var.add_cluster( - ep[CONF_ENDPOINT_NUM], CLUSTER_ID["BASIC"], CLUSTER_ROLE["SERVER"] - ) + var.add_cluster(ep[CONF_NUM], CLUSTER_ID["BASIC"], CLUSTER_ROLE["SERVER"]) ) - if CONF_IDENT in config: + if CONF_IDENT_TIME in config: cg.add( var.add_cluster( - ep[CONF_ENDPOINT_NUM], + ep[CONF_NUM], CLUSTER_ID["IDENTIFY"], CLUSTER_ROLE["SERVER"], ) @@ -224,7 +220,7 @@ async def to_code(config): for cl in ep[CONF_CLUSTERS]: cg.add( var.add_cluster( - ep[CONF_ENDPOINT_NUM], + ep[CONF_NUM], CLUSTER_ID[cl[CONF_ID]], CLUSTER_ROLE[cl[CONF_ROLE]], ) @@ -233,7 +229,7 @@ async def to_code(config): if CONF_VALUE in attr: cg.add( var.add_attr( - ep[CONF_ENDPOINT_NUM], + ep[CONF_NUM], CLUSTER_ID[cl[CONF_ID]], CLUSTER_ROLE[cl[CONF_ROLE]], attr[CONF_ID], @@ -243,7 +239,7 @@ async def to_code(config): if CONF_REPORT in attr and attr[CONF_REPORT] is True: cg.add( var.set_report( - ep[CONF_ENDPOINT_NUM], + ep[CONF_NUM], CLUSTER_ID[cl[CONF_ID]], CLUSTER_ROLE[cl[CONF_ROLE]], attr[CONF_ID], @@ -257,7 +253,7 @@ async def to_code(config): await cg.register_component(trigger, conf) cg.add( trigger.set_attr( - ep[CONF_ENDPOINT_NUM], + ep[CONF_NUM], CLUSTER_ID[cl[CONF_ID]], attr[CONF_ID], attr[CONF_TYPE], diff --git a/esphome/components/zigbee/automation.cpp b/esphome/components/zigbee/automation.cpp index ff96b5de44dd..119e4fe9e385 100644 --- a/esphome/components/zigbee/automation.cpp +++ b/esphome/components/zigbee/automation.cpp @@ -33,4 +33,4 @@ float get_b_from_xy(float x, float y) { } } // namespace zigbee -} // namespace esphome \ No newline at end of file +} // namespace esphome diff --git a/esphome/components/zigbee/automation.h b/esphome/components/zigbee/automation.h index 3ebe87fb88b3..3e8ee6f7068d 100644 --- a/esphome/components/zigbee/automation.h +++ b/esphome/components/zigbee/automation.h @@ -9,8 +9,6 @@ namespace esphome { namespace zigbee { -template T getValueByType(uint8_t attr_type, void *data); - class ZigBeeJoinTrigger : public Trigger<> { public: explicit ZigBeeJoinTrigger(ZigBeeComponent *parent) { @@ -57,10 +55,10 @@ template class ZigBeeOnValueTrigger : public Trigger, public Co public: explicit ZigBeeOnValueTrigger(ZigBeeComponent *parent) : parent_(parent) {} void set_attr(uint8_t endpoint_id, uint16_t cluster_id, uint16_t attr_id, uint8_t attr_type) { - this->ep_id = endpoint_id; - this->cl_id = cluster_id; - this->attr_id = attr_id; - this->attr_type = attr_type; + this->ep_id_ = endpoint_id; + this->cl_id_ = cluster_id; + this->attr_id_ = attr_id; + this->attr_type_ = attr_type; } void setup() override { this->parent_->add_on_value_callback([this](esp_zb_device_cb_common_info_t info, esp_zb_zcl_attribute_t attribute) { @@ -70,22 +68,22 @@ template class ZigBeeOnValueTrigger : public Trigger, public Co protected: void on_value_(esp_zb_device_cb_common_info_t info, esp_zb_zcl_attribute_t attribute) { - if (info.dst_endpoint == this->ep_id) { - if (info.cluster == this->cl_id) { - if (attribute.id == this->attr_id && attribute.data.type == attr_type && attribute.data.value) { - this->trigger(getValueByType(attr_type, attribute.data.value)); + if (info.dst_endpoint == this->ep_id_) { + if (info.cluster == this->cl_id_) { + if (attribute.id == this->attr_id_ && attribute.data.type == attr_type_ && attribute.data.value) { + this->trigger(get_value_by_type(attr_type_, attribute.data.value)); } } } } ZigBeeComponent *parent_; - uint8_t ep_id; - uint16_t cl_id; - uint16_t attr_id; - uint8_t attr_type; + uint8_t ep_id_; + uint16_t cl_id_; + uint16_t attr_id_; + uint8_t attr_type_; }; -template T getValueByType(uint8_t attr_type, void *data) { +template T get_value_by_type(uint8_t attr_type, void *data) { switch (attr_type) { case ESP_ZB_ZCL_ATTR_TYPE_8BIT: return (T) * (uint8_t *) data; diff --git a/esphome/components/zigbee/zigbee.cpp b/esphome/components/zigbee/zigbee.cpp index 6ed9693a6202..3bff1183015a 100644 --- a/esphome/components/zigbee/zigbee.cpp +++ b/esphome/components/zigbee/zigbee.cpp @@ -19,7 +19,7 @@ namespace zigbee { static const char *const TAG = "zigbee"; // uint8_t HA_ESP_LIGHT_ENDPOINT; -bool connected = false; +bool connected_ = false; ZigBeeComponent *zigbeeC; device_params_t coord; @@ -153,7 +153,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { extended_pan_id[2], extended_pan_id[1], extended_pan_id[0], esp_zb_get_pan_id(), esp_zb_get_current_channel()); zigbeeC->on_join_callback_.call(); - connected = true; + connected_ = true; memcpy(&(coord.ieee_addr), extended_pan_id, sizeof(esp_zb_ieee_addr_t)); coord.endpoint = 1; @@ -230,29 +230,29 @@ static esp_err_t zb_action_handler(esp_zb_core_action_callback_id_t callback_id, } void ZigBeeComponent::create_default_cluster(uint8_t endpoint_id, esp_zb_ha_standard_devices_t device_id) { - this->cluster_list[endpoint_id] = esphome_zb_default_clusters_create(device_id); - this->endpoint_list[endpoint_id] = device_id; + this->cluster_list_[endpoint_id] = esphome_zb_default_clusters_create(device_id); + this->endpoint_list_[endpoint_id] = device_id; } void ZigBeeComponent::add_cluster(uint8_t endpoint_id, uint16_t cluster_id, uint8_t role) { esp_zb_attribute_list_t *attr_list; switch (cluster_id) { case 0: - attr_list = create_basic_cluster(); + attr_list = create_basic_cluster_(); break; case 3: - attr_list = create_ident_cluster(); + attr_list = create_ident_cluster_(); break; default: attr_list = esphome_zb_default_attr_list_create(cluster_id); } - this->attribute_list[{endpoint_id, cluster_id, role}] = attr_list; + this->attribute_list_[{endpoint_id, cluster_id, role}] = attr_list; } void ZigBeeComponent::set_basic_cluster(std::string model, std::string manufacturer, std::string date, uint8_t power, uint8_t app_version, uint8_t stack_version, uint8_t hw_version, std::string area, uint8_t physical_env) { - this->basic_cluster_data = { + this->basic_cluster_data_ = { .model = model, .manufacturer = manufacturer, .date = date, @@ -265,75 +265,76 @@ void ZigBeeComponent::set_basic_cluster(std::string model, std::string manufactu }; } -esp_zb_attribute_list_t *ZigBeeComponent::create_basic_cluster() { +esp_zb_attribute_list_t *ZigBeeComponent::create_basic_cluster_() { // ------------------------------ Cluster BASIC ------------------------------ esp_zb_basic_cluster_cfg_t basic_cluster_cfg = { .zcl_version = ESP_ZB_ZCL_BASIC_ZCL_VERSION_DEFAULT_VALUE, - .power_source = this->basic_cluster_data.power, + .power_source = this->basic_cluster_data_.power, }; - ESP_LOGI(TAG, "Model: %s", this->basic_cluster_data.model.c_str()); - ESP_LOGI(TAG, "Manufacturer: %s", this->basic_cluster_data.manufacturer.c_str()); - ESP_LOGI(TAG, "Date: %s", this->basic_cluster_data.date.c_str()); - ESP_LOGI(TAG, "Area: %s", this->basic_cluster_data.area.c_str()); + ESP_LOGI(TAG, "Model: %s", this->basic_cluster_data_.model.c_str()); + ESP_LOGI(TAG, "Manufacturer: %s", this->basic_cluster_data_.manufacturer.c_str()); + ESP_LOGI(TAG, "Date: %s", this->basic_cluster_data_.date.c_str()); + ESP_LOGI(TAG, "Area: %s", this->basic_cluster_data_.area.c_str()); uint8_t *ManufacturerName = - get_character_string(this->basic_cluster_data.manufacturer); // warning: this is in format {length, 'string'} : - uint8_t *ModelIdentifier = get_character_string(this->basic_cluster_data.model); - uint8_t *DateCode = get_character_string(this->basic_cluster_data.date); - uint8_t *Location = get_character_string(this->basic_cluster_data.area); + get_character_string(this->basic_cluster_data_.manufacturer); // warning: this is in format {length, 'string'} : + uint8_t *ModelIdentifier = get_character_string(this->basic_cluster_data_.model); + uint8_t *DateCode = get_character_string(this->basic_cluster_data_.date); + uint8_t *Location = get_character_string(this->basic_cluster_data_.area); esp_zb_attribute_list_t *attr_list = esp_zb_basic_cluster_create(&basic_cluster_cfg); esp_zb_basic_cluster_add_attr(attr_list, ESP_ZB_ZCL_ATTR_BASIC_APPLICATION_VERSION_ID, - &(this->basic_cluster_data.app_version)); + &(this->basic_cluster_data_.app_version)); esp_zb_basic_cluster_add_attr(attr_list, ESP_ZB_ZCL_ATTR_BASIC_STACK_VERSION_ID, - &(this->basic_cluster_data.stack_version)); - esp_zb_basic_cluster_add_attr(attr_list, ESP_ZB_ZCL_ATTR_BASIC_HW_VERSION_ID, &(this->basic_cluster_data.hw_version)); + &(this->basic_cluster_data_.stack_version)); + esp_zb_basic_cluster_add_attr(attr_list, ESP_ZB_ZCL_ATTR_BASIC_HW_VERSION_ID, + &(this->basic_cluster_data_.hw_version)); esp_zb_basic_cluster_add_attr(attr_list, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, ManufacturerName); esp_zb_basic_cluster_add_attr(attr_list, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, ModelIdentifier); esp_zb_basic_cluster_add_attr(attr_list, ESP_ZB_ZCL_ATTR_BASIC_DATE_CODE_ID, DateCode); esp_zb_basic_cluster_add_attr(attr_list, ESP_ZB_ZCL_ATTR_BASIC_LOCATION_DESCRIPTION_ID, Location); esp_zb_basic_cluster_add_attr(attr_list, ESP_ZB_ZCL_ATTR_BASIC_PHYSICAL_ENVIRONMENT_ID, - &(this->basic_cluster_data.physical_env)); + &(this->basic_cluster_data_.physical_env)); return attr_list; } void ZigBeeComponent::set_ident_time(uint8_t ident_time) { // ------------------------------ Cluster IDENTIFY ------------------------------ - this->ident_time = ident_time; + this->ident_time_ = ident_time; } -esp_zb_attribute_list_t *ZigBeeComponent::create_ident_cluster() { +esp_zb_attribute_list_t *ZigBeeComponent::create_ident_cluster_() { // ------------------------------ Cluster IDENTIFY ------------------------------ esp_zb_identify_cluster_cfg_t identify_cluster_cfg = { - .identify_time = this->ident_time, + .identify_time = this->ident_time_, }; return esp_zb_identify_cluster_create(&identify_cluster_cfg); } esp_err_t ZigBeeComponent::create_endpoint(uint8_t endpoint_id, esp_zb_ha_standard_devices_t device_id) { - esp_zb_cluster_list_t *esp_zb_cluster_list = this->cluster_list[endpoint_id]; + esp_zb_cluster_list_t *esp_zb_cluster_list = this->cluster_list_[endpoint_id]; // ------------------------------ Create endpoint list ------------------------------ esp_zb_endpoint_config_t endpoint_config = {.endpoint = endpoint_id, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = device_id, .app_device_version = 0}; - return esp_zb_ep_list_add_ep(this->esp_zb_ep_list, esp_zb_cluster_list, endpoint_config); + return esp_zb_ep_list_add_ep(this->esp_zb_ep_list_, esp_zb_cluster_list, endpoint_config); } -void ZigBeeComponent::esp_zb_task() { +void ZigBeeComponent::esp_zb_task_() { /* initialize Zigbee stack */ esp_zb_zed_cfg_t zb_zed_cfg = { .ed_timeout = ED_AGING_TIMEOUT, .keep_alive = ED_KEEP_ALIVE, }; esp_zb_cfg_t zb_nwk_cfg = { - .esp_zb_role = this->device_role, + .esp_zb_role = this->device_role_, .install_code_policy = INSTALLCODE_POLICY_ENABLE, }; zb_nwk_cfg.nwk_cfg.zed_cfg = zb_zed_cfg; esp_zb_init(&zb_nwk_cfg); // clusters - for (auto const &[key, val] : this->attribute_list) { - esp_zb_cluster_list_t *esp_zb_cluster_list = this->cluster_list[std::get<0>(key)]; + for (auto const &[key, val] : this->attribute_list_) { + esp_zb_cluster_list_t *esp_zb_cluster_list = this->cluster_list_[std::get<0>(key)]; if (esphome_zb_cluster_list_add_or_update_cluster(std::get<1>(key), esp_zb_cluster_list, val, std::get<2>(key)) != ESP_OK) { ESP_LOGE(TAG, "Could not create cluster 0x%04X with role %u", std::get<1>(key), std::get<2>(key)); @@ -341,7 +342,7 @@ void ZigBeeComponent::esp_zb_task() { } // endpoints - for (auto const &[ep_id, dev_id] : this->endpoint_list) { + for (auto const &[ep_id, dev_id] : this->endpoint_list_) { // create_default_cluster(key, val); if (create_endpoint(ep_id, dev_id) != ESP_OK) { ESP_LOGE(TAG, "Could not create endpoint %u", ep_id); @@ -349,7 +350,7 @@ void ZigBeeComponent::esp_zb_task() { } // ------------------------------ Register Device ------------------------------ - if (esp_zb_device_register(this->esp_zb_ep_list) != ESP_OK) { + if (esp_zb_device_register(this->esp_zb_ep_list_) != ESP_OK) { ESP_LOGE(TAG, "Could not register the endpoint list"); this->mark_failed(); vTaskDelete(NULL); @@ -404,13 +405,13 @@ void ZigBeeComponent::setup() { this->mark_failed(); return; } - xTaskCreate([](void *arg) { static_cast(arg)->esp_zb_task(); }, "Zigbee_main", 4096, this, 24, + xTaskCreate([](void *arg) { static_cast(arg)->esp_zb_task_(); }, "Zigbee_main", 4096, this, 24, NULL); } void ZigBeeComponent::dump_config() { ESP_LOGCONFIG(TAG, "ZigBee:"); - for (auto const &[key, val] : this->endpoint_list) { + for (auto const &[key, val] : this->endpoint_list_) { ESP_LOGCONFIG(TAG, "Endpoint: %u, %d", key, val); } } diff --git a/esphome/components/zigbee/zigbee.h b/esphome/components/zigbee/zigbee.h index bbb2493105e7..8e7bcf3e0856 100644 --- a/esphome/components/zigbee/zigbee.h +++ b/esphome/components/zigbee/zigbee.h @@ -13,16 +13,16 @@ namespace esphome { namespace zigbee { -typedef struct device_params_s { +using device_params_t = struct DeviceParamsS { esp_zb_ieee_addr_t ieee_addr; uint8_t endpoint; uint16_t short_addr; -} device_params_t; +}; -typedef struct zdo_info_ctx_s { +using zdo_info_user_ctx_t = struct ZdoInfoCtxS { uint8_t endpoint; uint16_t short_addr; -} zdo_info_user_ctx_t; +}; /* Zigbee configuration */ #define INSTALLCODE_POLICY_ENABLE false /* enable the install code policy for security */ @@ -37,7 +37,7 @@ typedef struct zdo_info_ctx_s { #define ESP_ZB_DEFAULT_HOST_CONFIG() \ { .host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE, } -template T getValueByType(uint8_t attr_type, void *data); +template T get_value_by_type(uint8_t attr_type, void *data); class ZigBeeComponent : public Component { public: @@ -64,7 +64,7 @@ class ZigBeeComponent : public Component { } void report(); - void add_on_join_callback(std::function callback) { on_join_callback_.add(std::move(callback)); } + void add_on_join_callback(std::function &&callback) { this->on_join_callback_.add(std::move(callback)); } void add_on_value_callback( std::function callback) { on_value_callback_.add(std::move(callback)); @@ -75,15 +75,15 @@ class ZigBeeComponent : public Component { std::deque reporting_list; protected: - void esp_zb_task(); - esp_zb_attribute_list_t *create_ident_cluster(); - esp_zb_attribute_list_t *create_basic_cluster(); - bool connected = false; - std::map endpoint_list; - std::map cluster_list; - std::map, esp_zb_attribute_list_t *> attribute_list; - esp_zb_nwk_device_type_t device_role = ESP_ZB_DEVICE_TYPE_ED; - esp_zb_ep_list_t *esp_zb_ep_list = esp_zb_ep_list_create(); + void esp_zb_task_(); + esp_zb_attribute_list_t *create_ident_cluster_(); + esp_zb_attribute_list_t *create_basic_cluster_(); + bool connected_ = false; + std::map endpoint_list_; + std::map cluster_list_; + std::map, esp_zb_attribute_list_t *> attribute_list_; + esp_zb_nwk_device_type_t device_role_ = ESP_ZB_DEVICE_TYPE_ED; + esp_zb_ep_list_t *esp_zb_ep_list_ = esp_zb_ep_list_create(); struct { std::string model; std::string manufacturer; @@ -94,15 +94,15 @@ class ZigBeeComponent : public Component { uint8_t hw_version; std::string area; uint8_t physical_env; - } basic_cluster_data; - uint8_t ident_time; + } basic_cluster_data_; + uint8_t ident_time_; }; extern "C" void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct); template void ZigBeeComponent::add_attr(uint8_t endpoint_id, uint16_t cluster_id, uint8_t role, uint16_t attr_id, T value_p) { - esp_zb_attribute_list_t *attr_list = this->attribute_list[{endpoint_id, cluster_id, role}]; + esp_zb_attribute_list_t *attr_list = this->attribute_list_[{endpoint_id, cluster_id, role}]; esphome_zb_cluster_add_or_update_attr(cluster_id, attr_list, attr_id, &value_p); } diff --git a/esphome/components/zigbee/zigbee_helpers.h b/esphome/components/zigbee/zigbee_helpers.h index ad77979db8c1..242d284b6755 100644 --- a/esphome/components/zigbee/zigbee_helpers.h +++ b/esphome/components/zigbee/zigbee_helpers.h @@ -18,4 +18,9 @@ esp_err_t esphome_zb_cluster_add_or_update_attr(uint16_t cluster_id, esp_zb_attr #ifdef __cplusplus } + +namespace esphome { +namespace zigbee {} +} // namespace esphome + #endif