Enable --info to return data as JSON
#872
Open
+1,014
−123
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Content, Request
In issue #862 a request was formulated to return the result of
--infocommand in JSON or YAML format instead of current textual format, which is not machine readable. (I believe there was also another issue opened like this).While the issue #862 goes further in asking some instaneous return of actual device metrics and telemetry data, this PR only covers the return format part.
Solution description
The solution reuses the approach from PR #867 in adding a
--fmtparameter in the meshtastic call, this time used as a modifier for the--infocommand.From a design point of view, I separated the data aspect (what will be shown) from the formatting aspect (how the data will be presented). Thus, the interface and node classes will only return data dictionaries which then can be treated further. Any addition or change in formatting will never introduce a change in node or interface classes.
Formatting is externalized in separate classes, using a factory pattern to instantiate the formatting class.
The call in
__main__.pynow is fully generic, adding a new formatter like yaml will also not affect this part of the code.Testing