1616 pskToString ,
1717 stripnl ,
1818 message_to_json ,
19+ to_node_num ,
1920)
2021
2122logger = logging .getLogger (__name__ )
@@ -714,11 +715,7 @@ def factoryReset(self, full: bool = False):
714715 def removeNode (self , nodeId : Union [int , str ]):
715716 """Tell the node to remove a specific node by ID"""
716717 self .ensureSessionKey ()
717- if isinstance (nodeId , str ):
718- if nodeId .startswith ("!" ):
719- nodeId = int (nodeId [1 :], 16 )
720- else :
721- nodeId = int (nodeId )
718+ nodeId = to_node_num (nodeId )
722719
723720 p = admin_pb2 .AdminMessage ()
724721 p .remove_by_nodenum = nodeId
@@ -732,11 +729,7 @@ def removeNode(self, nodeId: Union[int, str]):
732729 def setFavorite (self , nodeId : Union [int , str ]):
733730 """Tell the node to set the specified node ID to be favorited on the NodeDB on the device"""
734731 self .ensureSessionKey ()
735- if isinstance (nodeId , str ):
736- if nodeId .startswith ("!" ):
737- nodeId = int (nodeId [1 :], 16 )
738- else :
739- nodeId = int (nodeId )
732+ nodeId = to_node_num (nodeId )
740733
741734 p = admin_pb2 .AdminMessage ()
742735 p .set_favorite_node = nodeId
@@ -750,11 +743,7 @@ def setFavorite(self, nodeId: Union[int, str]):
750743 def removeFavorite (self , nodeId : Union [int , str ]):
751744 """Tell the node to set the specified node ID to be un-favorited on the NodeDB on the device"""
752745 self .ensureSessionKey ()
753- if isinstance (nodeId , str ):
754- if nodeId .startswith ("!" ):
755- nodeId = int (nodeId [1 :], 16 )
756- else :
757- nodeId = int (nodeId )
746+ nodeId = to_node_num (nodeId )
758747
759748 p = admin_pb2 .AdminMessage ()
760749 p .remove_favorite_node = nodeId
@@ -768,11 +757,7 @@ def removeFavorite(self, nodeId: Union[int, str]):
768757 def setIgnored (self , nodeId : Union [int , str ]):
769758 """Tell the node to set the specified node ID to be ignored on the NodeDB on the device"""
770759 self .ensureSessionKey ()
771- if isinstance (nodeId , str ):
772- if nodeId .startswith ("!" ):
773- nodeId = int (nodeId [1 :], 16 )
774- else :
775- nodeId = int (nodeId )
760+ nodeId = to_node_num (nodeId )
776761
777762 p = admin_pb2 .AdminMessage ()
778763 p .set_ignored_node = nodeId
@@ -786,11 +771,7 @@ def setIgnored(self, nodeId: Union[int, str]):
786771 def removeIgnored (self , nodeId : Union [int , str ]):
787772 """Tell the node to set the specified node ID to be un-ignored on the NodeDB on the device"""
788773 self .ensureSessionKey ()
789- if isinstance (nodeId , str ):
790- if nodeId .startswith ("!" ):
791- nodeId = int (nodeId [1 :], 16 )
792- else :
793- nodeId = int (nodeId )
774+ nodeId = to_node_num (nodeId )
794775
795776 p = admin_pb2 .AdminMessage ()
796777 p .remove_ignored_node = nodeId
@@ -1013,10 +994,7 @@ def _sendAdmin(
1013994 ): # unless a special channel index was used, we want to use the admin index
1014995 adminIndex = self .iface .localNode ._getAdminChannelIndex ()
1015996 logger .debug (f"adminIndex:{ adminIndex } " )
1016- if isinstance (self .nodeNum , int ):
1017- nodeid = self .nodeNum
1018- else : # assume string starting with !
1019- nodeid = int (self .nodeNum [1 :],16 )
997+ nodeid = to_node_num (self .nodeNum )
1020998 if "adminSessionPassKey" in self .iface ._getOrCreateByNum (nodeid ):
1021999 p .session_passkey = self .iface ._getOrCreateByNum (nodeid ).get ("adminSessionPassKey" )
10221000 return self .iface .sendData (
@@ -1037,9 +1015,6 @@ def ensureSessionKey(self):
10371015 f"Not ensuring session key, because protocol use is disabled by noProto"
10381016 )
10391017 else :
1040- if isinstance (self .nodeNum , int ):
1041- nodeid = self .nodeNum
1042- else : # assume string starting with !
1043- nodeid = int (self .nodeNum [1 :],16 )
1018+ nodeid = to_node_num (self .nodeNum )
10441019 if self .iface ._getOrCreateByNum (nodeid ).get ("adminSessionPassKey" ) is None :
10451020 self .requestConfig (admin_pb2 .AdminMessage .SESSIONKEY_CONFIG )
0 commit comments