mirror of
https://github.com/esphome/esphome.git
synced 2026-06-24 13:27:14 +00:00
[zigbee] Add power_source option to esp32 (#16062)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
@@ -87,9 +87,8 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
),
|
),
|
||||||
cv.requires_component("nrf52"),
|
cv.requires_component("nrf52"),
|
||||||
),
|
),
|
||||||
cv.OnlyWith(CONF_POWER_SOURCE, "nrf52", default="DC_SOURCE"): cv.All(
|
cv.Optional(CONF_POWER_SOURCE, default="DC_SOURCE"): cv.enum(
|
||||||
cv.enum(POWER_SOURCE, upper=True),
|
POWER_SOURCE, upper=True
|
||||||
cv.requires_component("nrf52"),
|
|
||||||
),
|
),
|
||||||
cv.Optional(CONF_IEEE802154_VENDOR_OUI): cv.All(
|
cv.Optional(CONF_IEEE802154_VENDOR_OUI): cv.All(
|
||||||
cv.Any(
|
cv.Any(
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ void ZigbeeComponent::add_cluster(uint8_t endpoint_id, uint16_t cluster_id, uint
|
|||||||
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(const char *model, const char *manufacturer) {
|
void ZigbeeComponent::set_basic_cluster(const char *model, const char *manufacturer, uint8_t power_source) {
|
||||||
char date_buf[16];
|
char date_buf[16];
|
||||||
time_t time_val = App.get_build_time();
|
time_t time_val = App.get_build_time();
|
||||||
struct tm *timeinfo = localtime(&time_val);
|
struct tm *timeinfo = localtime(&time_val);
|
||||||
@@ -162,13 +162,14 @@ void ZigbeeComponent::set_basic_cluster(const char *model, const char *manufactu
|
|||||||
.model = get_zcl_string(model, 31),
|
.model = get_zcl_string(model, 31),
|
||||||
.manufacturer = get_zcl_string(manufacturer, 31),
|
.manufacturer = get_zcl_string(manufacturer, 31),
|
||||||
.date = get_zcl_string(date_buf, 15),
|
.date = get_zcl_string(date_buf, 15),
|
||||||
|
.power_source = power_source,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_zb_attribute_list_t *ZigbeeComponent::create_basic_cluster_() {
|
esp_zb_attribute_list_t *ZigbeeComponent::create_basic_cluster_() {
|
||||||
esp_zb_basic_cluster_cfg_t basic_cluster_cfg = {
|
esp_zb_basic_cluster_cfg_t basic_cluster_cfg = {
|
||||||
.zcl_version = ESP_ZB_ZCL_BASIC_ZCL_VERSION_DEFAULT_VALUE,
|
.zcl_version = ESP_ZB_ZCL_BASIC_ZCL_VERSION_DEFAULT_VALUE,
|
||||||
.power_source = 0,
|
.power_source = this->basic_cluster_data_.power_source,
|
||||||
};
|
};
|
||||||
esp_zb_attribute_list_t *attr_list = esp_zb_basic_cluster_create(&basic_cluster_cfg);
|
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_MANUFACTURER_NAME_ID,
|
esp_zb_basic_cluster_add_attr(attr_list, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID,
|
||||||
@@ -192,7 +193,12 @@ static void esp_zb_task_(void *pvParameters) {
|
|||||||
ESP_LOGE(TAG, "Could not setup Zigbee");
|
ESP_LOGE(TAG, "Could not setup Zigbee");
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
esp_zb_set_node_descriptor_power_source(1);
|
if (global_zigbee->is_battery_powered()) {
|
||||||
|
ESP_LOGD(TAG, "Battery powered!");
|
||||||
|
esp_zb_set_node_descriptor_power_source(0);
|
||||||
|
} else {
|
||||||
|
esp_zb_set_node_descriptor_power_source(1);
|
||||||
|
}
|
||||||
esp_zb_stack_main_loop();
|
esp_zb_stack_main_loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class ZigbeeComponent : public Component {
|
|||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
esp_err_t create_endpoint(uint8_t endpoint_id, zb_ha_standard_devs_e device_id,
|
esp_err_t create_endpoint(uint8_t endpoint_id, zb_ha_standard_devs_e device_id,
|
||||||
esp_zb_cluster_list_t *esp_zb_cluster_list);
|
esp_zb_cluster_list_t *esp_zb_cluster_list);
|
||||||
void set_basic_cluster(const char *model, const char *manufacturer);
|
void set_basic_cluster(const char *model, const char *manufacturer, uint8_t power_source);
|
||||||
void add_cluster(uint8_t endpoint_id, uint16_t cluster_id, uint8_t role);
|
void add_cluster(uint8_t endpoint_id, uint16_t cluster_id, uint8_t role);
|
||||||
void create_default_cluster(uint8_t endpoint_id, zb_ha_standard_devs_e device_id);
|
void create_default_cluster(uint8_t endpoint_id, zb_ha_standard_devs_e device_id);
|
||||||
|
|
||||||
@@ -62,6 +62,7 @@ class ZigbeeComponent : public Component {
|
|||||||
|
|
||||||
template<typename F> void add_on_join_callback(F &&cb) { this->join_cb_.add(std::forward<F>(cb)); }
|
template<typename F> void add_on_join_callback(F &&cb) { this->join_cb_.add(std::forward<F>(cb)); }
|
||||||
|
|
||||||
|
bool is_battery_powered() { return this->basic_cluster_data_.power_source == ESP_ZB_ZCL_BASIC_POWER_SOURCE_BATTERY; }
|
||||||
bool is_started() { return this->started; }
|
bool is_started() { return this->started; }
|
||||||
bool is_connected() { return this->connected_; }
|
bool is_connected() { return this->connected_; }
|
||||||
std::atomic<bool> started = false;
|
std::atomic<bool> started = false;
|
||||||
@@ -73,6 +74,7 @@ class ZigbeeComponent : public Component {
|
|||||||
uint8_t *model;
|
uint8_t *model;
|
||||||
uint8_t *manufacturer;
|
uint8_t *manufacturer;
|
||||||
uint8_t *date;
|
uint8_t *date;
|
||||||
|
uint8_t power_source;
|
||||||
} basic_cluster_data_;
|
} basic_cluster_data_;
|
||||||
bool connected_ = false;
|
bool connected_ = false;
|
||||||
#ifdef ZB_ED_ROLE
|
#ifdef ZB_ED_ROLE
|
||||||
|
|||||||
@@ -36,9 +36,11 @@ from .const import (
|
|||||||
ANALOG_INPUT_APPTYPE,
|
ANALOG_INPUT_APPTYPE,
|
||||||
BACNET_UNIT_NO_UNITS,
|
BACNET_UNIT_NO_UNITS,
|
||||||
BACNET_UNITS,
|
BACNET_UNITS,
|
||||||
|
CONF_POWER_SOURCE,
|
||||||
CONF_REPORT,
|
CONF_REPORT,
|
||||||
CONF_ROUTER,
|
CONF_ROUTER,
|
||||||
KEY_ZIGBEE,
|
KEY_ZIGBEE,
|
||||||
|
POWER_SOURCE,
|
||||||
REPORT,
|
REPORT,
|
||||||
ZigbeeAttribute,
|
ZigbeeAttribute,
|
||||||
)
|
)
|
||||||
@@ -320,6 +322,7 @@ async def esp32_to_code(config: ConfigType) -> "MockObj":
|
|||||||
var.set_basic_cluster(
|
var.set_basic_cluster(
|
||||||
config[CONF_MODEL],
|
config[CONF_MODEL],
|
||||||
"esphome",
|
"esphome",
|
||||||
|
cg.RawExpression(POWER_SOURCE[config[CONF_POWER_SOURCE]]),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
for ep in ep_list:
|
for ep in ep_list:
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ binary_sensor:
|
|||||||
zigbee:
|
zigbee:
|
||||||
model: zigbee_test
|
model: zigbee_test
|
||||||
router: true
|
router: true
|
||||||
|
power_source: MAINS_SINGLE_PHASE
|
||||||
on_join:
|
on_join:
|
||||||
then:
|
then:
|
||||||
- logger.log: "Joined network"
|
- logger.log: "Joined network"
|
||||||
|
|||||||
Reference in New Issue
Block a user