tuya-dimmer: Fix dimmer skipping power/dimmer commands

This tuya dimmer mcu sends data for multiple dimmer ids which breaks `tuya_ignore_dim` logic and sometimes when `power on` is sent its blocked due to multiple serial commands being sent at the same time. This patch makes sure we send dimmer commands only when we need to.
Bug is explained in https://github.com/arendst/Sonoff-Tasmota/issues/6215#issuecomment-521191828
This commit is contained in:
Shantur Rathore 2019-08-14 13:53:46 +01:00
parent 52ec4b93f3
commit f08e7ff5df
1 changed files with 15 additions and 11 deletions

View File

@ -149,8 +149,10 @@ void LightSerialDuty(uint8_t duty)
if(Settings.flag3.tuya_dimmer_range_255 == 0) { if(Settings.flag3.tuya_dimmer_range_255 == 0) {
duty = changeUIntScale(duty, 0, 255, 0, 100); duty = changeUIntScale(duty, 0, 255, 0, 100);
} }
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim value=%d (id=%d)"), duty, Settings.param[P_TUYA_DIMMER_ID]); if (tuya_new_dim != duty) {
TuyaSendValue(Settings.param[P_TUYA_DIMMER_ID], duty); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim value=%d (id=%d)"), duty, Settings.param[P_TUYA_DIMMER_ID]);
TuyaSendValue(Settings.param[P_TUYA_DIMMER_ID], duty);
}
} }
} else { } else {
tuya_ignore_dim = false; // reset flag tuya_ignore_dim = false; // reset flag
@ -215,16 +217,18 @@ void TuyaPacketProcess(void)
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Autoconfiguring Dimmer ID %d"), tuya_buffer[6]); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Autoconfiguring Dimmer ID %d"), tuya_buffer[6]);
Settings.param[P_TUYA_DIMMER_ID] = tuya_buffer[6]; Settings.param[P_TUYA_DIMMER_ID] = tuya_buffer[6];
} }
if(Settings.flag3.tuya_dimmer_range_255 == 0) { if (Settings.param[P_TUYA_DIMMER_ID] == tuya_buffer[6]) {
tuya_new_dim = (uint8_t) tuya_buffer[13]; if(Settings.flag3.tuya_dimmer_range_255 == 0) {
} else { tuya_new_dim = (uint8_t) tuya_buffer[13];
tuya_new_dim = changeUIntScale((uint8_t) tuya_buffer[13], 0, 255, 0, 100); } else {
} tuya_new_dim = changeUIntScale((uint8_t) tuya_buffer[13], 0, 255, 0, 100);
if ((power || Settings.flag3.tuya_apply_o20) && (tuya_new_dim > 0) && (abs(tuya_new_dim - Settings.light_dimmer) > 1)) { }
tuya_ignore_dim = true; if ((power || Settings.flag3.tuya_apply_o20) && (tuya_new_dim > 0) && (abs(tuya_new_dim - Settings.light_dimmer) > 1)) {
tuya_ignore_dim = true;
snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_DIMMER " %d"), tuya_new_dim ); snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_DIMMER " %d"), tuya_new_dim );
ExecuteCommand(scmnd, SRC_SWITCH); ExecuteCommand(scmnd, SRC_SWITCH);
}
} }
} }
} }