From 6932692058fdfe72a49e20d3218b671372abc799 Mon Sep 17 00:00:00 2001 From: Rohit Jadhav <69809379+jadhavrohit924@users.noreply.github.com> Date: Fri, 28 Jul 2023 12:07:59 +0530 Subject: [PATCH] [ESP32] Allowing empty semantic tags list in SupportedModes attribute of ModeSelect (#28324) * [ESP32] Allowing empty semantic tags list in SupportedModes attribute of ModeSelect * Restyled by autopep8 --------- Co-authored-by: Restyled.io --- .../tools/generate_esp32_chip_factory_bin.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/scripts/tools/generate_esp32_chip_factory_bin.py b/scripts/tools/generate_esp32_chip_factory_bin.py index 303f5cda968fda..6ee881d50689fe 100755 --- a/scripts/tools/generate_esp32_chip_factory_bin.py +++ b/scripts/tools/generate_esp32_chip_factory_bin.py @@ -203,7 +203,7 @@ def ishex(s): # get_fixed_label_dict() converts the list of strings to per endpoint dictionaries. # example input : ['0/orientation/up', '1/orientation/down', '2/orientation/down'] -# example outout : {'0': [{'orientation': 'up'}], '1': [{'orientation': 'down'}], '2': [{'orientation': 'down'}]} +# example output : {'0': [{'orientation': 'up'}], '1': [{'orientation': 'down'}], '2': [{'orientation': 'down'}]} def get_fixed_label_dict(fixed_labels): @@ -227,8 +227,13 @@ def get_fixed_label_dict(fixed_labels): return fl_dict # get_supported_modes_dict() converts the list of strings to per endpoint dictionaries. -# example input : ['0/label1/1/"1\0x8000, 2\0x8000", 1/label2/1/"1\0x8000, 2\0x8000"'] -# example outout : {'1': [{'Label': 'label1', 'Mode': 0, 'Semantic_Tag': [{'value': 1, 'mfgCode': 32768}, {'value': 2, 'mfgCode': 32768}]}, {'Label': 'label2', 'Mode': 1, 'Semantic_Tag': [{'value': 1, 'mfgCode': 32768}, {'value': 2, 'mfgCode': 32768}]}]} +# example with semantic tags +# input : ['0/label1/1/"1\0x8000, 2\0x8000" 1/label2/1/"1\0x8000, 2\0x8000"'] +# output : {'1': [{'Label': 'label1', 'Mode': 0, 'Semantic_Tag': [{'value': 1, 'mfgCode': 32768}, {'value': 2, 'mfgCode': 32768}]}, {'Label': 'label2', 'Mode': 1, 'Semantic_Tag': [{'value': 1, 'mfgCode': 32768}, {'value': 2, 'mfgCode': 32768}]}]} + +# example without semantic tags +# input : ['0/label1/1 1/label2/1'] +# output : {'1': [{'Label': 'label1', 'Mode': 0, 'Semantic_Tag': []}, {'Label': 'label2', 'Mode': 1, 'Semantic_Tag': []}]} def get_supported_modes_dict(supported_modes): @@ -240,8 +245,10 @@ def get_supported_modes_dict(supported_modes): label = mode_label_strs[1] ep = mode_label_strs[2] - semantic_tag_strs = mode_label_strs[3].split(', ') - semantic_tags = [{"value": int(v.split('\\')[0]), "mfgCode": int(v.split('\\')[1], 16)} for v in semantic_tag_strs] + semantic_tags = '' + if (len(mode_label_strs) == 4): + semantic_tag_strs = mode_label_strs[3].split(', ') + semantic_tags = [{"value": int(v.split('\\')[0]), "mfgCode": int(v.split('\\')[1], 16)} for v in semantic_tag_strs] mode_dict = {"Label": label, "Mode": int(mode), "Semantic_Tag": semantic_tags}