Skip to content

Commit

Permalink
Fix MAX17043 invalid JSON (#19495)
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed Sep 11, 2023
1 parent 728b1b2 commit 597c365
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 8 additions & 4 deletions tasmota/tasmota_support/support_command.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 1 addition & 3 deletions tasmota/tasmota_xsns_sensor/xsns_110_max17043.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 597c365

Please # to comment.