Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions exampleConfig.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# example config using camelCase keys
owner: Bob TBeam
ownerShort: BOB

channelUrl: https://www.meshtastic.org/d/#CgUYAyIBAQ

Expand Down
1 change: 1 addition & 0 deletions example_config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# example configuration file with snake_case keys
owner: Bob TBeam
owner_short: BOB

channel_url: https://www.meshtastic.org/d/#CgUYAyIBAQ

Expand Down
20 changes: 19 additions & 1 deletion meshtastic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ def onConnected(interface):
print(f"Setting device owner to {args.set_owner}")
interface.getNode(args.dest).setOwner(args.set_owner)

if args.set_owner_short:
closeNow = True
print(f"Setting device owner short to {args.set_owner_short}")
interface.getNode(args.dest).setOwner(long_name=None, short_name=args.set_owner_short)

if args.pos_fields:
# If --pos-fields invoked with args, set position fields
closeNow = True
Expand Down Expand Up @@ -332,6 +337,14 @@ def onConnected(interface):
print(f"Setting device owner to {configuration['owner']}")
interface.getNode(args.dest).setOwner(configuration['owner'])

if 'owner_short' in configuration:
print(f"Setting device owner short to {configuration['owner_short']}")
interface.getNode(args.dest).setOwner(long_name=None, short_owner=configuration['owner_short'])

if 'ownerShort' in configuration:
print(f"Setting device owner short to {configuration['ownerShort']}")
interface.getNode(args.dest).setOwner(long_name=None, short_owner=configuration['ownerShort'])

if 'channel_url' in configuration:
print("Setting channel url to", configuration['channel_url'])
interface.getNode(args.dest).setURL(configuration['channel_url'])
Expand Down Expand Up @@ -569,6 +582,7 @@ def subscribe():
def export_config(interface):
"""used in--export-config"""
owner = interface.getLongName()
owner_short = interface.getShortName()
channel_url = interface.localNode.getURL()
myinfo = interface.getMyNodeInfo()
pos = myinfo.get('position')
Expand All @@ -583,6 +597,8 @@ def export_config(interface):
config = "# start of Meshtastic configure yaml\n"
if owner:
config += f"owner: {owner}\n\n"
if owner_short:
config += f"owner_short: {owner_short}\n\n"
if channel_url:
if Globals.getInstance().get_camel_case():
config += f"channelUrl: {channel_url}\n\n"
Expand Down Expand Up @@ -785,10 +801,12 @@ def initParser():
parser.add_argument(
"--ch-shortfast", help="Change to the short-range and fast channel", action='store_true')


parser.add_argument(
"--set-owner", help="Set device owner name", action="store")

parser.add_argument(
"--set-owner-short", help="Set device owner short name", action="store")

parser.add_argument(
"--set-team", help="Set team affiliation (an invalid team will list valid values)", action="store")

Expand Down
21 changes: 21 additions & 0 deletions meshtastic/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,23 @@ def test_main_set_owner_to_bob(capsys):
mo.assert_called()


@pytest.mark.unit
@pytest.mark.usefixtures("reset_globals")
def test_main_set_owner_short_to_bob(capsys):
"""Test --set-owner-short bob"""
sys.argv = ['', '--set-owner-short', 'bob']
Globals.getInstance().set_args(sys.argv)

iface = MagicMock(autospec=SerialInterface)
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
main()
out, err = capsys.readouterr()
assert re.search(r'Connected to radio', out, re.MULTILINE)
assert re.search(r'Setting device owner short to bob', out, re.MULTILINE)
assert err == ''
mo.assert_called()


@pytest.mark.unit
@pytest.mark.usefixtures("reset_globals")
def test_main_set_ham_to_KI123(capsys):
Expand Down Expand Up @@ -913,6 +930,7 @@ def test_main_configure_with_snake_case(capsys):
out, err = capsys.readouterr()
assert re.search(r'Connected to radio', out, re.MULTILINE)
assert re.search(r'Setting device owner', out, re.MULTILINE)
assert re.search(r'Setting device owner short', out, re.MULTILINE)
assert re.search(r'Setting channel url', out, re.MULTILINE)
assert re.search(r'Fixing altitude', out, re.MULTILINE)
assert re.search(r'Fixing latitude', out, re.MULTILINE)
Expand Down Expand Up @@ -940,6 +958,7 @@ def test_main_configure_with_camel_case_keys(capsys):
out, err = capsys.readouterr()
assert re.search(r'Connected to radio', out, re.MULTILINE)
assert re.search(r'Setting device owner', out, re.MULTILINE)
assert re.search(r'Setting device owner short', out, re.MULTILINE)
assert re.search(r'Setting channel url', out, re.MULTILINE)
assert re.search(r'Fixing altitude', out, re.MULTILINE)
assert re.search(r'Fixing latitude', out, re.MULTILINE)
Expand Down Expand Up @@ -1604,6 +1623,7 @@ def test_main_export_config(capsys):
iface = MagicMock(autospec=SerialInterface)
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
mo.getLongName.return_value = 'foo'
mo.getShortName.return_value = 'oof'
mo.localNode.getURL.return_value = 'bar'
mo.getMyNodeInfo().get.return_value = { 'latitudeI': 1100000000, 'longitudeI': 1200000000,
'altitude': 100, 'batteryLevel': 34, 'latitude': 110.0,
Expand All @@ -1620,6 +1640,7 @@ def test_main_export_config(capsys):
assert not re.search(r'Connected to radio', out, re.MULTILINE)

assert re.search(r'owner: foo', out, re.MULTILINE)
assert re.search(r'owner_short: oof', out, re.MULTILINE)
assert re.search(r'channel_url: bar', out, re.MULTILINE)
assert re.search(r'location:', out, re.MULTILINE)
assert re.search(r'lat: 110.0', out, re.MULTILINE)
Expand Down
9 changes: 9 additions & 0 deletions meshtastic/tests/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ def test_setOwner_and_team(caplog):
assert re.search(r'p.set_owner.team:1', caplog.text, re.MULTILINE)


@pytest.mark.unit
def test_setOwnerShort(caplog):
"""Test setOwner"""
anode = Node('foo', 'bar', noProto=True)
with caplog.at_level(logging.DEBUG):
anode.setOwner(long_name=None, short_name='123')
assert re.search(r'p.set_owner.short_name:123:', caplog.text, re.MULTILINE)


@pytest.mark.unit
def test_setOwner_no_short_name(caplog):
"""Test setOwner"""
Expand Down