1717 stripnl ,
1818 message_to_json ,
1919 generate_channel_hash ,
20+ to_node_num ,
2021)
2122
2223logger = logging .getLogger (__name__ )
@@ -715,11 +716,7 @@ def factoryReset(self, full: bool = False):
715716 def removeNode (self , nodeId : Union [int , str ]):
716717 """Tell the node to remove a specific node by ID"""
717718 self .ensureSessionKey ()
718- if isinstance (nodeId , str ):
719- if nodeId .startswith ("!" ):
720- nodeId = int (nodeId [1 :], 16 )
721- else :
722- nodeId = int (nodeId )
719+ nodeId = to_node_num (nodeId )
723720
724721 p = admin_pb2 .AdminMessage ()
725722 p .remove_by_nodenum = nodeId
@@ -733,11 +730,7 @@ def removeNode(self, nodeId: Union[int, str]):
733730 def setFavorite (self , nodeId : Union [int , str ]):
734731 """Tell the node to set the specified node ID to be favorited on the NodeDB on the device"""
735732 self .ensureSessionKey ()
736- if isinstance (nodeId , str ):
737- if nodeId .startswith ("!" ):
738- nodeId = int (nodeId [1 :], 16 )
739- else :
740- nodeId = int (nodeId )
733+ nodeId = to_node_num (nodeId )
741734
742735 p = admin_pb2 .AdminMessage ()
743736 p .set_favorite_node = nodeId
@@ -751,11 +744,7 @@ def setFavorite(self, nodeId: Union[int, str]):
751744 def removeFavorite (self , nodeId : Union [int , str ]):
752745 """Tell the node to set the specified node ID to be un-favorited on the NodeDB on the device"""
753746 self .ensureSessionKey ()
754- if isinstance (nodeId , str ):
755- if nodeId .startswith ("!" ):
756- nodeId = int (nodeId [1 :], 16 )
757- else :
758- nodeId = int (nodeId )
747+ nodeId = to_node_num (nodeId )
759748
760749 p = admin_pb2 .AdminMessage ()
761750 p .remove_favorite_node = nodeId
@@ -769,11 +758,7 @@ def removeFavorite(self, nodeId: Union[int, str]):
769758 def setIgnored (self , nodeId : Union [int , str ]):
770759 """Tell the node to set the specified node ID to be ignored on the NodeDB on the device"""
771760 self .ensureSessionKey ()
772- if isinstance (nodeId , str ):
773- if nodeId .startswith ("!" ):
774- nodeId = int (nodeId [1 :], 16 )
775- else :
776- nodeId = int (nodeId )
761+ nodeId = to_node_num (nodeId )
777762
778763 p = admin_pb2 .AdminMessage ()
779764 p .set_ignored_node = nodeId
@@ -787,11 +772,7 @@ def setIgnored(self, nodeId: Union[int, str]):
787772 def removeIgnored (self , nodeId : Union [int , str ]):
788773 """Tell the node to set the specified node ID to be un-ignored on the NodeDB on the device"""
789774 self .ensureSessionKey ()
790- if isinstance (nodeId , str ):
791- if nodeId .startswith ("!" ):
792- nodeId = int (nodeId [1 :], 16 )
793- else :
794- nodeId = int (nodeId )
775+ nodeId = to_node_num (nodeId )
795776
796777 p = admin_pb2 .AdminMessage ()
797778 p .remove_ignored_node = nodeId
@@ -1014,10 +995,7 @@ def _sendAdmin(
1014995 ): # unless a special channel index was used, we want to use the admin index
1015996 adminIndex = self .iface .localNode ._getAdminChannelIndex ()
1016997 logger .debug (f"adminIndex:{ adminIndex } " )
1017- if isinstance (self .nodeNum , int ):
1018- nodeid = self .nodeNum
1019- else : # assume string starting with !
1020- nodeid = int (self .nodeNum [1 :],16 )
998+ nodeid = to_node_num (self .nodeNum )
1021999 if "adminSessionPassKey" in self .iface ._getOrCreateByNum (nodeid ):
10221000 p .session_passkey = self .iface ._getOrCreateByNum (nodeid ).get ("adminSessionPassKey" )
10231001 return self .iface .sendData (
@@ -1038,10 +1016,7 @@ def ensureSessionKey(self):
10381016 f"Not ensuring session key, because protocol use is disabled by noProto"
10391017 )
10401018 else :
1041- if isinstance (self .nodeNum , int ):
1042- nodeid = self .nodeNum
1043- else : # assume string starting with !
1044- nodeid = int (self .nodeNum [1 :],16 )
1019+ nodeid = to_node_num (self .nodeNum )
10451020 if self .iface ._getOrCreateByNum (nodeid ).get ("adminSessionPassKey" ) is None :
10461021 self .requestConfig (admin_pb2 .AdminMessage .SESSIONKEY_CONFIG )
10471022
0 commit comments