Clean Tuya code

This commit is contained in:
Theo Arends 2024-11-10 17:40:03 +01:00
parent fd7554d96e
commit 5f9912665a
3 changed files with 42 additions and 22 deletions

View File

@ -1580,19 +1580,6 @@ bool HandleRootStatusRefresh(void)
}
} else {
#endif // USE_SONOFF_IFAN
#ifdef USE_TUYA_MCU
if (IsModuleTuya()) {
if (device <= TasmotaGlobal.devices_present) {
ExecuteCommandPower(device, POWER_TOGGLE, SRC_IGNORE);
} else {
if (AsModuleTuyaMS() && device == TasmotaGlobal.devices_present + 1) {
uint8_t dpId = TuyaGetDpId(TUYA_MCU_FUNC_MODESET);
snprintf_P(svalue, sizeof(svalue), PSTR("Tuyasend4 %d,%d"), dpId, !TuyaModeSet());
ExecuteCommand(svalue, SRC_WEBGUI);
}
}
} else {
#endif // USE_TUYA_MCU
#ifdef USE_SHUTTER
int32_t ShutterWebButton;
if (ShutterWebButton = IsShutterWebButton(device)) {
@ -1607,9 +1594,6 @@ bool HandleRootStatusRefresh(void)
#ifdef USE_SONOFF_IFAN
}
#endif // USE_SONOFF_IFAN
#ifdef USE_TUYA_MCU
}
#endif // USE_TUYA_MCU
}
#ifdef USE_LIGHT
WebGetArg(PSTR("d0"), tmp, sizeof(tmp)); // 0 - 100 Dimmer value

View File

@ -1620,17 +1620,32 @@ void TuyaSensorsShow(bool json)
#ifdef USE_WEBSERVER
#define WEB_HANDLE_TUYA "d16"
void TuyaAddButton(void) {
if (AsModuleTuyaMS()) {
WSContentSend_P(HTTP_TABLE100);
char stemp[33];
snprintf_P(stemp, sizeof(stemp), PSTR("" D_JSON_IRHVAC_MODE ""));
WSContentSend_P(HTTP_DEVICE_CONTROL, 26, TasmotaGlobal.devices_present + 1, TasmotaGlobal.devices_present + 1,
(strlen(GetWebButton(TasmotaGlobal.devices_present))) ? HtmlEscape(GetWebButton(TasmotaGlobal.devices_present)).c_str() : stemp, "");
snprintf_P(stemp, sizeof(stemp), PSTR(D_JSON_IRHVAC_MODE));
WSContentSend_P(PSTR("<tr><td><button onclick='la(\"&" WEB_HANDLE_TUYA "=1\");'>%s</button></td>"), // &d16 is related to WebGetArg("d16", tmp, sizeof(tmp));
(strlen(GetWebButton(TasmotaGlobal.devices_present))) ? HtmlEscape(GetWebButton(TasmotaGlobal.devices_present)).c_str() : stemp);
WSContentSend_P(PSTR("</tr></table>"));
}
}
void TuyaWebGetArg(void) {
if (AsModuleTuyaMS()) {
char tmp[8]; // WebGetArg numbers only
WebGetArg(PSTR(WEB_HANDLE_TUYA), tmp, sizeof(tmp));
if (strlen(tmp)) {
uint8_t dpId = TuyaGetDpId(TUYA_MCU_FUNC_MODESET);
char svalue[32];
snprintf_P(svalue, sizeof(svalue), PSTR("Tuyasend4 %d,%d"), dpId, !TuyaModeSet());
ExecuteWebCommand(svalue);
}
}
}
#endif // USE_WEBSERVER
/*********************************************************************************************\
@ -1723,6 +1738,9 @@ bool Xdrv16(uint32_t function) {
case FUNC_WEB_ADD_MAIN_BUTTON:
TuyaAddButton();
break;
case FUNC_WEB_GET_ARG:
TuyaWebGetArg();
break;
case FUNC_WEB_SENSOR:
TuyaSensorsShow(0);
break;

View File

@ -2413,17 +2413,32 @@ void TuyaSensorsShow(bool json)
#ifdef USE_WEBSERVER
#define WEB_HANDLE_TUYA "d16"
void TuyaAddButton(void) {
if (AsModuleTuyaMS()) {
WSContentSend_P(HTTP_TABLE100);
char stemp[33];
snprintf_P(stemp, sizeof(stemp), PSTR("" D_JSON_IRHVAC_MODE ""));
WSContentSend_P(HTTP_DEVICE_CONTROL, 26, TasmotaGlobal.devices_present + 1, TasmotaGlobal.devices_present + 1,
(strlen(GetWebButton(TasmotaGlobal.devices_present))) ? HtmlEscape(GetWebButton(TasmotaGlobal.devices_present)).c_str() : stemp, "");
snprintf_P(stemp, sizeof(stemp), PSTR(D_JSON_IRHVAC_MODE));
WSContentSend_P(PSTR("<tr><td><button onclick='la(\"&" WEB_HANDLE_TUYA "=1\");'>%s</button></td>"), // &d16 is related to WebGetArg("d16", tmp, sizeof(tmp));
(strlen(GetWebButton(TasmotaGlobal.devices_present))) ? HtmlEscape(GetWebButton(TasmotaGlobal.devices_present)).c_str() : stemp);
WSContentSend_P(PSTR("</tr></table>"));
}
}
void TuyaWebGetArg(void) {
if (AsModuleTuyaMS()) {
char tmp[8]; // WebGetArg numbers only
WebGetArg(PSTR(WEB_HANDLE_TUYA), tmp, sizeof(tmp));
if (strlen(tmp)) {
uint8_t dpId = TuyaGetDpId(TUYA_MCU_FUNC_MODESET);
char svalue[32];
snprintf_P(svalue, sizeof(svalue), PSTR("Tuyasend4 %d,%d"), dpId, !TuyaModeSet());
ExecuteWebCommand(svalue);
}
}
}
#endif // USE_WEBSERVER
/*********************************************************************************************\
@ -2558,6 +2573,9 @@ bool Xdrv16(uint32_t function) {
case FUNC_WEB_ADD_MAIN_BUTTON:
TuyaAddButton();
break;
case FUNC_WEB_GET_ARG:
TuyaWebGetArg();
break;
case FUNC_WEB_SENSOR:
TuyaSensorsShow(0);
break;