From 86314e24e55adad217d0047acd4de97444354ebb Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 8 Jul 2019 12:42:46 +0200 Subject: [PATCH] Fix ambiguous Tuya set relay option by adding command SetOption41 allowing to control number of virtual relays Fix ambiguous Tuya set relay option by adding command SetOption41 allowing to control number of virtual relays (#6039) --- sonoff/sonoff.h | 2 +- sonoff/sonoff.ino | 10 +++++++++- sonoff/xdrv_16_tuyadimmer.ino | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 8d23d1771..7ecebaa79 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -230,7 +230,7 @@ enum ButtonStates { PRESSED, NOT_PRESSED }; enum Shortcuts { SC_CLEAR, SC_DEFAULT, SC_USER }; -enum SettingsParmaIndex {P_HOLD_TIME, P_MAX_POWER_RETRY, P_TUYA_DIMMER_ID, P_MDNS_DELAYED_START, P_BOOT_LOOP_OFFSET, P_RGB_REMAP, P_IR_UNKNOW_THRESHOLD, P_CSE7766_INVALID_POWER, P_HOLD_IGNORE, P_MAX_PARAM8}; // Max is PARAM8_SIZE (18) - SetOption32 until SetOption49 +enum SettingsParmaIndex {P_HOLD_TIME, P_MAX_POWER_RETRY, P_TUYA_DIMMER_ID, P_MDNS_DELAYED_START, P_BOOT_LOOP_OFFSET, P_RGB_REMAP, P_IR_UNKNOW_THRESHOLD, P_CSE7766_INVALID_POWER, P_HOLD_IGNORE, P_TUYA_RELAYS, P_MAX_PARAM8}; // Max is PARAM8_SIZE (18) - SetOption32 until SetOption49 enum DomoticzSensors {DZ_TEMP, DZ_TEMP_HUM, DZ_TEMP_HUM_BARO, DZ_POWER_ENERGY, DZ_ILLUMINANCE, DZ_COUNT, DZ_VOLTAGE, DZ_CURRENT, DZ_AIRQUALITY, DZ_MAX_SENSORS}; diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 5a26a86c6..ccfaaccef 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -850,12 +850,15 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len) param_low = 1; param_high = 250; break; + case P_TUYA_RELAYS: + param_high = 8; + break; } if ((payload >= param_low) && (payload <= param_high)) { Settings.param[pindex] = payload; switch (pindex) { #ifdef USE_LIGHT - case P_RGB_REMAP: + case P_RGB_REMAP: LightUpdateColorMapping(); break; #endif @@ -863,6 +866,11 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len) case P_IR_UNKNOW_THRESHOLD: IrReceiveUpdateThreshold(); break; +#endif +#ifdef USE_TUYA_DIMMER + case P_TUYA_RELAYS: + restart_flag = 2; // Need a restart to update GUI + break; #endif } } diff --git a/sonoff/xdrv_16_tuyadimmer.ino b/sonoff/xdrv_16_tuyadimmer.ino index e09b15a39..7f26e035c 100644 --- a/sonoff/xdrv_16_tuyadimmer.ino +++ b/sonoff/xdrv_16_tuyadimmer.ino @@ -282,7 +282,7 @@ bool TuyaModuleSelected(void) void TuyaInit(void) { - devices_present = Settings.param[6] == 0 ? 1 : Settings.param[6]; + devices_present += Settings.param[P_TUYA_RELAYS]; // SetOption41 - Add virtual relays if present if (!Settings.param[P_TUYA_DIMMER_ID]) { Settings.param[P_TUYA_DIMMER_ID] = TUYA_DIMMER_ID; }