-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathdecode-config.py
executable file
·7042 lines (6428 loc) · 432 KB
/
decode-config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
METADATA = {
'VERSION': '14.4.1.3',
'DESCRIPTION': 'Backup/restore and decode configuration tool for Tasmota',
'CLASSIFIER': 'Development Status :: 4 - Beta',
'URL': 'https://github.com/tasmota/decode-config',
'AUTHOR': 'Norbert Richter',
'AUTHOR_EMAIL': '[email protected]',
}
"""
decode-config.py - Backup/Restore Tasmota configuration data
Copyright (C) 2024 Norbert Richter <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Requirements:
decode-config is a Python 3.x program. Before installation prepare
python and pip for your system:
sudo apt-get install python3 python3-pip
Installation:
python -m pip install decode-config
Instructions:
Start decode-config.py with option -s <file|host|url|mqttbroker>
to retrieve config data from a Tasmota host
For further information see 'README.md' and start decode-config
with -h (short help) or -H (full help)
Returns:
0: successful
1: restore skipped
2: program argument error
3: file not found
4: data size mismatch
5: data CRC error
6: unsupported configuration version
7: configuration file read error
8: JSON file decoding error
9: restore file data error
10: device data download error
11: device data upload error
12: invalid configuration data
20: python module missing
21: internal error
22: HTTP connection error
23: MQTT connection error
>23: python library exit code
255: Other errors
"""
class ExitCode:
"""
Program return codes
"""
OK = 0
RESTORE_SKIPPED = 1
ARGUMENT_ERROR = 2
FILE_NOT_FOUND = 3
DATA_SIZE_MISMATCH = 4
DATA_CRC_ERROR = 5
UNSUPPORTED_VERSION = 6
FILE_READ_ERROR = 7
JSON_READ_ERROR = 8
RESTORE_DATA_ERROR = 9
DOWNLOAD_CONFIG_ERROR = 10
UPLOAD_CONFIG_ERROR = 11
INVALID_DATA = 12
MODULE_NOT_FOUND = 20
INTERNAL_ERROR = 21
HTTP_CONNECTION_ERROR = 22
MQTT_CONNECTION_ERROR = 23
STR = [
'OK',
'Restore skipped',
'Parameter error',
'File not found',
'Data size mismatch',
'Data CRC error',
'Unsupported version',
'File read error',
'JSON read error',
'Restore data error',
'Download error',
'Upload error',
'Invaid data',
'', '', '', '', '', '', '',
'Module not found',
'Internal error',
'HTTP connection error',
'MQTT connection error'
]
@staticmethod
def str(code):
"""
Program return string by code
@param: code
int number of code
"""
if 0 <= code < len(ExitCode.STR):
return ExitCode.STR[code]
return ''
# ======================================================================
# imports
# ======================================================================
def module_import_error(module):
"""
Module import error helper
"""
errstr = str(module)
print('{}, try "python -m pip install {}"'.format(errstr, errstr.split(' ')[len(errstr.split(' '))-1]), file=sys.stderr)
sys.exit(ExitCode.MODULE_NOT_FOUND)
# pylint: disable=wrong-import-position
import os.path
import sys
if sys.version_info[0] < 3:
print('Unsupported python version {}.{}.{} (EOL) - python 3.x required!'.format(sys.version_info[0], sys.version_info[1], sys.version_info[2]), file=sys.stderr)
sys.exit(ExitCode.UNSUPPORTED_VERSION)
import platform
try:
from datetime import datetime, timezone
import base64
import time
import copy
import struct
import socket # pylint: disable=unused-import
import re
import inspect
import itertools
import json
import configargparse
import requests
import urllib
import codecs
import textwrap
import hashlib
except ImportError as err:
module_import_error(err)
try:
from paho.mqtt import client as mqtt
MQTT_MODULE = True
except ImportError:
MQTT_MODULE = False
try:
import ssl
SSL_MODULE = True
except ImportError:
SSL_MODULE = False
# pylint: enable=wrong-import-position
# ======================================================================
# globals
# ======================================================================
METADATA['BUILD'] = ''
METADATA['VERSION_BUILD'] = METADATA['VERSION']
try:
SHA256 = hashlib.sha256()
FNAME = sys.argv[0]
if not os.path.isfile(FNAME):
FNAME += '.exe'
with open(FNAME, "rb") as fp:
for block in iter(lambda: fp.read(4096), b''):
SHA256.update(block)
METADATA['BUILD'] = SHA256.hexdigest()[:7]
METADATA['VERSION_BUILD'] = METADATA['VERSION'] + ' [' + METADATA['BUILD'] + ']'
except: # pylint: disable=bare-except
pass
PROG = '{} v{} by {} {}'.format(os.path.basename(sys.argv[0]), METADATA['VERSION_BUILD'], METADATA['AUTHOR'], METADATA['AUTHOR_EMAIL'])
# Tasmota constant
CONFIG_FILE_XOR = 0x5A
BINARYFILE_MAGIC = 0x63576223
MAX_BACKLOG = 30
MAX_BACKLOGLEN = 320
MQTT_MESSAGE_MAX_SIZE = 700
MQTT_TIMEOUT = 5000
MQTT_FILETYPE = 2
TASM_FILE_SETTINGS = '/.settings'
# decode-config constant
STR_CODING = 'utf-8'
HIDDEN_PASSWORD = '********'
INTERNAL = 'Internal'
VIRTUAL = '*'
SETTINGVAR = '$SETTINGVAR'
SIMULATING = "* Simulating "
DEFAULT_PORT_HTTP = 80
DEFAULT_PORT_HTTPS = 443
DEFAULT_PORT_MQTT = 1883
DEFAULT_PORT_MQTTS = 8883
DEFAULTS = {
'source':
{
'source': None,
'filesource': None,
'httpsource': None,
'mqttsource': None,
'port': None,
'username': 'admin',
'password': None,
'fulltopic': '',
'cafile': None,
'certfile': None,
'keyfile': None,
'insecure': False,
'keepalive': 60,
},
'backup':
{
'restorefile': None,
'backupfile': None,
'backupfileformat': 'json',
'extension': True,
'forcerestore': False,
},
'jsonformat':
{
'indent': None,
'compact': False,
'sort': True,
'hidepw': False,
},
'cmndformat':
{
'indent': 2,
'group': True,
'sort': True,
'useruleconcat': False,
'usebacklog': False,
},
'common':
{
'output': False,
'outputformat': 'json',
'configfile': None,
'dryrun': False,
'ignorewarning':False,
'filter': None,
},
}
PARSER = None
ARGS = {}
EXIT_CODE = 0
# CONFIG map
# 'encode' binary - raw (XOR encoded) configuration data incl. possible file tar header and files
# 'decode' binary - encoded configuration data (without tar header/files)
# 'header' binary - raw config file tar file header if any, otherwise None
# 'settings' map - appended setting files: filename and binary filedata
# 'info' map - info about device and used configuration data template
# 'hardware' int - ESP hardware type (see class Hardware.ESPxx const)
# 'version' int - Tasmota version
# 'template_version' int - Template version used for this Tasmota version
# 'template_size' int - configuration data size used for this Tasmota version
# 'valuemapping' map - full configuration data (with raw values)
# 'groupmapping' map - grouped configuration data (filtered by possible functions)
CONFIG = {}
# ======================================================================
# Settings mapping
# ======================================================================
"""
Settings dictionary
The Tasmota permanent setttings are stored in binary format using
'struct SYSCFG' defined in tasmota/include/tasmota_types.h.
decode-config handles the binary data described by this Settings
dictionary. The processing from/to Tasmota configuration data is
based on this dictionary.
<setting> = { <name> : <def> }
<name>: "string"
key (string)
for simply identifying value from Tasmota configuration this key has the same
name as the structure element of tasmota/include/tasmota_types.h
<def>: ( <hardware>, <format>, <addrdef>, <datadef> [,<converter>] )
tuple with 4 or 5 objects which describes the format, address and structure
of the binary source.
For optional values there are two possibilities: If the definition object is
mandatory it could be None, for none-mandatory optional objects it can be omit.
<hardware>: <int>
hardware bitmask validation
determines whether the setting is valid for a specific ESP platform (1) or not (0)
<format>: <formatstring> | <setting>
data type & format definition
<formatstring>: <string>
defines the use of data at <addrdef>
format is defined in 'struct module format string'
see https://docs.python.org/3/library/struct.html#format-strings
<setting>: <setting>
A dictionary describes a (sub)setting dictonary
and can recursively define another <setting>
<addrdef>: <baseaddr> | (<baseaddr>, <bits>, <bitshift>) | (<baseaddr>, <strindex>)
address definition
<baseaddr>: <uint>
The address (starting from 0) within binary config data.
<bits>: <uint>
number of bits used (positive integer)
<bitshift>: <int>
bit shift <bitshift>:
<bitshift> >= 0: shift the result right
<bitshift> < 0: shift the result left
<strindex>: <str>
name of the index into a set of strings delimited by \0
This will be dynamically extracted from the corresponding hardware index array for strings
<datadef>: <arraydef> | (<arraydef>, <validate> [,cmd])
data definition
<arraydef>: None | <dim> | [<dim>] | [<dim> ,<dim>...]
None:
single value
<dim>: <uint>
[<dim>]
a one-dimensional array of size <n>
[<dim> ,<dim>...]
a one- or multi-dimensional array
<validate>: None | <function>
value validation function
<cmd>: (<group>, <tasmotacmnd>) - optional
Tasmota command definition
<group>: <string>
command group
There exists two special group names
INTERNAL - processed but invisible in group output
VIRTUAL - must be used as group name for nested
dict definition - invisible in group output
<tasmotacmnd>: <function> | (<function>,...)
convert function into Tasmota cmnd function
<converter>: <readconverter> | (<readconverter>, <writeconverter>) -
read/write converter
<readconverter>: None | False | <function>
Will be used in bin2mapping to convert values read
from the binary data object into mapping dictionary
None
indicates no read conversion
False
False indicates the value will be ignored
<function>
to convert value from binary object to JSON.
Can also return None|False with the same result
as using the constant above.
<writeconverter>: None | False | <function>
Will be used in mapping2bin to convert values read
from mapping dictionary before write to binary
data object
None
indicates no write conversion
False
False indicates the value is readonly and is not
written back into the binary Tasmota data.
<function>
to convert value from JSON back to binary object.
Can also return None|False with the same result
as using the constant above.
Common definitions
<function>: <functionname> | <string> | None
the name of an object to be called or a string to be evaluated
<functionname>:
<functionname> will be called with one or three parameter:
if <arraydef> is None:
functionname(<value>)
if <arraydef> is any <dim>:
functionname(<value>, <index>)
<value>
setting value to be processed
<index>
if <arraydef> is a one-dimensional array
int array index (starting from 0)
if <arraydef> is a multi-dimensional array
[int,int(,int...)]
array of current index (starting from 0)
<string>
A string will be evaluate as is. The following placeholder
can be used for runtime replacements:
'$':
will be replaced by the object mapping value
'@':
can be used to reference another mapping value
'#': (for <tasmotacmnd> only)
will be replace by
- int array index (<arraydef> is a one-dimensional)
- array of int array indexes (<arraydef> is a multi-dimensional)
<string>: 'string' | "string"
characters enclosed by ' or "
<int>: integer
integer number in the range -2147483648 through 2147483647
<uint>: unsigned integer
integer number in the range 0 through 4294967295
"""
# ----------------------------------------------------------------------
# Settings helper
# ----------------------------------------------------------------------
def passwordread(value):
"""
Password read helper
"""
return HIDDEN_PASSWORD if ARGS.jsonhidepw else value
def passwordwrite(value):
"""
Password write helper
"""
return None if value == HIDDEN_PASSWORD else value
def scriptread(value):
"""
Scripter config helper to read script
"""
if CONFIG['valuemapping'].get('scripting_used', 0) == 1:
if CONFIG['valuemapping'].get('scripting_compressed', 0) == 1:
# uncompressed compressed string
uncompressed_data = bytearray(3072)
compressed = bytes.fromhex(value)
try:
Unishox().decompress(compressed, len(compressed), uncompressed_data, len(uncompressed_data))
except: # pylint: disable=bare-except
return value
try:
uncompressed_str = str(uncompressed_data, STR_CODING).split('\x00')[0]
except UnicodeDecodeError as err:
log(ExitCode.INVALID_DATA, "Compressed string - {}:\n {}".format(err, err.args[1]), type_=LogType.WARNING, line=inspect.getlineno(inspect.currentframe()))
uncompressed_str = str(uncompressed_data, STR_CODING, 'backslashreplace').split('\x00')[0]
return uncompressed_str
return value
return False
def scriptwrite(value):
"""
Scripter config helper to write script
"""
if CONFIG['valuemapping'].get('scripting_used', 0) == 1:
if CONFIG['valuemapping'].get('scripting_compressed', 0) == 1:
# compressed uncompressed string
fielddef = CONFIG['info']['template'].get('script', None)
if fielddef is None:
print("wrong setting for 'script'", file=sys.stderr)
raise SyntaxError('SETTING error')
compressed_data = bytearray(get_fieldlength(fielddef))
if isinstance(value, str):
uncompressed_data = bytes(value, STR_CODING)
else:
uncompressed_data = value
Unishox().compress(uncompressed_data, len(uncompressed_data), compressed_data, len(compressed_data))
index0 = compressed_data.find(b'\x00')
if index0 >= 0:
compressed_data = compressed_data[:index0]
return compressed_data
return value
return False
def isscript(value):
"""
Rules config helper
"""
if CONFIG['valuemapping'].get('scripting_used', 0) == 1:
return value
return False
def rulesread(value):
"""
Scripter config helper to read rules
"""
if CONFIG['valuemapping'].get('scripting_used', 0) == 0:
# check if string is compressed
if len(value) > 2 and value[0] == '\x00':
# uncompress string
uncompressed_data = bytearray(3072)
compressed = bytes.fromhex(value[3:])
try:
Unishox().decompress(compressed, len(compressed), uncompressed_data, len(uncompressed_data))
except: # pylint: disable=bare-except
return value
try:
uncompressed_str = str(uncompressed_data, STR_CODING).split('\x00')[0]
except UnicodeDecodeError as err:
log(ExitCode.INVALID_DATA, "Compressed string - {}:\n {}".format(err, err.args[1]), type_=LogType.WARNING, line=inspect.getlineno(inspect.currentframe()))
uncompressed_str = str(uncompressed_data, STR_CODING, 'backslashreplace').split('\x00')[0]
return uncompressed_str
# return origin str
return value
# scripting is enabled, rule space used for script so rule is invalid and disabled
return False
def ruleswrite(value):
"""
Scripter config helper to write rules
compression for Rules, depends on 'compress_rules_cpu' (SetOption93)
If `SetOption93 0`
Rule[x][] = 511 char max NULL terminated string (512 with trailing NULL)
Rule[x][0] = 0 if the Rule<x> is empty
New: in case the string is empty we also enforce:
Rule[x][1] = 0 (i.e. we have two conseutive NULLs)
If `SetOption93 1`
If the rule is smaller than 511, it is stored uncompressed. Rule[x][0] is not null.
If the rule is empty, Rule[x][0] = 0 and Rule[x][1] = 0;
If the rule is bigger than 511, it is stored compressed
The first byte of each Rule is always NULL.
Rule[x][0] = 0, if firmware is downgraded, the rule will be considered as empty
The second byte contains the size of uncompressed rule in 8-bytes blocks (i.e. (len+7)/8 )
Maximum rule size is 2KB (2048 bytes per rule), although there is little chances compression ratio will go down to 75%
Rule[x][1] = size uncompressed in dwords. If zero, the rule is empty.
The remaining bytes contain the compressed rule, NULL terminated
"""
if CONFIG['valuemapping'].get('scripting_used', 0) == 0:
fielddef = CONFIG['info']['template'].get('rules', None)
if fielddef is None:
print("wrong setting for 'rule'", file=sys.stderr)
raise SyntaxError('SETTING error')
try:
subfielddef = get_subfielddef(fielddef)
length = get_fieldlength(subfielddef)
except: # pylint: disable=bare-except
length = 512
# check if string should be compressed
try:
possible_compress = CONFIG['info']['template']['flag4'][1]['compress_rules_cpu']
except: # pylint: disable=bare-except
possible_compress = False
if possible_compress and len(value) > 0 and value[0] != '\x00' and len(value) >= length:
# compressed uncompressed string
compressed_data = bytearray(length)
if isinstance(value, str):
uncompressed_data = bytes(value, STR_CODING)
else:
uncompressed_data = value
try:
Unishox().compress(uncompressed_data, len(uncompressed_data), compressed_data, len(compressed_data))
index0 = compressed_data.find(b'\x00')
if index0 >= 0:
compressed_data = compressed_data[:index0]
except: # pylint: disable=bare-except
return value
return b'\x00' + struct.pack("B", int((len(value)+7)/8)) + compressed_data
if len(value) == 0:
return b'\x00\x00'
# return origin str
return value
# scripting is enabled, rule space used for script so rule is invalid and disabled
return False
# ----------------------------------------------------------------------
# Tasmota configuration data definition
# ----------------------------------------------------------------------
# global objects used by eval(<tasmotacmnd>)
SETTING_OBJECTS = {
'socket': socket,
'struct': struct,
'time': time,
'textwrap': textwrap
}
class Hardware:
"""
ESPxx configuration data hardware class
"""
# Bit mask for supported hardware
ESP82 = 0b00000001 # All ESP82xx
ESP32ex = 0b00000010 # ESP32 excluding S2-S3/C2-C6
ESP82_32ex = 0b00000011 # ESP82xx + ESP32 excluding ESP32 S2-S3/C2-C6
ESP32S3 = 0b00000100 # ESP32S3
ESP32S2 = 0b00001000 # ESP32S2
ESP32C3 = 0b00010000 # ESP32C3
ESP32C2 = 0b00100000 # ESP32C2
ESP32C6 = 0b01000000 # ESP32C6
ESP32 = 0b01111110 # All ESP32
ESP = 0b11111111 # All ESP
# Hardware bitmask and description
config = (
(ESP82, "ESP82"),
(ESP32ex, "ESP32 (excl S2-S3/C2-C6)"),
(ESP82_32ex, "ESP82/32 (excl ESP32 S2-S3/C2-C6)"),
(ESP32S3, "ESP32S3"),
(ESP32, "ESP32"),
(ESP, "ESP82/32")
)
# Tasmota config_version values
config_versions = (ESP82, ESP32ex, ESP32S3, ESP32S2, ESP32C3, ESP32C2, ESP32C6)
def get_bitmask(self, config_version):
"""
Get hardware bitmask based on Tasmota config_version
"""
try:
return self.config_versions[config_version]
except: # pylint: disable=bare-except
return self.ESP
def hstr(self, setting_hardware):
"""
Create an dict index string based on hardware
@param setting_hardware:
hardware definition value from setting
@return:
dict index string
"""
try:
return 'TEXTINDEX_'+self.config[[hw[0] for hw in self.config].index(setting_hardware)][1]
except: # pylint: disable=bare-except
return 'TEXTINDEX_'+self.config[len(self.config)-1][1]
def str(self, config_version):
"""
Create hardware string
@param config_version:
config_version value from Tasmota configuration
@return:
hardware string
"""
hardware = self.get_bitmask(config_version)
try:
return self.config[[hw[0] for hw in self.config].index(hardware)][1]
except: # pylint: disable=bare-except
return self.config[len(self.config)-1][1]
def match(self, setting_hardware, config_version):
"""
Test match of setting hardware with config data from Tasmota
@param setting_hardware:
hardware definition value from setting
@param config_version:
config_version vvalue from Tasmota configuration
@return:
True if setting hardware matchs Tasmota configuration data
"""
return (setting_hardware & self.get_bitmask(config_version)) != 0
HARDWARE = Hardware()
# pylint: disable=bad-continuation,bad-whitespace
SETTING_5_10_0 = {
# <hardware>, <format>, <addrdef>, <datadef> [,<converter>]
'cfg_holder': (HARDWARE.ESP, '<L', 0x000, (None, None, (INTERNAL, None)), '"0x{:08x}".format($)' ),
'save_flag': (HARDWARE.ESP, '<L', 0x004, (None, None, (INTERNAL, None)), (None, False) ),
'version': (HARDWARE.ESP, '<L', 0x008, (None, None, ('System', None)), ('hex($)', False) ),
'bootcount': (HARDWARE.ESP, '<L', 0x00C, (None, None, ('System', None)), (None, False) ),
'flag': (HARDWARE.ESP, {
'save_state': (HARDWARE.ESP, '<L', (0x010,1, 0), (None, None, ('SetOption', '"SetOption0 {}".format($)')) ),
'button_restrict': (HARDWARE.ESP, '<L', (0x010,1, 1), (None, None, ('SetOption', '"SetOption1 {}".format($)')) ),
'value_units': (HARDWARE.ESP, '<L', (0x010,1, 2), (None, None, ('SetOption', '"SetOption2 {}".format($)')) ),
'mqtt_enabled': (HARDWARE.ESP, '<L', (0x010,1, 3), (None, None, ('SetOption', '"SetOption3 {}".format($)')) ),
'mqtt_response': (HARDWARE.ESP, '<L', (0x010,1, 4), (None, None, ('SetOption', '"SetOption4 {}".format($)')) ),
'mqtt_power_retain': (HARDWARE.ESP, '<L', (0x010,1, 5), (None, None, ('MQTT', '"PowerRetain {}".format($)')) ),
'mqtt_button_retain': (HARDWARE.ESP, '<L', (0x010,1, 6), (None, None, ('MQTT', '"ButtonRetain {}".format($)')) ),
'mqtt_switch_retain': (HARDWARE.ESP, '<L', (0x010,1, 7), (None, None, ('MQTT', '"SwitchRetain {}".format($)')) ),
'temperature_conversion': (HARDWARE.ESP, '<L', (0x010,1, 8), (None, None, ('SetOption', '"SetOption8 {}".format($)')) ),
'mqtt_sensor_retain': (HARDWARE.ESP, '<L', (0x010,1, 9), (None, None, ('MQTT', '"SensorRetain {}".format($)')) ),
'mqtt_offline': (HARDWARE.ESP, '<L', (0x010,1,10), (None, None, ('SetOption', '"SetOption10 {}".format($)')) ),
'button_swap': (HARDWARE.ESP, '<L', (0x010,1,11), (None, None, ('SetOption', '"SetOption11 {}".format($)')) ),
'stop_flash_rotate': (HARDWARE.ESP, '<L', (0x010,1,12), (None, None, ('SetOption', '"SetOption12 {}".format($)')) ),
'button_single': (HARDWARE.ESP, '<L', (0x010,1,13), (None, None, ('SetOption', '"SetOption13 {}".format($)')) ),
'interlock': (HARDWARE.ESP, '<L', (0x010,1,14), (None, None, ('SetOption', '"SetOption14 {}".format($)')) ),
'pwm_control': (HARDWARE.ESP, '<L', (0x010,1,15), (None, None, ('SetOption', '"SetOption15 {}".format($)')) ),
'ws_clock_reverse': (HARDWARE.ESP, '<L', (0x010,1,16), (None, None, ('SetOption', '"SetOption16 {}".format($)')) ),
'decimal_text': (HARDWARE.ESP, '<L', (0x010,1,17), (None, None, ('SetOption', '"SetOption17 {}".format($)')) ),
}, 0x010, (None, None, (VIRTUAL, None)), (None, None) ),
'save_data': (HARDWARE.ESP, '<h', 0x014, (None, '0 <= $ <= 3600', ('Management', '"SaveData {}".format($)')) ),
'timezone': (HARDWARE.ESP, 'b', 0x016, (None, '-13 <= $ <= 13 or $==99', ('Management', '"Timezone {}".format($)')) ),
'ota_url': (HARDWARE.ESP, '101s',0x017, (None, None, ('Management', '"OtaUrl {}".format($)')) ),
'mqtt_prefix': (HARDWARE.ESP, '11s', 0x07C, ([3], None, ('MQTT', '"Prefix{} {}".format(#+1,$)')) ),
'seriallog_level': (HARDWARE.ESP, 'B', 0x09E, (None, '0 <= $ <= 5', ('Management', '"SerialLog {}".format($)')) ),
'sta_config': (HARDWARE.ESP, 'B', 0x09F, (None, '0 <= $ <= 5', ('Wifi', '"WifiConfig {}".format($)')) ),
'sta_active': (HARDWARE.ESP, 'B', 0x0A0, (None, '0 <= $ <= 1', ('Wifi', '"AP {}".format($)')) ),
'sta_ssid': (HARDWARE.ESP, '33s', 0x0A1, ([2], None, ('Wifi', '"SSId{} {}".format(#+1,$)')) ),
'sta_pwd': (HARDWARE.ESP, '65s', 0x0E3, ([2], None, ('Wifi', '"Password{} {}".format(#+1,$)')), (passwordread, passwordwrite) ),
'hostname': (HARDWARE.ESP, '33s', 0x165, (None, None, ('Wifi', '"Hostname {}".format($)')) ),
'syslog_host': (HARDWARE.ESP, '33s', 0x186, (None, None, ('Management', '"LogHost {}".format($)')) ),
'syslog_port': (HARDWARE.ESP, '<H', 0x1A8, (None, '1 <= $ <= 32766', ('Management', '"LogPort {}".format($)')) ),
'syslog_level': (HARDWARE.ESP, 'B', 0x1AA, (None, '0 <= $ <= 4', ('Management', '"SysLog {}".format($)')) ),
'webserver': (HARDWARE.ESP, 'B', 0x1AB, (None, '0 <= $ <= 2', ('Wifi', '"WebServer {}".format($)')) ),
'weblog_level': (HARDWARE.ESP, 'B', 0x1AC, (None, '0 <= $ <= 4', ('Management', '"WebLog {}".format($)')) ),
'mqtt_fingerprint': (HARDWARE.ESP, 'B', 0x1AD, ([60], None, ('MQTT', '"MqttFingerprint {}".format(" ".join("{:02X}".format(c) for c in @["mqtt_fingerprint"]))')), '"0x{:02x}".format($)' ),
'mqtt_host': (HARDWARE.ESP, '33s', 0x1E9, (None, None, ('MQTT', '"MqttHost {}".format($)')) ),
'mqtt_port': (HARDWARE.ESP, '<H', 0x20A, (None, None, ('MQTT', '"MqttPort {}".format($)')) ),
'mqtt_client': (HARDWARE.ESP, '33s', 0x20C, (None, None, ('MQTT', '"MqttClient {}".format($)')) ),
'mqtt_user': (HARDWARE.ESP, '33s', 0x22D, (None, None, ('MQTT', '"MqttUser {}".format($)')) ),
'mqtt_pwd': (HARDWARE.ESP, '33s', 0x24E, (None, None, ('MQTT', '"MqttPassword {}".format($)')), (passwordread, passwordwrite) ),
'mqtt_topic': (HARDWARE.ESP, '33s', 0x26F, (None, None, ('MQTT', '"Topic {}".format($)')) ),
'button_topic': (HARDWARE.ESP, '33s', 0x290, (None, None, ('MQTT', '"ButtonTopic {}".format($)')) ),
'mqtt_grptopic': (HARDWARE.ESP, '33s', 0x2B1, (None, None, ('MQTT', '"GroupTopic {}".format($)')) ),
'mqtt_fingerprinth': (HARDWARE.ESP, 'B', 0x2D2, ([20], None, ('MQTT', None)) ),
'pwm_frequency': (HARDWARE.ESP, '<H', 0x2E6, (None, '$==1 or 100 <= $ <= 4000', ('Management', '"PwmFrequency {}".format($)')) ),
'power': (HARDWARE.ESP, {
'power1': (HARDWARE.ESP, '<L', (0x2E8,1,0), (None, None, ('Control', '"Power1 {}".format($)')) ),
'power2': (HARDWARE.ESP, '<L', (0x2E8,1,1), (None, None, ('Control', '"Power2 {}".format($)')) ),
'power3': (HARDWARE.ESP, '<L', (0x2E8,1,2), (None, None, ('Control', '"Power3 {}".format($)')) ),
'power4': (HARDWARE.ESP, '<L', (0x2E8,1,3), (None, None, ('Control', '"Power4 {}".format($)')) ),
'power5': (HARDWARE.ESP, '<L', (0x2E8,1,4), (None, None, ('Control', '"Power5 {}".format($)')) ),
'power6': (HARDWARE.ESP, '<L', (0x2E8,1,5), (None, None, ('Control', '"Power6 {}".format($)')) ),
'power7': (HARDWARE.ESP, '<L', (0x2E8,1,6), (None, None, ('Control', '"Power7 {}".format($)')) ),
'power8': (HARDWARE.ESP, '<L', (0x2E8,1,7), (None, None, ('Control', '"Power8 {}".format($)')) ),
}, 0x2E8, (None, None, ('Control', None)), (None, None) ),
'pwm_value': (HARDWARE.ESP, '<H', 0x2EC, ([5], '0 <= $ <= 1023', ('Management', '"Pwm{} {}".format(#+1,$)')) ),
'altitude': (HARDWARE.ESP, '<h', 0x2F6, (None, '-30000 <= $ <= 30000', ('Sensor', '"Altitude {}".format($)')) ),
'tele_period': (HARDWARE.ESP, '<H', 0x2F8, (None, '0 == $ or 10 <= $ <= 3600', ('MQTT', '"TelePeriod {}".format($)')) ),
'ledstate': (HARDWARE.ESP, 'B', 0x2FB, (None, '0 <= $ <= 8', ('Control', '"LedState {}".format(($ & 0x7))')) ),
'param': (HARDWARE.ESP, 'B', 0x2FC, ([23], None, ('SetOption', '"SetOption{} {}".format(#+32,$)')) ),
'state_text': (HARDWARE.ESP, '11s', 0x313, ([4], None, ('MQTT', '"StateText{} {}".format(#+1,$)')) ),
'domoticz_update_timer': (HARDWARE.ESP, '<H', 0x340, (None, '0 <= $ <= 3600', ('Domoticz', '"DomoticzUpdateTimer {}".format($)')) ),
'pwm_range': (HARDWARE.ESP, '<H', 0x342, (None, '$==1 or 255 <= $ <= 1023', ('Management', '"PwmRange {}".format($)')) ),
'domoticz_relay_idx': (HARDWARE.ESP, '<L', 0x344, ([4], None, ('Domoticz', '"DomoticzIdx{} {}".format(#+1,$)')) ),
'domoticz_key_idx': (HARDWARE.ESP, '<L', 0x354, ([4], None, ('Domoticz', '"DomoticzKeyIdx{} {}".format(#+1,$)')) ),
'energy_power_calibration': (HARDWARE.ESP, '<L', 0x364, (None, None, ('Power', '"PowerSet {}".format($)')) ),
'energy_voltage_calibration': (HARDWARE.ESP, '<L', 0x368, (None, None, ('Power', '"VoltageSet {}".format($)')) ),
'energy_current_calibration': (HARDWARE.ESP, '<L', 0x36C, (None, None, ('Power', '"CurrentSet {}".format($)')) ),
'energy_kWhtoday': (HARDWARE.ESP, '<L', 0x370, (None, '0 <= $ <= 4250000', ('Power', '"EnergyReset1 {}".format(int(round(float($)//100)))')) ),
'energy_kWhyesterday': (HARDWARE.ESP, '<L', 0x374, (None, '0 <= $ <= 4250000', ('Power', '"EnergyReset2 {}".format(int(round(float($)//100)))')) ),
'energy_kWhdoy': (HARDWARE.ESP, '<H', 0x378, (None, None, ('Power', None)) ),
'energy_min_power': (HARDWARE.ESP, '<H', 0x37A, (None, None, ('Power', '"PowerLow {}".format($)')) ),
'energy_max_power': (HARDWARE.ESP, '<H', 0x37C, (None, None, ('Power', '"PowerHigh {}".format($)')) ),
'energy_min_voltage': (HARDWARE.ESP, '<H', 0x37E, (None, None, ('Power', '"VoltageLow {}".format($)')) ),
'energy_max_voltage': (HARDWARE.ESP, '<H', 0x380, (None, None, ('Power', '"VoltageHigh {}".format($)')) ),
'energy_min_current': (HARDWARE.ESP, '<H', 0x382, (None, None, ('Power', '"CurrentLow {}".format($)')) ),
'energy_max_current': (HARDWARE.ESP, '<H', 0x384, (None, None, ('Power', '"CurrentHigh {}".format($)')) ),
'energy_max_power_limit': (HARDWARE.ESP, '<H', 0x386, (None, None, ('Power', '"MaxPower {}".format($)')) ),
'energy_max_power_limit_hold': (HARDWARE.ESP, '<H', 0x388, (None, None, ('Power', '"MaxPowerHold {}".format($)')) ),
'energy_max_power_limit_window':(HARDWARE.ESP, '<H', 0x38A, (None, None, ('Power', '"MaxPowerWindow {}".format($)')) ),
'energy_max_power_safe_limit': (HARDWARE.ESP, '<H', 0x38C, (None, None, ('Power', '"SavePower {}".format($)')) ),
'energy_max_power_safe_limit_hold':
(HARDWARE.ESP, '<H', 0x38E, (None, None, ('Power', '"SavePowerHold {}".format($)')) ),
'energy_max_power_safe_limit_window':
(HARDWARE.ESP, '<H', 0x390, (None, None, ('Power', '"SavePowerWindow {}".format($)')) ),
'energy_max_energy': (HARDWARE.ESP, '<H', 0x392, (None, None, ('Power', '"MaxEnergy {}".format($)')) ),
'energy_max_energy_start': (HARDWARE.ESP, '<H', 0x394, (None, None, ('Power', '"MaxEnergyStart {}".format($)')) ),
'mqtt_retry': (HARDWARE.ESP, '<H', 0x396, (None, '10 <= $ <= 32000', ('MQTT', '"MqttRetry {}".format($)')) ),
'poweronstate': (HARDWARE.ESP, 'B', 0x398, (None, '0 <= $ <= 5', ('Control', '"PowerOnState {}".format($)')) ),
'last_module': (HARDWARE.ESP, 'B', 0x399, (None, None, (INTERNAL, None)) ),
'blinktime': (HARDWARE.ESP, '<H', 0x39A, (None, '2 <= $ <= 3600', ('Control', '"BlinkTime {}".format($)')) ),
'blinkcount': (HARDWARE.ESP, '<H', 0x39C, (None, '0 <= $ <= 32000', ('Control', '"BlinkCount {}".format($)')) ),
'friendlyname': (HARDWARE.ESP, '33s', 0x3AC, ([4], None, ('Management', '"FriendlyName{} {}".format(#+1,"\\"" if len($) == 0 else $)')) ),
'switch_topic': (HARDWARE.ESP, '33s', 0x430, (None, None, ('MQTT', '"SwitchTopic {}".format($)')) ),
'sleep': (HARDWARE.ESP, 'B', 0x453, (None, '0 <= $ <= 250', ('Management', '"Sleep {}".format($)')) ),
'domoticz_switch_idx': (HARDWARE.ESP, '<H', 0x454, ([4], None, ('Domoticz', '"DomoticzSwitchIdx{} {}".format(#+1,$)')) ),
'domoticz_sensor_idx': (HARDWARE.ESP, '<H', 0x45C, ([12], None, ('Domoticz', '"DomoticzSensorIdx{} {}".format(#+1,$)')) ),
'module': (HARDWARE.ESP, 'B', 0x474, (None, None, ('Management', '"Module {}".format($)')) ),
'ws_color': (HARDWARE.ESP, 'B', 0x475, ([4,3],None, ('Light', None)) ),
'ws_width': (HARDWARE.ESP, 'B', 0x481, ([3], None, ('Light', None)) ),
'my_gp': (HARDWARE.ESP, 'B', 0x484, ([18], None, ('Management', '"Gpio{} {}".format(#,$)')) ),
'light_pixels': (HARDWARE.ESP, '<H', 0x496, (None, '1 <= $ <= 512', ('Light', '"Pixels {}".format($)')) ),
'light_color': (HARDWARE.ESP, 'B', 0x498, ([5], None, ('Light', None)) ),
'light_correction': (HARDWARE.ESP, 'B', 0x49D , (None, '0 <= $ <= 1', ('Light', '"LedTable {}".format($)')) ),
'light_dimmer': (HARDWARE.ESP, 'B', 0x49E, (None, '0 <= $ <= 100', ('Light', '"Wakeup {}".format($)')) ),
'light_fade': (HARDWARE.ESP, 'B', 0x4A1, (None, '0 <= $ <= 1', ('Light', '"Fade {}".format($)')) ),
'light_speed': (HARDWARE.ESP, 'B', 0x4A2, (None, '1 <= $ <= 20', ('Light', '"Speed {}".format($)')) ),
'light_scheme': (HARDWARE.ESP, 'B', 0x4A3, (None, None, ('Light', '"Scheme {}".format($)')) ),
'light_width': (HARDWARE.ESP, 'B', 0x4A4, (None, '0 <= $ <= 4', ('Light', '"Width {}".format($)')) ),
'light_wakeup': (HARDWARE.ESP, '<H', 0x4A6, (None, '0 <= $ <= 3100', ('Light', '"WakeUpDuration {}".format($)')) ),
'web_password': (HARDWARE.ESP, '33s', 0x4A9, (None, None, ('Wifi', '"WebPassword {}".format($)')), (passwordread, passwordwrite) ),
'switchmode': (HARDWARE.ESP, 'B', 0x4CA, ([4], '0 <= $ <= 7', ('Control', '"SwitchMode{} {}".format(#+1,$)')) ),
'ntp_server': (HARDWARE.ESP, '33s', 0x4CE, ([3], None, ('Wifi', '"NtpServer{} {}".format(#+1,$)')) ),
'ina219_mode': (HARDWARE.ESP, 'B', 0x531, (None, '0 <= $ <= 7', ('Sensor', '"Sensor13 {}".format($)')) ),
'pulse_timer': (HARDWARE.ESP, '<H', 0x532, ([8], '0 <= $ <= 64900', ('Control', '"PulseTime{} {}".format(#+1,$)')) ),
'ip_address': (HARDWARE.ESP, '<L', 0x544, ([4], None, ('Wifi', '"IPAddress{} {}".format(#+1,$)')), ("socket.inet_ntoa(struct.pack('<L', $))", "struct.unpack('<L', socket.inet_aton($))[0]")),
'energy_kWhtotal': (HARDWARE.ESP, '<L', 0x554, (None, '0 <= $ <= 4250000000', ('Power', '"EnergyReset3 {}".format(int(round(float($)//100)))')) ),
'mqtt_fulltopic': (HARDWARE.ESP, '100s',0x558, (None, None, ('MQTT', '"FullTopic {}".format($)')) ),
'flag2': (HARDWARE.ESP, {
'current_resolution': (HARDWARE.ESP, '<L', (0x5BC,2,15), (None, '0 <= $ <= 3', ('Sensor', '"AmpRes {}".format($)')) ),
'voltage_resolution': (HARDWARE.ESP, '<L', (0x5BC,2,17), (None, '0 <= $ <= 3', ('Sensor', '"VoltRes {}".format($)')) ),
'wattage_resolution': (HARDWARE.ESP, '<L', (0x5BC,2,19), (None, '0 <= $ <= 3', ('Sensor', '"WattRes {}".format($)')) ),
'emulation': (HARDWARE.ESP, '<L', (0x5BC,2,21), (None, '0 <= $ <= 2', ('Management', '"Emulation {}".format($)')) ),
'energy_resolution': (HARDWARE.ESP, '<L', (0x5BC,3,23), (None, '0 <= $ <= 5', ('Sensor', '"EnergyRes {}".format($)')) ),
'pressure_resolution': (HARDWARE.ESP, '<L', (0x5BC,2,26), (None, '0 <= $ <= 3', ('Sensor', '"PressRes {}".format($)')) ),
'humidity_resolution': (HARDWARE.ESP, '<L', (0x5BC,2,28), (None, '0 <= $ <= 3', ('Sensor', '"HumRes {}".format($)')) ),
'temperature_resolution': (HARDWARE.ESP, '<L', (0x5BC,2,30), (None, '0 <= $ <= 3', ('Sensor', '"TempRes {}".format($)')) ),
}, 0x5BC, (None, None, (VIRTUAL, None)), (None, None) ),
'pulse_counter': (HARDWARE.ESP, '<L', 0x5C0, ([4], None, ('Sensor', '"Counter{} {}".format(#+1,$)')) ),
'pulse_counter_type': (HARDWARE.ESP, {
'pulse_counter_type1': (HARDWARE.ESP, '<H', (0x5D0,1,0), (None, None, ('Sensor', '"CounterType1 {}".format($)')) ),
'pulse_counter_type2': (HARDWARE.ESP, '<H', (0x5D0,1,1), (None, None, ('Sensor', '"CounterType2 {}".format($)')) ),
'pulse_counter_type3': (HARDWARE.ESP, '<H', (0x5D0,1,2), (None, None, ('Sensor', '"CounterType3 {}".format($)')) ),
'pulse_counter_type4': (HARDWARE.ESP, '<H', (0x5D0,1,3), (None, None, ('Sensor', '"CounterType4 {}".format($)')) ),
}, 0x5D0, (None, None, ('Sensor', None)), (None, None) ),
'pulse_counter_debounce': (HARDWARE.ESP, '<H', 0x5D2, (None, '0 <= $ <= 32000', ('Sensor', '"CounterDebounce {}".format($)')) ),
'rf_code': (HARDWARE.ESP, 'B', 0x5D4, ([17,9],None, ('Rf', None)), '"0x{:02x}".format($)'),
}
# ======================================================================
SETTING_5_11_0 = copy.copy(SETTING_5_10_0)
SETTING_5_11_0.update ({
'display_model': (HARDWARE.ESP, 'B', 0x2D2, (None, '0 <= $ <= 16', ('Display', '"Model {}".format($)')) ),
'display_mode': (HARDWARE.ESP, 'B', 0x2D3, (None, '0 <= $ <= 5', ('Display', '"Mode {}".format($)')) ),
'display_refresh': (HARDWARE.ESP, 'B', 0x2D4, (None, '1 <= $ <= 7', ('Display', '"Refresh {}".format($)')) ),
'display_rows': (HARDWARE.ESP, 'B', 0x2D5, (None, '1 <= $ <= 32', ('Display', '"Rows {}".format($)')) ),
'display_cols': (HARDWARE.ESP, 'B', 0x2D6, ([2], '1 <= $ <= 40', ('Display', '"Cols{} {}".format(#+1,$)')) ),
'display_address': (HARDWARE.ESP, 'B', 0x2D8, ([8], None, ('Display', '"Address{} {}".format(#+1,$)')) ),
'display_dimmer': (HARDWARE.ESP, 'B', 0x2E0, (None, '0 <= $ <= 100', ('Display', '"Dimmer {}".format($)')) ),
'display_size': (HARDWARE.ESP, 'B', 0x2E1, (None, '1 <= $ <= 4', ('Display', '"Size {}".format($)')) ),
})
SETTING_5_11_0['flag'][1].update ({
'light_signal': (HARDWARE.ESP, '<L', (0x010,1,18), (None, None, ('SetOption', '"SetOption18 {}".format($)')) ),
})
SETTING_5_11_0.pop('mqtt_fingerprinth',None)
# ======================================================================
SETTING_5_12_0 = copy.copy(SETTING_5_11_0)
SETTING_5_12_0['flag'][1].update ({
'hass_discovery': (HARDWARE.ESP, '<L', (0x010,1,19), (None, None, ('SetOption', '"SetOption19 {}".format($)')) ),
'not_power_linked': (HARDWARE.ESP, '<L', (0x010,1,20), (None, None, ('SetOption', '"SetOption20 {}".format($)')) ),
'no_power_on_check': (HARDWARE.ESP, '<L', (0x010,1,21), (None, None, ('SetOption', '"SetOption21 {}".format($)')) ),
})
# ======================================================================
SETTING_5_13_1 = copy.copy(SETTING_5_12_0)
SETTING_5_13_1.pop('mqtt_fingerprint',None)
SETTING_5_13_1['flag'][1].update ({
'mqtt_serial': (HARDWARE.ESP, '<L', (0x010,1,22), (None, None, ('SetOption', '"SetOption22 {}".format($)')) ),
'rules_enabled': (HARDWARE.ESP, '<L', (0x010,1,23), (None, None, ('SetOption', '"SetOption23 {}".format($)')) ),
'rules_once': (HARDWARE.ESP, '<L', (0x010,1,24), (None, None, ('SetOption', '"SetOption24 {}".format($)')) ),
'knx_enabled': (HARDWARE.ESP, '<L', (0x010,1,25), (None, None, ('KNX', '"KNX_ENABLED {}".format($)')) ),
})
SETTING_5_13_1.update ({
'baudrate': (HARDWARE.ESP, 'B', 0x09D, (None, None, ('Serial', '"Baudrate {}".format($)')), ('$ * 1200','$ // 1200') ),
'mqtt_fingerprint1': (HARDWARE.ESP, 'B', 0x1AD, ([20], None, ('MQTT', '"MqttFingerprint1 {}".format(" ".join("{:02X}".format(c) for c in @["mqtt_fingerprint1"]))')), '"0x{:02x}".format($)' ),
'mqtt_fingerprint2': (HARDWARE.ESP, 'B', 0x1AD+20, ([20], None, ('MQTT', '"MqttFingerprint2 {}".format(" ".join("{:02X}".format(c) for c in @["mqtt_fingerprint2"]))')), '"0x{:02x}".format($)' ),
'energy_power_delta': (HARDWARE.ESP, 'B', 0x33F, (None, None, ('Power', '"PowerDelta {}".format($)')) ),
'light_rotation': (HARDWARE.ESP, '<H', 0x39E, (None, None, ('Light', '"Rotation {}".format($)')) ),
'serial_delimiter': (HARDWARE.ESP, 'B', 0x451, (None, None, ('Serial', '"SerialDelimiter {}".format($)')) ),
'sbaudrate': (HARDWARE.ESP, 'B', 0x452, (None, None, ('Serial', '"SBaudrate {}".format($)')), ('$ * 1200','$ // 1200') ),
'knx_GA_registered': (HARDWARE.ESP, 'B', 0x4A5, (None, None, ('KNX', None)) ),
'knx_CB_registered': (HARDWARE.ESP, 'B', 0x4A8, (None, None, ('KNX', None)) ),
'timer': (HARDWARE.ESP, {
'time': (HARDWARE.ESP, '<L', (0x670,11, 0),(None, '0 <= $ < 1440', ('Timer', '"Timer{} {{\\\"Arm\\\":{arm},\\\"Mode\\\":{mode},\\\"Time\\\":\\\"{tsign}{time}\\\",\\\"Window\\\":{window},\\\"Days\\\":\\\"{days}\\\",\\\"Repeat\\\":{repeat},\\\"Output\\\":{device},\\\"Action\\\":{power}}}".format(#+1, arm=@["timer"][#]["arm"],mode=@["timer"][#]["mode"],tsign="-" if @["timer"][#]["mode"]>0 and @["timer"][#]["time"]>(12*60) else "",time=time.strftime("%H:%M",time.gmtime((@["timer"][#]["time"] if @["timer"][#]["mode"]==0 else @["timer"][#]["time"] if @["timer"][#]["time"]<=(12*60) else @["timer"][#]["time"]-(12*60))*60)),window=@["timer"][#]["window"],repeat=@["timer"][#]["repeat"],days="{:07b}".format(@["timer"][#]["days"])[::-1],device=@["timer"][#]["device"]+1,power=@["timer"][#]["power"] )')), '"0x{:03x}".format($)' ),
'window': (HARDWARE.ESP, '<L', (0x670, 4,11),(None, None, ('Timer', None)) ),
'repeat': (HARDWARE.ESP, '<L', (0x670, 1,15),(None, None, ('Timer', None)) ),
'days': (HARDWARE.ESP, '<L', (0x670, 7,16),(None, None, ('Timer', None)), '"0b{:07b}".format($)' ),
'device': (HARDWARE.ESP, '<L', (0x670, 4,23),(None, None, ('Timer', None)) ),
'power': (HARDWARE.ESP, '<L', (0x670, 2,27),(None, None, ('Timer', None)) ),
'mode': (HARDWARE.ESP, '<L', (0x670, 2,29),(None, '0 <= $ <= 3', ('Timer', None)) ),
'arm': (HARDWARE.ESP, '<L', (0x670, 1,31),(None, None, ('Timer', None)) ),
}, 0x670, ([16], None, ('Timer', None)) ),
'latitude': (HARDWARE.ESP, 'i', 0x6B0, (None, None, ('Timer', '"Latitude {}".format($)')), ('float($) / 1000000', 'int($ * 1000000)')),
'longitude': (HARDWARE.ESP, 'i', 0x6B4, (None, None, ('Timer', '"Longitude {}".format($)')), ('float($) / 1000000', 'int($ * 1000000)')),
'knx_physsical_addr': (HARDWARE.ESP, '<H', 0x6B8, (None, None, ('KNX', None)) ),
'knx_GA_addr': (HARDWARE.ESP, '<H', 0x6BA, ([10], None, ('KNX', None)) ),
'knx_CB_addr': (HARDWARE.ESP, '<H', 0x6CE, ([10], None, ('KNX', None)) ),
'knx_GA_param': (HARDWARE.ESP, 'B', 0x6E2, ([10], None, ('KNX', None)) ),
'knx_CB_param': (HARDWARE.ESP, 'B', 0x6EC, ([10], None, ('KNX', None)) ),
'rules': (HARDWARE.ESP, '512s',0x800, (None, None, ('Rules', '"Rule {}".format("\\"" if len($) == 0 else $)')) ),
})
# ======================================================================
SETTING_5_14_0 = copy.copy(SETTING_5_13_1)
SETTING_5_14_0['flag'][1].update ({
'device_index_enable': (HARDWARE.ESP, '<L', (0x010,1,26), (None, None, ('SetOption', '"SetOption26 {}".format($)')) ),
})
SETTING_5_14_0['flag'][1].pop('rules_once',None)
SETTING_5_14_0.update ({
'tflag': (HARDWARE.ESP, {
'hemis': (HARDWARE.ESP, '<H', (0x2E2,1, 0), (None, None, ('Management', None)) ),
'week': (HARDWARE.ESP, '<H', (0x2E2,3, 1), (None, '0 <= $ <= 4', ('Management', None)) ),
'month': (HARDWARE.ESP, '<H', (0x2E2,4, 4), (None, '1 <= $ <= 12', ('Management', None)) ),
'dow': (HARDWARE.ESP, '<H', (0x2E2,3, 8), (None, '1 <= $ <= 7', ('Management', None)) ),
'hour': (HARDWARE.ESP, '<H', (0x2E2,5,11), (None, '0 <= $ <= 23', ('Management', None)) ),
}, 0x2E2, ([2], None, ('Management', None)), (None, None) ),
'param': (HARDWARE.ESP, 'B', 0x2FC, ([18], None, ('SetOption', '"SetOption{} {}".format(#+32,$)')) ),
'toffset': (HARDWARE.ESP, '<h', 0x30E, ([2], None, ('Management', '"{cmnd} {hemis},{week},{month},{dow},{hour},{toffset}".format(cmnd="TimeSTD" if #==0 else "TimeDST", hemis=@["tflag"][#]["hemis"], week=@["tflag"][#]["week"], month=@["tflag"][#]["month"], dow=@["tflag"][#]["dow"], hour=@["tflag"][#]["hour"], toffset=value)')) ),
})
# ======================================================================
SETTING_6_0_0 = copy.copy(SETTING_5_14_0)
SETTING_6_0_0.update ({
'cfg_holder': (HARDWARE.ESP, '<H', 0x000, (None, None, ('System', None)), ),
'cfg_size': (HARDWARE.ESP, '<H', 0x002, (None, None, ('System', None)), (None, False)),
'bootcount': (HARDWARE.ESP, '<H', 0x00C, (None, None, ('System', None)), (None, False)),
'cfg_crc': (HARDWARE.ESP, '<H', 0x00E, (None, None, ('System', None)), '"0x{:04x}".format($)'),
'rule_enabled': (HARDWARE.ESP, {
'rule1': (HARDWARE.ESP, 'B', (0x49F,1,0), (None, None, ('Rules', '"Rule1 {}".format($)')) ),
'rule2': (HARDWARE.ESP, 'B', (0x49F,1,1), (None, None, ('Rules', '"Rule2 {}".format($)')) ),
'rule3': (HARDWARE.ESP, 'B', (0x49F,1,2), (None, None, ('Rules', '"Rule3 {}".format($)')) ),
}, 0x49F, (None, None, ('Rules', None)), (None, None) ),
'rule_once': (HARDWARE.ESP, {
'rule1': (HARDWARE.ESP, 'B', (0x4A0,1,0), (None, None, ('Rules', '"Rule1 {}".format($+4)')) ),
'rule2': (HARDWARE.ESP, 'B', (0x4A0,1,1), (None, None, ('Rules', '"Rule2 {}".format($+4)')) ),
'rule3': (HARDWARE.ESP, 'B', (0x4A0,1,2), (None, None, ('Rules', '"Rule3 {}".format($+4)')) ),
}, 0x4A0, (None, None, ('Rules', None)), (None, None) ),
'mems': (HARDWARE.ESP, '10s', 0x7CE, ([5], None, ('Rules', '"Mem{} {}".format(#+1,"\\"" if len($) == 0 else $)')) ),
'rules': (HARDWARE.ESP, '512s',0x800, ([3], None, ('Rules', '"Rule{} {}".format(#+1,"\\"" if len($) == 0 else $)')) ),
})
SETTING_6_0_0['flag'][1].update ({
'knx_enable_enhancement': (HARDWARE.ESP, '<L', (0x010,1,27), (None, None, ('KNX', '"KNX_ENHANCED {}".format($)')) ),
})
# ======================================================================
SETTING_6_1_1 = copy.copy(SETTING_6_0_0)
SETTING_6_1_1.update ({
'flag3': (HARDWARE.ESP, '<L', 0x3A0, (None, None, (INTERNAL, None)), '"0x{:08x}".format($)' ),
'switchmode': (HARDWARE.ESP, 'B', 0x3A4, ([8], '0 <= $ <= 7', ('Control', '"SwitchMode{} {}".format(#+1,$)')) ),
'mcp230xx_config': (HARDWARE.ESP, {
'pinmode': (HARDWARE.ESP, '<H', (0x6F6,3, 0), (None, None, ('Sensor', '"Sensor29 {pin},{pinmode},{pullup},{intmode}".format(pin=#, pinmode=@["mcp230xx_config"][#]["pinmode"], pullup=@["mcp230xx_config"][#]["pullup"], intmode=@["mcp230xx_config"][#]["int_report_mode"])')) ),
'pullup': (HARDWARE.ESP, '<H', (0x6F6,1, 3), (None, None, ('Sensor', None)) ),
'saved_state': (HARDWARE.ESP, '<H', (0x6F6,1, 4), (None, None, ('Sensor', None)) ),
'int_report_mode': (HARDWARE.ESP, '<H', (0x6F6,2, 5), (None, None, ('Sensor', None)) ),
'int_report_defer': (HARDWARE.ESP, '<H', (0x6F6,4, 7), (None, None, ('Sensor', None)) ),
'int_count_en': (HARDWARE.ESP, '<H', (0x6F6,1,11), (None, None, ('Sensor', None)) ),
}, 0x6F6, ([16], None, ('Sensor', None)), (None, None) ),
})
SETTING_6_1_1['flag'][1].update ({
'rf_receive_decimal': (HARDWARE.ESP, '<L', (0x010,1,28), (None, None, ('SetOption' , '"SetOption28 {}".format($)')) ),
'ir_receive_decimal': (HARDWARE.ESP, '<L', (0x010,1,29), (None, None, ('SetOption', '"SetOption29 {}".format($)')) ),
'hass_light': (HARDWARE.ESP, '<L', (0x010,1,30), (None, None, ('SetOption', '"SetOption30 {}".format($)')) ),
})
# ======================================================================
SETTING_6_2_1 = copy.copy(SETTING_6_1_1)
SETTING_6_2_1.update ({
'rule_stop': (HARDWARE.ESP, {
'rule1': (HARDWARE.ESP, 'B', (0x1A7,1,0), (None, None, ('Rules', '"Rule1 {}".format($+8)')) ),
'rule2': (HARDWARE.ESP, 'B', (0x1A7,1,1), (None, None, ('Rules', '"Rule2 {}".format($+8)')) ),
'rule3': (HARDWARE.ESP, 'B', (0x1A7,1,2), (None, None, ('Rules', '"Rule3 {}".format($+8)')) ),
}, 0x1A7, None),
'display_rotate': (HARDWARE.ESP, 'B', 0x2FA, (None, '0 <= $ <= 3', ('Display', '"Rotate {}".format($)')) ),
'display_font': (HARDWARE.ESP, 'B', 0x312, (None, '1 <= $ <= 4', ('Display', '"Font {}".format($)')) ),
'flag3': (HARDWARE.ESP, {
'timers_enable': (HARDWARE.ESP, '<L', (0x3A0,1, 0), (None, None, ('Timer', '"Timers {}".format($)')) ),
'user_esp8285_enable': (HARDWARE.ESP, '<L', (0x3A0,1,31), (None, None, (INTERNAL, None)) ),
}, 0x3A0, (None, None, (VIRTUAL, None)), (None, None) ),
'button_debounce': (HARDWARE.ESP, '<H', 0x542, (None, '40 <= $ <= 1000', ('Control', '"ButtonDebounce {}".format($)')) ),
'switch_debounce': (HARDWARE.ESP, '<H', 0x66E, (None, '40 <= $ <= 1000', ('Control', '"SwitchDebounce {}".format($)')) ),
'mcp230xx_int_prio': (HARDWARE.ESP, 'B', 0x716, (None, None, ('Sensor', None)) ),
'mcp230xx_int_timer': (HARDWARE.ESP, '<H', 0x718, (None, None, ('Sensor', None)) ),
})
SETTING_6_2_1['flag'][1].pop('rules_enabled',None)
SETTING_6_2_1['flag'][1].update ({
'mqtt_serial_raw': (HARDWARE.ESP, '<L', (0x010,1,23), (None, None, ('SetOption', '"SetOption23 {}".format($)')) ),
'global_state': (HARDWARE.ESP, '<L', (0x010,1,31), (None, None, ('SetOption', '"SetOption31 {}".format($)')) ),
})
SETTING_6_2_1['flag2'][1].update ({
'axis_resolution': (HARDWARE.ESP, '<L', (0x5BC,2,13), (None, None, ('Sensor', None)) ), # Need to be services by command Sensor32