From 3c884118ed8e3f7f1ac8d95536babce3aabb0300 Mon Sep 17 00:00:00 2001 From: s-hadinger <49731213+s-hadinger@users.noreply.github.com> Date: Fri, 2 Aug 2024 19:42:11 +0200 Subject: [PATCH] Berry `zigbee.started()` (#21895) --- CHANGELOG.md | 1 + lib/libesp32/berry_tasmota/src/be_zigbee.c | 3 +++ .../tasmota_xdrv_driver/xdrv_23_zigbee_A_impl.ino | 2 +- .../xdrv_52_3_berry_zigbee.ino | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91f9e9e7b..ec6ad0a97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file. - Berry `file.savecode()` (#21884) - Berry `solidify.nocompact()` and reduce size of Matter UI (#21885) - Berry `zigbee.find()` +- Berry `zigbee.started()` ### Breaking Changed - Berry `energy` module support for 8 phases and move to pseudo-arrays (#21887) diff --git a/lib/libesp32/berry_tasmota/src/be_zigbee.c b/lib/libesp32/berry_tasmota/src/be_zigbee.c index 0f4510aaf..7ec6f7bba 100644 --- a/lib/libesp32/berry_tasmota/src/be_zigbee.c +++ b/lib/libesp32/berry_tasmota/src/be_zigbee.c @@ -49,6 +49,7 @@ static int zd_member(bvm *vm) { be_return(vm); } +extern int zc_started(struct bvm *vm); extern int zc_info(struct bvm *vm); extern int zc_item(struct bvm *vm); extern int zc_find(struct bvm *vm); @@ -112,6 +113,8 @@ class be_class_zb_coord_ntv (scope: global, name: zb_coord_ntv, strings: weak) { zcl_attribute_list, class(be_class_zcl_attribute_list) zb_device, class(be_class_zb_device) + started, func(zc_started) + info, func(zc_info) item, func(zc_item) find, func(zc_find) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_A_impl.ino b/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_A_impl.ino index f010d2a2a..040a59d1a 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_A_impl.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_23_zigbee_A_impl.ino @@ -2426,7 +2426,7 @@ void ZigbeeShow(bool json) zigbee.major_rel, zigbee.minor_rel, zigbee.maint_rel, zigbee.revision); WSContentSend_P(HTTP_BTN_ZB_BUTTONS); - } else { + } else if (zigbee.state_machine) { // show buttons only if the state machine is still running. If not running anymore, it means aborted uint32_t grey = WebColor(COL_FORM); WSContentSend_P(HTTP_BTN_ZB_BUTTONS_DISABLED, grey, grey); } diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_zigbee.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_zigbee.ino index 390859afe..e2c9d3fb8 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_zigbee.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_zigbee.ino @@ -75,6 +75,21 @@ extern "C" { extern "C" { // Zigbee Coordinator `zc` + + // `zigbee.started() -> bool or nil` + // Returns `true` if Zigbee sucessfully started, `false` if not yet started + // or `nil` if not configured or aborted + int zc_started(struct bvm *vm); + int zc_started(struct bvm *vm) { + // return `nil` if `zigbee.active` is false (i.e. no GPIO configured) + // or aborted, `zigbee.init_phase` is `true` but `zigbee.state_machine` is `false` + if (!zigbee.active || (!zigbee.state_machine && zigbee.init_phase)) { + be_return_nil(vm); + } + be_pushbool(vm, !zigbee.init_phase); + be_return(vm); + } + int zc_info(struct bvm *vm); int zc_info(struct bvm *vm) { int32_t top = be_top(vm); // Get the number of arguments