Skip to content

Conversation

dandrzejewski
Copy link
Contributor

This PR adds the ability to specify which node information is shown in the table produced by the --nodes parameter. It is optional, and specifying the --nodes parameter without the new param outputs the same table it does today.

The new CLI param is --show-fields and it requires a comma-separated list of field names. It can only be specified alongside --nodes.

For example, --nodes --show-fields user.id,user.hwModel,position.altitude will output the following table (the "N" column always shows):

╒═════╤═══════════╤═════════════════╤════════════╕
│   N │ ID        │ Hardware        │ Altitude   │
╞═════╪═══════════╪═════════════════╪════════════╡
│   1 │ !4cbc2ae6 │ RAK4631         │ N/A        │
├─────┼───────────┼─────────────────┼────────────┤
│   2 │ !12b5aebe │ RAK4631         │ 382m       │
├─────┼───────────┼─────────────────┼────────────┤
│   3 │ !29dc16d7 │ RAK4631         │ 314m       │
├─────┼───────────┼─────────────────┼────────────┤
│   4 │ !b4640294 │ RAK4631         │ 355m       │
├─────┼───────────┼─────────────────┼────────────┤
│   5 │ !1117fb10 │ TRACKER_T1000_E │ 327m       │
╘═════╧═══════════╧═════════════════╧════════════╛

I also did a bit of refactoring in the showNodes() function in mesh_interface.py related to this. Rather than simply going through and retrieving individual bits of information out of the data structures, there's now a default list of fields to show and that list contains the fields that are shown today.

There's now a mapping of field names to human-readable names. Fields that are not in the mapping will be shown with raw field names and values, for example:

--nodes --show-fields user.id,user.hwModel,position.altitude,deviceMetrics.voltage

will show the following until someone goes in and adds the name mapping and value formatting. Note the column header name is not human-readable, the actual values are not formatted to a particular precision, and there's no unit of measure shown.

╒═════╤═══════════╤═════════════════╤════════════╤═════════════════════════╕
│   N │ ID        │ Hardware        │ Altitude   │   deviceMetrics.voltage │
╞═════╪═══════════╪═════════════════╪════════════╪═════════════════════════╡
│   1 │ !4cbc2ae6 │ RAK4631         │ N/A        │                   4.098 │
├─────┼───────────┼─────────────────┼────────────┼─────────────────────────┤
│   2 │ !12b5aebe │ RAK4631         │ 382m       │                   3.151 │
├─────┼───────────┼─────────────────┼────────────┼─────────────────────────┤
│   3 │ !29dc16d7 │ RAK4631         │ 314m       │                   2.69  │
├─────┼───────────┼─────────────────┼────────────┼─────────────────────────┤
│   4 │ !b4640294 │ RAK4631         │ 355m       │                   2.917 │
├─────┼───────────┼─────────────────┼────────────┼─────────────────────────┤
│   5 │ !1117fb10 │ TRACKER_T1000_E │ 327m       │                   3.222 │
╘═════╧═══════════╧═════════════════╧════════════╧═════════════════════════╛

@CLAassistant
Copy link

CLAassistant commented Feb 15, 2025

CLA assistant check
All committers have signed the CLA.

@pdxlocations
Copy link
Member

I've given this PR a test drive and functionally it works well. I'll let a dev comment on the code and structure. Nice!

Copy link
Contributor

@ianmcorvidae ianmcorvidae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caught one small thing, and also set the CI to run. We'll see if that turns anything up, but otherwise this looks good to me! I'm sure there's some stuff we could do to make it more concise or smart, but I think this way is good for now.

return None
return value

if showFields is None or showFields.count == 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that count is a method on lists, not a property, so this wouldn't ever be true. I'm guessing you mean len(showFields) == 0 here.

@ianmcorvidae
Copy link
Contributor

Ah, yeah, looks like pylint is complaining a bit.

If you want to check the CI stuff locally, you can run:

poetry run pylint meshtastic examples/ --ignore-patterns ".*_pb2.pyi?$"

and poetry run mypy meshtastic/

and poetry run pytest

It looks like I may have messed something up with mypy, though, just pushed a fix for that to master. So if it complains about argcomplete then merge in master, or rebase.

@dandrzejewski
Copy link
Contributor Author

poetry run pylint meshtastic examples/ --ignore-patterns ".*_pb2.pyi?$"

Want to run something by you. Running pylint, I see:

meshtastic\mesh_interface.py:290: error: Incompatible types in assignment (expression has type "Any | None", variable has type "dict[str, Any]") [assignment]

But I'm specifically taking advantage of Python's dynamic typing here to save a line or two. value starts out as a dict but becomes a string.

I "fixed" it by indicating that it could be a str, dict or even None:

            value: Optional[Union[str, dict]] = node_dict

@ianmcorvidae
Copy link
Contributor

I think that's fine, particularly given the return value for the function in general is Any. It's a working variable, so I think the type being a little funky is expected, just lets us catch it if something falls outside the assumptions!

Copy link

codecov bot commented Feb 19, 2025

Codecov Report

Attention: Patch coverage is 90.62500% with 6 lines in your changes missing coverage. Please review.

Project coverage is 60.60%. Comparing base (5837bd0) to head (dd88037).
Report is 12 commits behind head on master.

Files with missing lines Patch % Lines
meshtastic/mesh_interface.py 93.22% 4 Missing ⚠️
meshtastic/__main__.py 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #736      +/-   ##
==========================================
+ Coverage   60.13%   60.60%   +0.46%     
==========================================
  Files          24       24              
  Lines        3986     4031      +45     
==========================================
+ Hits         2397     2443      +46     
+ Misses       1589     1588       -1     
Flag Coverage Δ
unittests 60.60% <90.62%> (+0.46%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ianmcorvidae
Copy link
Contributor

Fixed up a couple small things that pylint/pytest were complaining about since I know you were having some install issues from discord. I think this looks good to me, thanks for the contribution!

@ianmcorvidae ianmcorvidae merged commit acc4714 into meshtastic:master Feb 19, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants