Skip to content

Commit

Permalink
clean up settings response to use CopyFrom to be better at repeated a…
Browse files Browse the repository at this point in the history
…nd nested fields
  • Loading branch information
ianmcorvidae committed Sep 12, 2024
1 parent 180ddbc commit cc2067b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions meshtastic/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def onResponseRequestSettings(self, p):
print("")
adminMessage = p["decoded"]["admin"]
if "getConfigResponse" in adminMessage:
oneof = "get_config_response"
resp = adminMessage["getConfigResponse"]
field = list(resp.keys())[0]
config_type = self.localConfig.DESCRIPTOR.fields_by_name.get(
Expand All @@ -106,6 +107,7 @@ def onResponseRequestSettings(self, p):
if config_type is not None:
config_values = getattr(self.localConfig, config_type.name)
elif "getModuleConfigResponse" in adminMessage:
oneof = "get_module_config_response"
resp = adminMessage["getModuleConfigResponse"]
field = list(resp.keys())[0]
config_type = self.moduleConfig.DESCRIPTOR.fields_by_name.get(
Expand All @@ -118,8 +120,8 @@ def onResponseRequestSettings(self, p):
)
return
if config_values is not None:
for key, value in resp[field].items():
setattr(config_values, camel_to_snake(key), value)
raw_config = getattr(getattr(adminMessage['raw'], oneof), field)
config_values.CopyFrom(raw_config)
print(f"{str(camel_to_snake(field))}:\n{str(config_values)}")

def requestConfig(self, configType):
Expand Down

0 comments on commit cc2067b

Please sign in to comment.