mirror of
https://github.com/bckelley/tconnectsync.git
synced 2026-08-24 03:34:12 -05:00
fix duplicate enum keys
This commit is contained in:
@@ -5286,9 +5286,9 @@ class LidCgmDataFsl3(BaseEvent):
|
|||||||
ValidAlgstateAlgstateIs100 = 2**7
|
ValidAlgstateAlgstateIs100 = 2**7
|
||||||
EgvWasSuccessfullyAddedToCgmSubsystemArrayE = 2**8
|
EgvWasSuccessfullyAddedToCgmSubsystemArrayE = 2**8
|
||||||
OmrReadingType = 2**9
|
OmrReadingType = 2**9
|
||||||
SensorTypeSeeCgmtxtypeEnum = 2**11
|
SensorTypeSeeCgmtxtypeEnum_11 = 2**11
|
||||||
SensorTypeSeeCgmtxtypeEnum = 2**12
|
SensorTypeSeeCgmtxtypeEnum_12 = 2**12
|
||||||
SensorTypeSeeCgmtxtypeEnum = 2**13
|
SensorTypeSeeCgmtxtypeEnum_13 = 2**13
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def egvInfoBitmask(self):
|
def egvInfoBitmask(self):
|
||||||
|
|||||||
@@ -39,15 +39,40 @@ def enumNameFormat(text):
|
|||||||
|
|
||||||
return f'{t[0].upper()}{t[1:]}'
|
return f'{t[0].upper()}{t[1:]}'
|
||||||
|
|
||||||
|
|
||||||
|
def uniqueMemberNames(tx):
|
||||||
|
names = {}
|
||||||
|
|
||||||
|
for key, value in tx.items():
|
||||||
|
name = enumNameFormat(value)
|
||||||
|
if not name:
|
||||||
|
continue
|
||||||
|
names.setdefault(name, []).append(str(key))
|
||||||
|
|
||||||
|
unique_names = {}
|
||||||
|
for key, value in tx.items():
|
||||||
|
name = enumNameFormat(value)
|
||||||
|
if not name:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if len(names[name]) == 1:
|
||||||
|
unique_names[key] = name
|
||||||
|
continue
|
||||||
|
|
||||||
|
unique_names[key] = f'{name}_{key}'
|
||||||
|
|
||||||
|
return unique_names
|
||||||
|
|
||||||
def transform_enum(event_def, name, name_fmt, field, tx):
|
def transform_enum(event_def, name, name_fmt, field, tx):
|
||||||
out = []
|
out = []
|
||||||
|
member_names = uniqueMemberNames(tx)
|
||||||
lines_for_out = json.dumps(tx, indent=4).splitlines()
|
lines_for_out = json.dumps(tx, indent=4).splitlines()
|
||||||
out += [f'{enumNameFormat(name_fmt)}Map = {lines_for_out[0]}']
|
out += [f'{enumNameFormat(name_fmt)}Map = {lines_for_out[0]}']
|
||||||
out += lines_for_out[1:]
|
out += lines_for_out[1:]
|
||||||
out += ['']
|
out += ['']
|
||||||
out += [f'class {enumNameFormat(name_fmt)}Enum(Enum):']
|
out += [f'class {enumNameFormat(name_fmt)}Enum(Enum):']
|
||||||
out += [
|
out += [
|
||||||
f' {enumNameFormat(v)} = {k}' for k, v in tx.items() if enumNameFormat(v)
|
f' {member_names[k]} = {k}' for k, v in tx.items() if k in member_names
|
||||||
]
|
]
|
||||||
out += ['']
|
out += ['']
|
||||||
out += [
|
out += [
|
||||||
@@ -77,13 +102,14 @@ def transform_dictionary(event_def, name, name_fmt, field, tx):
|
|||||||
|
|
||||||
def transform_bitmask(event_def, name, name_fmt, field, tx):
|
def transform_bitmask(event_def, name, name_fmt, field, tx):
|
||||||
out = []
|
out = []
|
||||||
|
member_names = uniqueMemberNames(tx)
|
||||||
lines_for_out = json.dumps(tx, indent=4).splitlines()
|
lines_for_out = json.dumps(tx, indent=4).splitlines()
|
||||||
out += [f'{enumNameFormat(name_fmt)}Map = {lines_for_out[0]}']
|
out += [f'{enumNameFormat(name_fmt)}Map = {lines_for_out[0]}']
|
||||||
out += lines_for_out[1:]
|
out += lines_for_out[1:]
|
||||||
out += ['']
|
out += ['']
|
||||||
out += [f'class {enumNameFormat(name_fmt)}Bitmask(IntFlag):',]
|
out += [f'class {enumNameFormat(name_fmt)}Bitmask(IntFlag):',]
|
||||||
out += [
|
out += [
|
||||||
f' {enumNameFormat(v)} = 2**{k}' for k, v in tx.items() if enumNameFormat(v)
|
f' {member_names[k]} = 2**{k}' for k, v in tx.items() if k in member_names
|
||||||
]
|
]
|
||||||
out += ['']
|
out += ['']
|
||||||
out += [
|
out += [
|
||||||
|
|||||||
Reference in New Issue
Block a user