diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index e2942945b..3c26923c5 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -76,48 +76,47 @@ const char kWifiConfig[] PROGMEM = /********************************************************************************************/ -void ResponseCmndNumber(int value) -{ +void ResponseCmndNumber(int value) { Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, value); } -void ResponseCmndFloat(float value, uint32_t decimals) -{ +void ResponseCmndFloat(float value, uint32_t decimals) { Response_P(PSTR("{\"%s\":%*_f}"), XdrvMailbox.command, decimals, &value); // Return float value without quotes } -void ResponseCmndIdxNumber(int value) -{ +void ResponseCmndIdxNumber(int value) { Response_P(S_JSON_COMMAND_INDEX_NVALUE, XdrvMailbox.command, XdrvMailbox.index, value); } -void ResponseCmndChar_P(const char* value) -{ +void ResponseCmndChar_P(const char* value) { Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, value); } -void ResponseCmndChar(const char* value) -{ +void ResponseCmndChar(const char* value) { Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, EscapeJSONString(value).c_str()); } -void ResponseCmndStateText(uint32_t value) -{ +void ResponseCmndStateText(uint32_t value) { ResponseCmndChar(GetStateText(value)); } -void ResponseCmndDone(void) -{ - ResponseCmndChar(PSTR(D_JSON_DONE)); +void ResponseCmndDone(void) { + ResponseCmndChar_P(PSTR(D_JSON_DONE)); } -void ResponseCmndIdxChar(const char* value) -{ +void ResponseCmndError(void) { + ResponseCmndChar_P(PSTR(D_JSON_ERROR)); +} + +void ResponseCmndIdxChar(const char* value) { Response_P(S_JSON_COMMAND_INDEX_SVALUE, XdrvMailbox.command, XdrvMailbox.index, EscapeJSONString(value).c_str()); } -void ResponseCmndAll(uint32_t text_index, uint32_t count) -{ +void ResponseCmndIdxError(void) { + ResponseCmndIdxChar(PSTR(D_JSON_ERROR)); +} + +void ResponseCmndAll(uint32_t text_index, uint32_t count) { uint32_t real_index = text_index; ResponseClear(); for (uint32_t i = 0; i < count; i++) { diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index 1c3345fd7..fc52aee8a 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -2297,7 +2297,7 @@ void CmndScale(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_RULE_VARS)) { if (XdrvMailbox.data_len > 0) { - if (ArgC() > 1) { // Process parameter entry + if (ArgC() == 5) { // Process parameter entry char argument[XdrvMailbox.data_len]; float valueIN = CharToFloat(ArgV(argument, 1)); @@ -2308,6 +2308,9 @@ void CmndScale(void) float value = map_double(valueIN, fromLow, fromHigh, toLow, toHigh); dtostrfd(value, Settings.flag2.calc_resolution, rules_vars[XdrvMailbox.index -1]); bitSet(Rules.vars_event, XdrvMailbox.index -1); + } else { + ResponseCmndIdxError(); + return; } } ResponseCmndIdxChar(rules_vars[XdrvMailbox.index -1]); diff --git a/tasmota/xdrv_11_knx.ino b/tasmota/xdrv_11_knx.ino index afddce071..445bcf0f0 100644 --- a/tasmota/xdrv_11_knx.ino +++ b/tasmota/xdrv_11_knx.ino @@ -1189,7 +1189,7 @@ void CmndKnxPa(void) if ( ((pa_area == 0) && (pa_line == 0) && (pa_member == 0)) || (pa_area > 15) || (pa_line > 15) || (pa_member > 255) ) { - Response_P (PSTR("{\"%s\":\"" D_ERROR "\"}"), XdrvMailbox.command ); + ResponseCmndError(); return; } // Invalid command @@ -1220,7 +1220,7 @@ void CmndKnxGa(void) || (ga_area > 31) || (ga_line > 7) || (ga_member > 255) || (ga_option < 0) || ((ga_option > KNX_MAX_device_param ) && (ga_option != KNX_Empty)) || (!device_param[ga_option-1].show) ) { - Response_P (PSTR("{\"%s\":\"" D_ERROR "\"}"), XdrvMailbox.command ); + ResponseCmndIdxError(); return; } // Invalid command @@ -1239,7 +1239,7 @@ void CmndKnxGa(void) if ( (XdrvMailbox.payload <= Settings.knx_GA_registered) && (XdrvMailbox.payload > 0) ) { XdrvMailbox.index = XdrvMailbox.payload; } else { - Response_P (PSTR("{\"%s\":\"" D_ERROR "\"}"), XdrvMailbox.command ); + ResponseCmndIdxError(); return; } } @@ -1250,7 +1250,7 @@ void CmndKnxGa(void) KNX_addr.ga.area, KNX_addr.ga.line, KNX_addr.ga.member ); } } else { - ResponseCmndNumber (Settings.knx_GA_registered ); + ResponseCmndIdxNumber (Settings.knx_GA_registered ); } } } @@ -1271,7 +1271,7 @@ void CmndKnxCb(void) || (cb_area > 31) || (cb_line > 7) || (cb_member > 255) || (cb_option < 0) || ((cb_option > KNX_MAX_device_param ) && (cb_option != KNX_Empty)) || (!device_param[cb_option-1].show) ) { - Response_P (PSTR("{\"%s\":\"" D_ERROR "\"}"), XdrvMailbox.command ); + ResponseCmndIdxError(); return; } // Invalid command @@ -1290,7 +1290,7 @@ void CmndKnxCb(void) if ( (XdrvMailbox.payload <= Settings.knx_CB_registered) && (XdrvMailbox.payload > 0) ) { XdrvMailbox.index = XdrvMailbox.payload; } else { - Response_P (PSTR("{\"%s\":\"" D_ERROR "\"}"), XdrvMailbox.command ); + ResponseCmndIdxError(); return; } } @@ -1301,7 +1301,7 @@ void CmndKnxCb(void) KNX_addr.ga.area, KNX_addr.ga.line, KNX_addr.ga.member ); } } else { - ResponseCmndNumber (Settings.knx_CB_registered ); + ResponseCmndIdxNumber (Settings.knx_CB_registered ); } } } diff --git a/tasmota/xdrv_29_deepsleep.ino b/tasmota/xdrv_29_deepsleep.ino index 45da79cb2..48e1b727a 100644 --- a/tasmota/xdrv_29_deepsleep.ino +++ b/tasmota/xdrv_29_deepsleep.ino @@ -188,7 +188,7 @@ void CmndDeepsleepTime(void) } } } - Response_P(S_JSON_COMMAND_NVALUE, XdrvMailbox.command, Settings.deepsleep); + ResponseCmndNumber(Settings.deepsleep); } /*********************************************************************************************\