From 4f72987a29541d0b7da7a0ab56f4985ec5c4d36e Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Sun, 23 Jan 2022 11:22:05 -0800 Subject: [PATCH] add some config tests --- exampleConfig.yaml | 1 + example_config.yaml | 1 + meshtastic/__main__.py | 4 ++++ meshtastic/tests/test_main.py | 4 ++++ 4 files changed, 10 insertions(+) diff --git a/exampleConfig.yaml b/exampleConfig.yaml index c4539fa..35590f3 100644 --- a/exampleConfig.yaml +++ b/exampleConfig.yaml @@ -1,5 +1,6 @@ # example config using camelCase keys owner: Bob TBeam +ownerShort: BOB channelUrl: https://www.meshtastic.org/d/#CgUYAyIBAQ diff --git a/example_config.yaml b/example_config.yaml index eff8c3f..ac3d263 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -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 diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index d6bfa6b..e851139 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -341,6 +341,10 @@ def onConnected(interface): 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']) diff --git a/meshtastic/tests/test_main.py b/meshtastic/tests/test_main.py index 3bc722b..ce01da5 100644 --- a/meshtastic/tests/test_main.py +++ b/meshtastic/tests/test_main.py @@ -930,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) @@ -957,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) @@ -1621,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, @@ -1637,6 +1640,7 @@ position_flags: 35""" 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)