python icon indicating copy to clipboard operation
python copied to clipboard

Enable `--info` to return data as JSON

Open juergenRe opened this issue 4 weeks ago • 0 comments

Content, Request

In issue #862 a request was formulated to return the result of --info command 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 --fmt parameter in the meshtastic call, this time used as a modifier for the --info command.

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__.py now is fully generic, adding a new formatter like yaml will also not affect this part of the code.

Testing

  • All unit tests have been updated so they reflect the new structure and test things correctly
  • The formatter classes got new unit tests, based on sample json data files creating different sets of data simulating the return data from node or interface.
  • Unit and integration tests pass 100%. I did not run smoke tests, because most of them anyway fail, so the result is not meaningful.

juergenRe avatar Nov 30 '25 08:11 juergenRe