Merge pull request #340 from meshtastic/patch-1

remove "Request Settings" during init, team settings and deprecated settings.
This commit is contained in:
Thomas Göttgens
2022-06-17 10:59:54 +02:00
committed by GitHub
7 changed files with 5 additions and 225 deletions

View File

@@ -254,19 +254,6 @@ def onConnected(interface):
fieldNames.append(config_pb2.PositionFlags.Name(bit))
print(' '.join(fieldNames))
if args.set_team:
closeNow = True
try:
v_team = meshtastic.mesh_pb2.Team.Value(args.set_team.upper())
except ValueError:
v_team = 0
print(f"ERROR: Team \'{args.set_team}\' not found.")
print("Try a team name from the sorted list below, or use 'CLEAR' for unaffiliated:")
print(sorted(meshtastic.mesh_pb2.Team.keys()))
else:
print(f"Setting team to {meshtastic.mesh_pb2.Team.Name(v_team)}")
interface.getNode(args.dest).setOwner(team=v_team)
if args.set_ham:
closeNow = True
print(f"Setting Ham ID to {args.set_ham} and turning off encryption")
@@ -849,9 +836,6 @@ def initParser():
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")
parser.add_argument(
"--set-ham", help="Set licensed Ham ID and turn off encryption", action="store")
@@ -913,13 +897,6 @@ def initParser():
parser.add_argument("--noproto", help="Don't start the API, just function as a dumb serial terminal.",
action="store_true")
parser.add_argument('--setchan', dest='deprecated', nargs=2, action='append',
help='Deprecated, use "--ch-set param value" instead')
parser.add_argument('--set-router', dest='deprecated',
action='store_true', help='Deprecated, use "--set is_router true" instead')
parser.add_argument('--unset-router', dest='deprecated',
action='store_false', help='Deprecated, use "--set is_router false" instead')
have_tunnel = platform.system() == 'Linux'
if have_tunnel:
parser.add_argument('--tunnel', action='store_true',

View File

@@ -362,11 +362,9 @@ class MeshInterface:
def waitForConfig(self):
"""Block until radio config is received. Returns True if config has been received."""
# TODO
return True
#success = self._timeout.waitForSet(self, attrs=('myInfo', 'nodes')) and self.localNode.waitForConfig()
#if not success:
#raise Exception("Timed out waiting for interface config")
success = self._timeout.waitForSet(self, attrs=('myInfo', 'nodes')) and self.localNode.waitForConfig()
if not success:
raise Exception("Timed out waiting for interface config")
def getMyNodeInfo(self):
"""Get info about my node."""

View File

@@ -64,7 +64,6 @@ class Node:
"""Send regular MeshPackets to ask for settings and channels."""
logging.debug(f"requestConfig for nodeNum:{self.nodeNum}")
self.radioConfig = None
self.partialConfig = []
self.channels = None
self.partialChannels = [] # We keep our channels in a temp array until finished
@@ -76,7 +75,7 @@ class Node:
self.cannedPluginMessagePart3 = None
self.cannedPluginMessagePart4 = None
self._requestSettings()
self._requestChannel(0)
def turnOffEncryptionOnPrimaryChannel(self):
"""Turn off encryption on primary channel."""
@@ -165,7 +164,7 @@ class Node:
else:
return 0
def setOwner(self, long_name=None, short_name=None, is_licensed=False, team=None):
def setOwner(self, long_name=None, short_name=None, is_licensed=False):
"""Set device owner name"""
logging.debug(f"in setOwner nodeNum:{self.nodeNum}")
nChars = 3
@@ -194,14 +193,11 @@ class Node:
short_name = short_name[:nChars]
p.set_owner.short_name = short_name
p.set_owner.is_licensed = is_licensed
if team is not None:
p.set_owner.team = team
# Note: These debug lines are used in unit tests
logging.debug(f'p.set_owner.long_name:{p.set_owner.long_name}:')
logging.debug(f'p.set_owner.short_name:{p.set_owner.short_name}:')
logging.debug(f'p.set_owner.is_licensed:{p.set_owner.is_licensed}')
logging.debug(f'p.set_owner.team:{p.set_owner.team}')
return self._sendAdmin(p)
def getURL(self, includeAll: bool = True):
@@ -252,66 +248,6 @@ class Node:
self.writeChannel(ch.index)
i = i + 1
def onResponseRequestSettings(self, p):
"""Handle the response packets for requesting settings _requestSettings()"""
logging.debug(f'onResponseRequestSetting() p:{p}')
errorFound = False
if "routing" in p["decoded"]:
if p["decoded"]["routing"]["errorReason"] != "NONE":
errorFound = True
print(f'Error on response: {p["decoded"]["routing"]["errorReason"]}')
# TODO
#if errorFound is False:
#self.partialConfig[p["decoded"]["admin"]["payloadVariant"]] = p["decoded"]["admin"]["raw"].get_config_response
#logging.debug(f'self.partialConfig:{self.partialConfig}')
#self._timeout.reset() # We made foreward progress
#self.gotResponse = True
def _requestSettings(self):
"""Done with initial config messages, now send regular
MeshPackets to ask for settings."""
# TODO: should we check that localNode has an 'admin' channel?
# Show progress message for super slow operations
if self != self.iface.localNode:
print("Requesting preferences from remote node.")
print("Be sure:")
print(" 1. There is a SECONDARY channel named 'admin'.")
print(" 2. The '--seturl' was used to configure.")
print(" 3. All devices have the same modem config. (i.e., '--ch-longfast')")
print(" 4. All devices have been rebooted after all of the above. (optional, but recommended)")
print("Note: This could take a while (it requests remote channel configs, then writes config)")
p1 = admin_pb2.AdminMessage()
p1.get_config_request = admin_pb2.AdminMessage.ConfigType.DEVICE_CONFIG
self._sendAdmin(p1, wantResponse=True, onResponse=self.onResponseRequestSettings)
p2 = admin_pb2.AdminMessage()
p2.get_config_request = admin_pb2.AdminMessage.ConfigType.POSITION_CONFIG
self._sendAdmin(p2, wantResponse=True, onResponse=self.onResponseRequestSettings)
p3 = admin_pb2.AdminMessage()
p3.get_config_request = admin_pb2.AdminMessage.ConfigType.POWER_CONFIG
self._sendAdmin(p3, wantResponse=True, onResponse=self.onResponseRequestSettings)
p4 = admin_pb2.AdminMessage()
p4.get_config_request = admin_pb2.AdminMessage.ConfigType.WIFI_CONFIG
self._sendAdmin(p4, wantResponse=True, onResponse=self.onResponseRequestSettings)
p5 = admin_pb2.AdminMessage()
p5.get_config_request = admin_pb2.AdminMessage.ConfigType.DISPLAY_CONFIG
self._sendAdmin(p5, wantResponse=True, onResponse=self.onResponseRequestSettings)
p6 = admin_pb2.AdminMessage()
p6.get_config_request = admin_pb2.AdminMessage.ConfigType.LORA_CONFIG
self._sendAdmin(p6, wantResponse=True, onResponse=self.onResponseRequestSettings)
# TODO Assemble radioConfig
logging.debug("Received config, now fetching channels...")
self._requestChannel(0) # now start fetching channels
def onResponseRequestCannedMessagePluginMessagePart1(self, p):
"""Handle the response packet for requesting canned message plugin message part 1"""
logging.debug(f'onResponseRequestCannedMessagePluginMessagePart1() p:{p}')

View File

@@ -789,63 +789,6 @@ def test_main_setalt(capsys):
assert err == ''
mo.assert_called()
# TODO
#@pytest.mark.unit
#@pytest.mark.usefixtures("reset_globals")
#def test_main_set_team_valid(capsys):
# """Test --set-team"""
# sys.argv = ['', '--set-team', 'CYAN']
# Globals.getInstance().set_args(sys.argv)
#
# mocked_node = MagicMock(autospec=Node)
# def mock_setOwner(team):
# print('inside mocked setOwner')
# print(f'{team}')
# mocked_node.setOwner.side_effect = mock_setOwner
#
# iface = MagicMock(autospec=SerialInterface)
# iface.localNode.return_value = mocked_node
#
# with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
# with patch('meshtastic.mesh_pb2.Team') as mm:
# mm.Name.return_value = 'FAKENAME'
# mm.Value.return_value = 'FAKEVAL'
# main()
# out, err = capsys.readouterr()
# assert re.search(r'Connected to radio', out, re.MULTILINE)
# assert re.search(r'Setting team to', out, re.MULTILINE)
# assert err == ''
# mo.assert_called()
# mm.Name.assert_called()
# mm.Value.assert_called()
#
# TODO
#@pytest.mark.unit
#@pytest.mark.usefixtures("reset_globals")
#def test_main_set_team_invalid(capsys):
# """Test --set-team using an invalid team name"""
# sys.argv = ['', '--set-team', 'NOTCYAN']
# Globals.getInstance().set_args(sys.argv)
#
# iface = MagicMock(autospec=SerialInterface)
#
# def throw_an_exception(exc):
# raise ValueError("Fake exception.")
#
# with patch('meshtastic.serial_interface.SerialInterface', return_value=iface) as mo:
# with patch('meshtastic.mesh_pb2.Team') as mm:
# mm.Value.side_effect = throw_an_exception
# main()
# out, err = capsys.readouterr()
# assert re.search(r'Connected to radio', out, re.MULTILINE)
# assert re.search(r'ERROR: Team', out, re.MULTILINE)
# assert err == ''
# mo.assert_called()
# mm.Value.assert_called()
@pytest.mark.unit
@pytest.mark.usefixtures("reset_globals")
def test_main_seturl(capsys):
@@ -1541,24 +1484,6 @@ def test_main_get_with_invalid(capsys):
mo.assert_called()
@pytest.mark.unit
@pytest.mark.usefixtures("reset_globals")
def test_main_setchan(capsys):
"""Test --setchan (deprecated)"""
sys.argv = ['', '--setchan', 'a', 'b']
Globals.getInstance().set_args(sys.argv)
iface = MagicMock(autospec=SerialInterface)
with patch('meshtastic.serial_interface.SerialInterface', return_value=iface):
with pytest.raises(SystemExit) as pytest_wrapped_e:
main()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 1
_, err = capsys.readouterr()
assert re.search(r'usage:', err, re.MULTILINE)
@pytest.mark.unit
@pytest.mark.usefixtures("reset_globals")
def test_main_onReceive_empty(caplog, capsys):

View File

@@ -164,19 +164,6 @@ from ..channel_pb2 import Channel
# assert err == ''
# TODO
#@pytest.mark.unit
#def test_setOwner_and_team(caplog):
# """Test setOwner"""
# anode = Node('foo', 'bar', noProto=True)
# with caplog.at_level(logging.DEBUG):
# anode.setOwner(long_name ='Test123', short_name='123', team=1)
# assert re.search(r'p.set_owner.long_name:Test123:', caplog.text, re.MULTILINE)
# assert re.search(r'p.set_owner.short_name:123:', caplog.text, re.MULTILINE)
# assert re.search(r'p.set_owner.is_licensed:False', caplog.text, re.MULTILINE)
# assert re.search(r'p.set_owner.team:1', caplog.text, re.MULTILINE)
# TODO
#@pytest.mark.unit
#def test_setOwnerShort(caplog):
@@ -197,7 +184,6 @@ from ..channel_pb2 import Channel
# assert re.search(r'p.set_owner.long_name:Test123:', caplog.text, re.MULTILINE)
# assert re.search(r'p.set_owner.short_name:Tst:', caplog.text, re.MULTILINE)
# assert re.search(r'p.set_owner.is_licensed:False', caplog.text, re.MULTILINE)
# assert re.search(r'p.set_owner.team:0', caplog.text, re.MULTILINE)
# TODO
@@ -210,7 +196,6 @@ from ..channel_pb2 import Channel
# assert re.search(r'p.set_owner.long_name:Tnt:', caplog.text, re.MULTILINE)
# assert re.search(r'p.set_owner.short_name:Tnt:', caplog.text, re.MULTILINE)
# assert re.search(r'p.set_owner.is_licensed:False', caplog.text, re.MULTILINE)
# assert re.search(r'p.set_owner.team:0', caplog.text, re.MULTILINE)
# TODO
@@ -223,7 +208,6 @@ from ..channel_pb2 import Channel
# assert re.search(r'p.set_owner.long_name:A B C:', caplog.text, re.MULTILINE)
# assert re.search(r'p.set_owner.short_name:ABC:', caplog.text, re.MULTILINE)
# assert re.search(r'p.set_owner.is_licensed:True', caplog.text, re.MULTILINE)
# assert re.search(r'p.set_owner.team:0', caplog.text, re.MULTILINE)
# TODO

View File

@@ -214,26 +214,6 @@ def test_smoke1_set_owner():
assert return_value == 0
@pytest.mark.smoke1
def test_smoke1_set_team():
"""Test --set-team """
# unset the team
return_value, out = subprocess.getstatusoutput('meshtastic --set-team CLEAR')
assert re.match(r'Connected to radio', out)
assert re.search(r'^Setting team to CLEAR', out, re.MULTILINE)
assert return_value == 0
# pause for the radio
time.sleep(PAUSE_AFTER_REBOOT)
return_value, out = subprocess.getstatusoutput('meshtastic --set-team CYAN')
assert re.search(r'Setting team to CYAN', out, re.MULTILINE)
assert return_value == 0
# pause for the radio
time.sleep(PAUSE_AFTER_REBOOT)
return_value, out = subprocess.getstatusoutput('meshtastic --info')
assert re.search(r'CYAN', out, re.MULTILINE)
assert return_value == 0
@pytest.mark.smoke1
def test_smoke1_ch_set_modem_config():
"""Test --ch-set modem_config"""

View File

@@ -219,26 +219,6 @@ def test_smokevirt_set_owner():
assert return_value == 0
@pytest.mark.smokevirt
def test_smokevirt_set_team():
"""Test --set-team """
# unset the team
return_value, out = subprocess.getstatusoutput('meshtastic --host localhost --set-team CLEAR')
assert re.match(r'Connected to radio', out)
assert re.search(r'^Setting team to CLEAR', out, re.MULTILINE)
assert return_value == 0
# pause for the radio
time.sleep(PAUSE_AFTER_REBOOT)
return_value, out = subprocess.getstatusoutput('meshtastic --host localhost --set-team CYAN')
assert re.search(r'Setting team to CYAN', out, re.MULTILINE)
assert return_value == 0
# pause for the radio
time.sleep(PAUSE_AFTER_REBOOT)
return_value, out = subprocess.getstatusoutput('meshtastic --host localhost --info')
assert re.search(r'CYAN', out, re.MULTILINE)
assert return_value == 0
@pytest.mark.smokevirt
def test_smokevirt_ch_values():
"""Test --ch-longslow, --ch-longfast, --ch-mediumslow, --ch-mediumsfast,