Skip to content

Commit

Permalink
CI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
luar123 committed Nov 30, 2024
1 parent 6f12fe9 commit 0bf3673
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 89 deletions.
36 changes: 16 additions & 20 deletions esphome/components/zigbee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -200,31 +200,27 @@ 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"],
)
)
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]],
)
Expand All @@ -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],
Expand All @@ -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],
Expand All @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion esphome/components/zigbee/automation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ float get_b_from_xy(float x, float y) {
}

} // namespace zigbee
} // namespace esphome
} // namespace esphome
28 changes: 13 additions & 15 deletions esphome/components/zigbee/automation.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
namespace esphome {
namespace zigbee {

template<class T> T getValueByType(uint8_t attr_type, void *data);

class ZigBeeJoinTrigger : public Trigger<> {
public:
explicit ZigBeeJoinTrigger(ZigBeeComponent *parent) {
Expand Down Expand Up @@ -57,10 +55,10 @@ template<typename Ts> class ZigBeeOnValueTrigger : public Trigger<Ts>, 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) {
Expand All @@ -70,22 +68,22 @@ template<typename Ts> class ZigBeeOnValueTrigger : public Trigger<Ts>, 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<Ts>(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<Ts>(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<class T> T getValueByType(uint8_t attr_type, void *data) {
template<class T> 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;
Expand Down
71 changes: 36 additions & 35 deletions esphome/components/zigbee/zigbee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -265,91 +265,92 @@ 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));
}
}

// 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);
}
}

// ------------------------------ 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);
Expand Down Expand Up @@ -404,13 +405,13 @@ void ZigBeeComponent::setup() {
this->mark_failed();
return;
}
xTaskCreate([](void *arg) { static_cast<ZigBeeComponent *>(arg)->esp_zb_task(); }, "Zigbee_main", 4096, this, 24,
xTaskCreate([](void *arg) { static_cast<ZigBeeComponent *>(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);
}
}
Expand Down
Loading

0 comments on commit 0bf3673

Please sign in to comment.