Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

464: allow for 0x node prefix values #731

Merged
merged 19 commits into from
Feb 19, 2025

Conversation

migillett
Copy link
Contributor

@migillett migillett commented Jan 26, 2025

A potential answer to issue 464. This allows users to run commands using a different prefix (0x) from the meshtastic CLI.

The code change here checks for if the node ID supplied can be turned into an int or not. If so, just pass the node id directly in. If not, it must be a string. Grab the last 8 characters of the node id and force-format the id to have a ! prefix. That way users can provide any prefix they want to the meshtastic CLI.

@ianmcorvidae
Copy link
Contributor

This doesn't look bad, aside from the CI errors (looks like it wants a tuple, not a list, for the metavar). However, I'd prefer if this handling was moved into _sendPacket, which is what currently processes the !xxxxxxxx into integers, and it's a bit lower level. Not everything flows through sendData, though most does.

@migillett
Copy link
Contributor Author

@ianmcorvidae ok! I can move this into the _sendPacket function. That's no problem. Do we still want to keep the documentation for [!xxxxxxxx, xxxxxxxxxx] or drop those changes?

@ianmcorvidae
Copy link
Contributor

ianmcorvidae commented Feb 18, 2025

I think those metavar changes are fine but it looks like mypy wants it to be a tuple instead of a list. That should just mean ("!XXXXXXXX", "0xXXXXXXXX") instead of ["!XXXXXXXX", "0xXXXXXXXX"] for those, I believe.

I do also notice that it's complaining that int | str isn't indexable due to the code you have ensuring the presence of the !. With integrating it into _sendPacket that may go away, though. If you want to check the stuff that CI does, but locally:

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

@migillett
Copy link
Contributor Author

@ianmcorvidae ok, I think that got it. I tried several things but the metavars deal would constantly throw errors no matter what I did. Once I went back to the old metavars definition of metavar="!xxxxxxxx" the tests passed successfully. I instead added a bit to the help deal telling about using ! or 0x prefixes. Technically no prefixes are required at all with how we're parsing hexadecimal strings with this change though. Want to see what you think about that one.

I also ran a manual test locally between my nodes using ! and 0x prefixes and both worked

@migillett
Copy link
Contributor Author

I could also do a if nodeId.startswith('!') or nodeId.startswith('0x'): too. but I didn't want to hard-code prefixes unless necessary. But I'm game for either.

@migillett
Copy link
Contributor Author

just saw the build errors, I'm on it.

@migillett
Copy link
Contributor Author

@ianmcorvidae sorry about that. fixed the issues the linter was yelling about.

@ianmcorvidae
Copy link
Contributor

Perfect, no worries. I'll kick it off again in case there's anything else. The linter can get a bit annoying at times so that's understood, haha

@ianmcorvidae
Copy link
Contributor

Looks like that's all resolved now. Thanks for the contribution!

Copy link

codecov bot commented Feb 19, 2025

Codecov Report

Attention: Patch coverage is 62.50000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 60.58%. Comparing base (fc3b81d) to head (23ea19c).
Report is 40 commits behind head on master.

Files with missing lines Patch % Lines
meshtastic/mesh_interface.py 40.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #731      +/-   ##
==========================================
+ Coverage   60.35%   60.58%   +0.22%     
==========================================
  Files          24       24              
  Lines        3970     4031      +61     
==========================================
+ Hits         2396     2442      +46     
- Misses       1574     1589      +15     
Flag Coverage Δ
unittests 60.58% <62.50%> (+0.22%) ⬆️

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 ianmcorvidae merged commit 5f174b2 into meshtastic:master Feb 19, 2025
11 checks passed
@migillett
Copy link
Contributor Author

@ianmcorvidae you're welcome! hopefully the first of many.

@migillett migillett deleted the 464/0x-prefix branch February 19, 2025 16:31
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.

2 participants