diff --git a/CHANGELOG.md b/CHANGELOG.md index b45515f60..a4100cd7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file. ### Fixed - Refactor energy monitoring reducing stack usage and solve inherent exceptions and watchdogs (#18164) +- Berry fix `tasmota.get_power(index)` ### Removed diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino index bea6cdbe0..842d8804a 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino @@ -708,17 +708,25 @@ extern "C" { int32_t l_getpower(bvm *vm) { power_t pow = TasmotaGlobal.power; int32_t top = be_top(vm); // Get the number of arguments - if (top == 2 && be_isint(vm, 2)) { - pow = be_toint(vm, 2); - } - be_newobject(vm, "list"); - for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) { - be_pushbool(vm, bitRead(pow, i)); - be_data_push(vm, -2); + if (top >= 2 && be_isint(vm, 2)) { + int32_t idx = be_toint(vm, 2); + if (idx >= 0 && idx < TasmotaGlobal.devices_present) { + be_pushbool(vm, bitRead(pow, idx)); + be_return(vm); + } else { + be_return_nil(vm); + } + } else { + // no parameter, return an array of all values + be_newobject(vm, "list"); + for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) { + be_pushbool(vm, bitRead(pow, i)); + be_data_push(vm, -2); + be_pop(vm, 1); + } be_pop(vm, 1); + be_return(vm); // Return } - be_pop(vm, 1); - be_return(vm); // Return } int32_t l_setpower(bvm *vm);