diff --git a/tasmota/xdrv_23_zigbee_2_devices.ino b/tasmota/xdrv_23_zigbee_2_devices.ino index 991646d06..9a71075c0 100644 --- a/tasmota/xdrv_23_zigbee_2_devices.ino +++ b/tasmota/xdrv_23_zigbee_2_devices.ino @@ -72,7 +72,7 @@ typedef struct Z_Device { uint16_t hue; // last Hue: 0..359 uint16_t x, y; // last color [x,y] uint8_t linkquality; // lqi from last message, 0xFF means unknown - uint8_t batterypercentx2;// battery percentage x 2 (0..200), 0xFF means unknwon + uint8_t batterypercent; // battery percentage (0..100), 0xFF means unknwon } Z_Device; /*********************************************************************************************\ @@ -151,8 +151,8 @@ public: void setReachable(uint16_t shortaddr, bool reachable); void setLQI(uint16_t shortaddr, uint8_t lqi); uint8_t getLQI(uint16_t shortaddr) const; - void setBatteryPercentx2(uint16_t shortaddr, uint8_t bpx2); - uint8_t getBatteryPercentx2(uint16_t shortaddr) const; + void setBatteryPercent(uint16_t shortaddr, uint8_t bp); + uint8_t getBatteryPercent(uint16_t shortaddr) const; // get next sequence number for (increment at each all) uint8_t getNextSeqNumber(uint16_t shortaddr); @@ -642,17 +642,17 @@ uint8_t Z_Devices::getLQI(uint16_t shortaddr) const { return 0xFF; } -void Z_Devices::setBatteryPercentx2(uint16_t shortaddr, uint8_t bpx2) { +void Z_Devices::setBatteryPercent(uint16_t shortaddr, uint8_t bp) { Z_Device & device = getShortAddr(shortaddr); if (&device == nullptr) { return; } // don't crash if not found - device.batterypercentx2 = bpx2; + device.batterypercent = bp; } -uint8_t Z_Devices::getBatteryPercentx2(uint16_t shortaddr) const { +uint8_t Z_Devices::getBatteryPercent(uint16_t shortaddr) const { int32_t found = findShortAddr(shortaddr); if (found >= 0) { const Z_Device & device = devicesAt(found); - return device.batterypercentx2; + return device.batterypercent; } return 0xFF; } diff --git a/tasmota/xdrv_23_zigbee_5_converters.ino b/tasmota/xdrv_23_zigbee_5_converters.ino index 9488918b3..4456c177f 100644 --- a/tasmota/xdrv_23_zigbee_5_converters.ino +++ b/tasmota/xdrv_23_zigbee_5_converters.ino @@ -1187,7 +1187,7 @@ int32_t Z_ModelKeepFunc(const class ZCLFrame *zcl, uint16_t shortaddr, JsonObjec } // Record BatteryPercentage int32_t Z_BatteryPercentageKeepFunc(const class ZCLFrame *zcl, uint16_t shortaddr, JsonObject& json, const char *name, JsonVariant& value, const String &new_name, uint16_t cluster, uint16_t attr) { - zigbee_devices.setBatteryPercentx2(shortaddr, value.as()); + zigbee_devices.setBatteryPercent(shortaddr, json[new_name]); return 1; } @@ -1343,7 +1343,7 @@ int32_t Z_AqaraSensorFunc(const class ZCLFrame *zcl, uint16_t shortaddr, JsonObj json[F("BatteryVoltage")] = batteryvoltage; uint8_t batterypercentage = toPercentageCR2032(val); json[F("BatteryPercentage")] = batterypercentage; - zigbee_devices.setBatteryPercentx2(shortaddr, batterypercentage * 2); + zigbee_devices.setBatteryPercent(shortaddr, batterypercentage); // deprecated json[F(D_JSON_VOLTAGE)] = batteryvoltage; json[F("Battery")] = toPercentageCR2032(val); diff --git a/tasmota/xdrv_23_zigbee_A_impl.ino b/tasmota/xdrv_23_zigbee_A_impl.ino index 489aece50..315ad7d74 100644 --- a/tasmota/xdrv_23_zigbee_A_impl.ino +++ b/tasmota/xdrv_23_zigbee_A_impl.ino @@ -1094,6 +1094,11 @@ void ZigbeeShow(bool json) if (0xFF != lqi) { snprintf_P(spart2, sizeof(spart2), PSTR("%d"), lqi); } + // uint8_t bp = zigbee_devices.getBatteryPercentx2(shortaddr); + // Be aware that bp + // if (0xFF != bp) { + // snprintf_P(spart2, sizeof(spart2), PSTR("%d"), bp); + // } WSContentSend_PD(PSTR("{s}%s{m}LQI %s{e}"), name, spart2); }