Skip to content

Commit 4c29d7d

Browse files
committed
refactor camel and snake naming in setPref
Same change as done in getPerf to have less branches (simplifies the code).
1 parent 839bbbc commit 4c29d7d

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

meshtastic/__main__.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def setPref(config, comp_name, valStr) -> bool:
177177

178178
snake_name = meshtastic.util.camel_to_snake(name[-1])
179179
camel_name = meshtastic.util.snake_to_camel(name[-1])
180+
uni_name = camel_name if mt_config.camel_case else snake_name
180181
logging.debug(f"snake_name:{snake_name}")
181182
logging.debug(f"camel_name:{camel_name}")
182183

@@ -213,14 +214,9 @@ def setPref(config, comp_name, valStr) -> bool:
213214
if e:
214215
val = e.number
215216
else:
216-
if mt_config.camel_case:
217-
print(
218-
f"{name[0]}.{camel_name} does not have an enum called {val}, so you can not set it."
219-
)
220-
else:
221-
print(
222-
f"{name[0]}.{snake_name} does not have an enum called {val}, so you can not set it."
223-
)
217+
print(
218+
f"{name[0]}.{uni_name} does not have an enum called {val}, so you can not set it."
219+
)
224220
print(f"Choices in sorted order are:")
225221
names = []
226222
for f in enumType.values:
@@ -255,10 +251,7 @@ def setPref(config, comp_name, valStr) -> bool:
255251
getattr(config_values, pref.name)[:] = cur_vals
256252

257253
prefix = f"{'.'.join(name[0:-1])}." if config_type.message_type is not None else ""
258-
if mt_config.camel_case:
259-
print(f"Set {prefix}{camel_name} to {valStr}")
260-
else:
261-
print(f"Set {prefix}{snake_name} to {valStr}")
254+
print(f"Set {prefix}{uni_name} to {valStr}")
262255

263256
return True
264257

0 commit comments

Comments
 (0)