Skip to content

Commit 0f4aa73

Browse files
committed
add custom vars to completion list
1 parent ed746eb commit 0f4aa73

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/meshcore_cli/meshcore_cli.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,11 @@ def make_completion_dict(contacts, to=None):
278278
"manual_add_contacts":None,
279279
"telemetry_mode_base":None,
280280
"telemetry_mode_loc":None,
281+
"custom":None
281282
},
282283
})
284+
completion_list["set"].update(make_completion_dict.custom_vars)
285+
completion_list["get"].update(make_completion_dict.custom_vars)
283286
else :
284287
completion_list.update({
285288
"send" : None,
@@ -357,6 +360,7 @@ def make_completion_dict(contacts, to=None):
357360
})
358361

359362
return completion_list
363+
make_completion_dict.custom_vars = {}
360364

361365
async def interactive_loop(mc, to=None) :
362366
print("""Interactive mode, most commands from terminal chat should work.
@@ -389,6 +393,12 @@ async def interactive_loop(mc, to=None) :
389393

390394
bindings = KeyBindings()
391395

396+
res = await mc.commands.get_custom_vars()
397+
cv = []
398+
if res.type != EventType.ERROR :
399+
cv = list(res.payload.keys())
400+
make_completion_dict.custom_vars = {k:None for k in cv}
401+
392402
# Add our own key binding.
393403
@bindings.add("escape")
394404
def _(event):
@@ -863,7 +873,9 @@ async def next_cmd(mc, cmds, json_output=False):
863873
lon : longitude
864874
radio : radio parameters
865875
tx : tx power
866-
print_snr : snr display in messages""")
876+
print_snr : snr display in messages
877+
custom : all custom variables in json format
878+
each custom var can also be get/set directly""")
867879
case "print_name":
868880
if json_output :
869881
print(json.dumps({"print_name" : interactive_loop.print_name}))
@@ -956,14 +968,24 @@ async def next_cmd(mc, cmds, json_output=False):
956968
print(json.dumps({"telemetry_mode_loc" : mc.self_info["telemetry_mode_loc"]}))
957969
else :
958970
print(f"telemetry_mode_loc: {mc.self_info['telemetry_mode_loc']}")
971+
case "custom" :
972+
res = await mc.commands.get_custom_vars()
973+
logger.debug(res)
974+
if res.type == EventType.ERROR :
975+
if json_output :
976+
print(json.dumps(res))
977+
else :
978+
logger.error("Couldn't get custom variables")
979+
else :
980+
print(json.dumps(res.payload, indent=4))
959981
case _ :
960982
res = await mc.commands.get_custom_vars()
961983
logger.debug(res)
962984
if res.type == EventType.ERROR :
963985
if json_output :
964986
print(json.dumps(res))
965987
else :
966-
print(f"Couldn't get custom variables")
988+
logger.error(f"Couldn't get custom variables")
967989
else :
968990
try:
969991
if cmds[1].startswith("_"):

0 commit comments

Comments
 (0)