From 597c3655b068a8a3970191a5d1710515d4f94424 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 11 Sep 2023 11:35:26 +0200 Subject: [PATCH] Fix MAX17043 invalid JSON (#19495) --- tasmota/tasmota_support/support_command.ino | 12 ++++++++---- tasmota/tasmota_xsns_sensor/xsns_110_max17043.ino | 4 +--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tasmota/tasmota_support/support_command.ino b/tasmota/tasmota_support/support_command.ino index 9fb41fa3e..674440696 100644 --- a/tasmota/tasmota_support/support_command.ino +++ b/tasmota/tasmota_support/support_command.ino @@ -249,11 +249,15 @@ void CmndWifiTest(void) #endif //USE_WEBSERVER } -void CmndBatteryPercent(void) { - if (XdrvMailbox.payload > 101) XdrvMailbox.payload = 100; - if (XdrvMailbox.payload >= 0) { - Settings->battery_level_percent = XdrvMailbox.payload; +void UpdateBatteryPercent(int batt_percentage) { + if (batt_percentage > 101) { batt_percentage = 100; } + if (batt_percentage >= 0) { + Settings->battery_level_percent = batt_percentage; } +} + +void CmndBatteryPercent(void) { + UpdateBatteryPercent(XdrvMailbox.payload); ResponseCmndNumber(Settings->battery_level_percent); } diff --git a/tasmota/tasmota_xsns_sensor/xsns_110_max17043.ino b/tasmota/tasmota_xsns_sensor/xsns_110_max17043.ino index 3e9a64a74..542f27642 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_110_max17043.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_110_max17043.ino @@ -108,9 +108,7 @@ void Max17043Show(bool json) { // only update the system percentage if it's changed battery_current = int(round(percentage)); if (battery_latest != battery_current) { - char cmnd[30]; - sprintf(cmnd, "%s %d", D_CMND_ZIGBEE_BATTPERCENT, battery_current); - ExecuteCommand(cmnd, SRC_SENSOR); + UpdateBatteryPercent(battery_current); battery_latest = battery_current; } if (json) {