1616 pskToString ,
1717 stripnl ,
1818 message_to_json ,
19+ to_node_num ,
1920)
2021
2122logger = logging .getLogger (__name__ )
@@ -52,20 +53,6 @@ def __repr__(self):
5253 r += ")"
5354 return r
5455
55- def _to_node_num (self , nodeId : Union [int , str ]) -> int :
56- """Normalize node id from int | '!hex' | '0xhex' | 'decimal' to int."""
57- if isinstance (nodeId , int ):
58- return nodeId
59- s = str (nodeId ).strip ()
60- if s .startswith ("!" ):
61- s = s [1 :]
62- if s .lower ().startswith ("0x" ):
63- return int (s , 16 )
64- try :
65- return int (s , 10 )
66- except ValueError :
67- return int (s , 16 )
68-
6956 def module_available (self , excluded_bit : int ) -> bool :
7057 """Check DeviceMetadata.excluded_modules to see if a module is available."""
7158 meta = getattr (self .iface , "metadata" , None )
@@ -728,7 +715,7 @@ def factoryReset(self, full: bool = False):
728715 def removeNode (self , nodeId : Union [int , str ]):
729716 """Tell the node to remove a specific node by ID"""
730717 self .ensureSessionKey ()
731- nodeId = self . _to_node_num (nodeId )
718+ nodeId = to_node_num (nodeId )
732719
733720 p = admin_pb2 .AdminMessage ()
734721 p .remove_by_nodenum = nodeId
@@ -742,7 +729,7 @@ def removeNode(self, nodeId: Union[int, str]):
742729 def setFavorite (self , nodeId : Union [int , str ]):
743730 """Tell the node to set the specified node ID to be favorited on the NodeDB on the device"""
744731 self .ensureSessionKey ()
745- nodeId = self . _to_node_num (nodeId )
732+ nodeId = to_node_num (nodeId )
746733
747734 p = admin_pb2 .AdminMessage ()
748735 p .set_favorite_node = nodeId
@@ -756,7 +743,7 @@ def setFavorite(self, nodeId: Union[int, str]):
756743 def removeFavorite (self , nodeId : Union [int , str ]):
757744 """Tell the node to set the specified node ID to be un-favorited on the NodeDB on the device"""
758745 self .ensureSessionKey ()
759- nodeId = self . _to_node_num (nodeId )
746+ nodeId = to_node_num (nodeId )
760747
761748 p = admin_pb2 .AdminMessage ()
762749 p .remove_favorite_node = nodeId
@@ -770,7 +757,7 @@ def removeFavorite(self, nodeId: Union[int, str]):
770757 def setIgnored (self , nodeId : Union [int , str ]):
771758 """Tell the node to set the specified node ID to be ignored on the NodeDB on the device"""
772759 self .ensureSessionKey ()
773- nodeId = self . _to_node_num (nodeId )
760+ nodeId = to_node_num (nodeId )
774761
775762 p = admin_pb2 .AdminMessage ()
776763 p .set_ignored_node = nodeId
@@ -784,7 +771,7 @@ def setIgnored(self, nodeId: Union[int, str]):
784771 def removeIgnored (self , nodeId : Union [int , str ]):
785772 """Tell the node to set the specified node ID to be un-ignored on the NodeDB on the device"""
786773 self .ensureSessionKey ()
787- nodeId = self . _to_node_num (nodeId )
774+ nodeId = to_node_num (nodeId )
788775
789776 p = admin_pb2 .AdminMessage ()
790777 p .remove_ignored_node = nodeId
@@ -1007,7 +994,7 @@ def _sendAdmin(
1007994 ): # unless a special channel index was used, we want to use the admin index
1008995 adminIndex = self .iface .localNode ._getAdminChannelIndex ()
1009996 logger .debug (f"adminIndex:{ adminIndex } " )
1010- nodeid = self . _to_node_num (self .nodeNum )
997+ nodeid = to_node_num (self .nodeNum )
1011998 if "adminSessionPassKey" in self .iface ._getOrCreateByNum (nodeid ):
1012999 p .session_passkey = self .iface ._getOrCreateByNum (nodeid ).get ("adminSessionPassKey" )
10131000 return self .iface .sendData (
@@ -1028,6 +1015,6 @@ def ensureSessionKey(self):
10281015 f"Not ensuring session key, because protocol use is disabled by noProto"
10291016 )
10301017 else :
1031- nodeid = self . _to_node_num (self .nodeNum )
1018+ nodeid = to_node_num (self .nodeNum )
10321019 if self .iface ._getOrCreateByNum (nodeid ).get ("adminSessionPassKey" ) is None :
10331020 self .requestConfig (admin_pb2 .AdminMessage .SESSIONKEY_CONFIG )
0 commit comments