From ab9baf2ac074280ea3fb3b008d8878cae66b547d Mon Sep 17 00:00:00 2001 From: thirug010 <30732819+thirug010@users.noreply.github.com> Date: Wed, 22 May 2019 01:28:38 -0500 Subject: [PATCH] Resolved conflit and Updated the code Skop dimmer packets for non-dimmer configuration 1. Rsolved the build conflict on sonoff/_changelog.ino tools/decode-config.py 2. Updated the code Skop dimmer packets for non-dimmer configuration --- sonoff/_changelog.ino | 18 ++++++-- sonoff/xdrv_16_tuyadimmer.ino | 24 +++++----- tools/decode-config.py | 82 +++++++++++++++++++---------------- 3 files changed, 71 insertions(+), 53 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index de056c030..530805bf7 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,15 +1,25 @@ /* - * 6.5.0.14 20190520 - * Updated xdrv_16_tuyadimmer.ino repalced TuyGetPower with bitRead() - * - * 6.5.0.12 20190517 + * 6.5.0.13 20190517 * Add command SetOption65 (tuya_show_dimmer) to enable or disable dimmer Slider ( for 4 Gang Tuya switch) * Added Seeting.pram9 to define no of Tuya MCU devices * Updated xdrv_01_webserver.ino to check for the tuya_show_dimmer option to display slider2 * Updated xdrv_16_tuyadimmer.ino create bool serial packet based on the Device Id and set the power status based on the Device id from MCU packet + * Updated xdrv_16_tuyadimmer.ino skip dimmer packets for device configured as non - dimmer + * + * 6.5.0.12 20190521 + * Add AriLux RF control GPIO option "ALux IrSel" (159) replacing "Led4i" (59) for full LED control (#5709) + * Add LED GPIO option "LedLink" (157) and "LedLinki" (158) to select dedicated link status LED (#5709) + * Add support for up to four LEDs related to four power outputs. Enabled when "LedLink(i)" is configured too (#5709) + * Add extended LED power control using command LedPowerX where X is 1 to 4. Enabled when "LedLink(i)" is configured too (#5709) * * 6.5.0.11 20190517 * Add command SetOption64 0/1 to switch between "-" or "_" as sensor index separator impacting DS18X20, DHT, BMP and SHT3X sensor names (#5689) + * Add initial support for Scripts as replacement for Rules. Default disabled but can be enabled in my_user_config.h (#5689) + * Add rule System#Save executed just before a planned restart + * Add HX711 weight restore after controlled restart or after power restore just before executing command Sensor34 7 (#5367, #5786) + * Remove define USE_EMULATION from my_user_config.h (#5826) + * Add defines USE_EMULATION_WEMO and USE_EMULATION_HUE to my_user_config.h to control emulation features at compile time (#5826) + * Add support for SPS30 Particle sensor thanks to Gerhard Mutz (#5830) * * 6.5.0.10 20190513 * Enable ADC0 by default in my_user_config.h (#5671) diff --git a/sonoff/xdrv_16_tuyadimmer.ino b/sonoff/xdrv_16_tuyadimmer.ino index 6e16efc51..667d0d458 100644 --- a/sonoff/xdrv_16_tuyadimmer.ino +++ b/sonoff/xdrv_16_tuyadimmer.ino @@ -207,21 +207,23 @@ void TuyaPacketProcess(void) else if (tuya_buffer[5] == 8) { // dim packet AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Dim State=%d"), tuya_buffer[13]); + if(Settings.flag3.tuya_show_dimmer == 0) // + { + if (!Settings.param[P_TUYA_DIMMER_ID]) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Autoconfiguring Dimmer ID %d"), tuya_buffer[6]); + Settings.param[P_TUYA_DIMMER_ID] = tuya_buffer[6]; + } - if (!Settings.param[P_TUYA_DIMMER_ID]) { - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Autoconfiguring Dimmer ID %d"), tuya_buffer[6]); - Settings.param[P_TUYA_DIMMER_ID] = tuya_buffer[6]; - } + tuya_new_dim = round(tuya_buffer[13] * (100. / 255.)); + if((power || Settings.flag3.tuya_apply_o20) && (tuya_new_dim > 0) && (abs(tuya_new_dim - Settings.light_dimmer) > 1)) { - tuya_new_dim = round(tuya_buffer[13] * (100. / 255.)); - if((power || Settings.flag3.tuya_apply_o20) && (tuya_new_dim > 0) && (abs(tuya_new_dim - Settings.light_dimmer) > 1)) { + 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 ); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send CMND_DIMMER_STR=%s"), scmnd ); - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send CMND_DIMMER_STR=%s"), scmnd ); - - tuya_ignore_dim = true; - ExecuteCommand(scmnd, SRC_SWITCH); + tuya_ignore_dim = true; + ExecuteCommand(scmnd, SRC_SWITCH); + } } } break; diff --git a/tools/decode-config.py b/tools/decode-config.py index b2ea6f5d9..6482edcbd 100755 --- a/tools/decode-config.py +++ b/tools/decode-config.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -VER = '2.2.0025' +VER = '2.2.0026' """ decode-config.py - Backup/Restore Sonoff-Tasmota configuration data @@ -29,7 +29,7 @@ Requirements: Instructions: Execute command with option -d to retrieve config data from a host or use -f to read a configuration file saved using Tasmota Web-UI - + For further information read 'decode-config.md' For help execute command with argument -h (or -H for advanced help) @@ -263,7 +263,7 @@ exitcode = 0 Settings dictionary describes the config file fields definition: = { : } - + : "string" a python valid dictionary key (string) @@ -333,12 +333,12 @@ Settings dictionary describes the config file fields definition: to convert value from JSON back to binary object Common definitions - + : | | None function to be called or string to evaluate: : A function name will be called with one or two parameter: - The value to be processed + The value to be processed (optional) the current array index (1,n) A string will be evaluate as is. The following @@ -358,7 +358,7 @@ Settings dictionary describes the config file fields definition: numbers in the range -2147483648 through 2147483647 : unsigned integer numbers in the range 0 through 4294967295 - + """ # ---------------------------------------------------------------------- # Settings helper @@ -370,16 +370,16 @@ def passwordwrite(value): def bitsRead(x, n=0, c=1): """ Reads bit(s) of a number - + @param x: the number from which to read - + @param n: which bit position to read - + @param c: how many bits to read (1 if omitted) - + @return: the bit value(s) """ @@ -396,14 +396,14 @@ def bitsRead(x, n=0, c=1): x &= (1< 0: - groups.add(group) + groups.add(group.title()) if isinstance(format_, dict): subgroups = GetGroupList(format_) if subgroups is not None and len(subgroups) > 0: for group in subgroups: - groups.add(group) + groups.add(group.title()) groups=list(groups) groups.sort() return groups - + class FileType: FILE_NOT_FOUND = None @@ -1347,7 +1353,7 @@ def MakeUrl(host, port=80, location=''): def LoadTasmotaConfig(filename): """ Load config from Tasmota file - + @param filename: filename to load @@ -1420,7 +1426,7 @@ def TasmotaGet(cmnd, host, port, username=DEFAULTS['source']['username'], passwo body = buffer.getvalue() except: pass - + return responsecode, body @@ -1605,7 +1611,7 @@ def GetSettingsCrc(dobj): def GetFieldDef(fielddef, fields="format_, addrdef, baseaddr, bits, bitshift, datadef, arraydef, validate, cmd, group, tasmotacmnd, converter, readconverter, writeconverter"): - + """ Get field definition items @@ -1723,7 +1729,7 @@ def GetFieldDef(fielddef, fields="format_, addrdef, baseaddr, bits, bitshift, da else: print >> sys.stderr, 'wrong {} length ({}) in {}'.format(converter, len(converter), fielddef) raise SyntaxError(' error') - + return eval(fields) @@ -1798,13 +1804,13 @@ def CmndConverter(valuemapping, value, idx, fielddef): else: evalstr = tasmotacmnd.replace('$','value').replace('@','valuemapping') result = eval(evalstr) - + elif callable(tasmotacmnd): # use as format function if idx is not None: result = tasmotacmnd(value, idx) else: result = tasmotacmnd(value) - + return result @@ -1821,7 +1827,7 @@ def ValidateValue(value, fielddef): True if value is valid, False if invalid """ validate = GetFieldDef(fielddef, fields='validate') - + if value == 0: # can not complete all validate condition # some Tasmota values are not allowed to be 0 on input @@ -1918,7 +1924,7 @@ def GetFieldMinMax(fielddef): max_ = GetFormatCount(format_) return min_,max_ - + def GetFieldLength(fielddef): """ @@ -2039,7 +2045,7 @@ def GetFieldValue(fielddef, dobj, addr): """ format_, bits, bitshift = GetFieldDef(fielddef, fields='format_, bits, bitshift') - + value_ = 0 unpackedvalue = struct.unpack_from(format_, dobj, addr) singletype, bitsize = GetFormatType(format_) @@ -2076,7 +2082,7 @@ def SetFieldValue(fielddef, dobj, addr, value): format_, bits, bitshift = GetFieldDef(fielddef, fields='format_, bits, bitshift') formatcnt = GetFormatCount(format_) - singletype, bitsize = GetFormatType(format_) + singletype, bitsize = GetFormatType(format_) if args.debug >= 2: print >> sys.stderr, "SetFieldValue(): fielddef {}, addr 0x{:04x} value {} formatcnt {} singletype {} bitsize {} ".format(fielddef,addr,value,formatcnt,singletype,bitsize) if not format_[-1:].lower() in ['s','p']: @@ -2138,7 +2144,7 @@ def GetField(dobj, fieldname, fielddef, raw=False, addroffset=0): value = GetField(dobj, fieldname, subfielddef, raw=raw, addroffset=addroffset+offset) valuemapping.append(value) offset += length - + # contains a dict elif isinstance(format_, dict): mapping_value = {} @@ -2333,7 +2339,7 @@ def SetField(dobj, fieldname, fielddef, restore, addroffset=0, filename=""): curvalue = GetFieldValue(fielddef, dobj, baseaddr+addroffset) if prevvalue != curvalue and args.verbose: message("Value for '{}' changed from {} to {}".format(fieldname, prevvalue, curvalue), typ=LogType.INFO) - else: + else: if args.debug >= 2: print >> sys.stderr, "SetField(): Special field '{}' using '{}'/{}{} @{} skipped".format(fieldname, format_, arraydef, bits, hex(baseaddr+addroffset)) else: @@ -2502,14 +2508,14 @@ def Mapping2Bin(decode_cfg, jsonconfig, filename=""): restore data mapping @param filename: name of the restore file (for error output only) - + @return: changed binary config data (decrypted) or None on error """ if isinstance(decode_cfg, str): decode_cfg = bytearray(decode_cfg) - + # get binary header data to use the correct version template from device version, size, setting = GetTemplateSetting(decode_cfg) @@ -2549,13 +2555,13 @@ def Mapping2Cmnd(decode_cfg, valuemapping, filename=""): data mapping @param filename: name of the restore file (for error output only) - + @return: Tasmota command mapping {group: [cmnd <,cmnd <,...>>]} """ if isinstance(decode_cfg, str): decode_cfg = bytearray(decode_cfg) - + # get binary header data to use the correct version template from device version, size, setting = GetTemplateSetting(decode_cfg) @@ -2782,7 +2788,7 @@ def OutputTasmotaCmnds(tasmotacmnds): print print "# {}:".format(group) OutputTasmotaSubCmnds(cmnds) - + else: cmnds = [] for group in groups: @@ -2793,7 +2799,7 @@ def OutputTasmotaCmnds(tasmotacmnds): def ParseArgs(): """ Program argument parser - + @return: configargparse.parse_args() result """ @@ -3056,5 +3062,5 @@ if __name__ == "__main__": if args.outputformat == 'cmnd' or args.outputformat == 'command': tasmotacmnds = Mapping2Cmnd(decode_cfg, configmapping) OutputTasmotaCmnds(tasmotacmnds) - + sys.exit(exitcode)