88
99import serial
1010import zigpy .exceptions
11+ import zigpy .types
1112
1213import zigpy_zigate .config
1314import zigpy_zigate .uart
@@ -39,6 +40,7 @@ class CommandId(enum.IntEnum):
3940 MANAGEMENT_NETWORK_UPDATE_REQUEST = 0x004A
4041 SEND_RAW_APS_DATA_PACKET = 0x0530
4142 AHI_SET_TX_POWER = 0x0806
43+ GET_NETWORK_KEY = 0x0054
4244
4345
4446class ResponseId (enum .IntEnum ):
@@ -65,6 +67,7 @@ class ResponseId(enum.IntEnum):
6567 APS_DATA_CONFIRM_FAILED = 0x8702
6668 AHI_SET_TX_POWER_RSP = 0x8806
6769 EXTENDED_ERROR = 0x9999
70+ GET_NETWORK_KEY_LIST = 0x8054
6871
6972
7073class SendSecurity (t .uint8_t , enum .Enum ):
@@ -142,6 +145,7 @@ class FactoryNewRestartStatus(t.uint8_t, enum.Enum):
142145 ),
143146 ResponseId .AHI_SET_TX_POWER_RSP : (t .uint8_t ,),
144147 ResponseId .EXTENDED_ERROR : (t .Status ,),
148+ ResponseId .GET_NETWORK_KEY_LIST : (zigpy .types .KeyData ,),
145149}
146150
147151COMMANDS = {
@@ -212,6 +216,10 @@ class CommandError(zigpy.exceptions.APIException):
212216 pass
213217
214218
219+ class CommandNotSupportedError (CommandError ):
220+ pass
221+
222+
215223class ZiGate :
216224 def __init__ (self , device_config : Dict [str , Any ]):
217225 self ._app = None
@@ -568,6 +576,16 @@ def handle_callback(self, *args):
568576 except Exception as e :
569577 LOGGER .exception ("Exception running handler" , exc_info = e )
570578
579+ async def get_network_key (self ):
580+ rsp , _ = await self .command (
581+ CommandId .GET_NETWORK_KEY , wait_response = ResponseId .GET_NETWORK_KEY_LIST
582+ )
583+
584+ if rsp [0 ] == t .Status .UnhandledCommand :
585+ raise CommandNotSupportedError ()
586+
587+ return rsp [0 ]
588+
571589 @classmethod
572590 async def probe (cls , device_config : Dict [str , Any ]) -> bool :
573591 """Probe port for the device presence."""
0 commit comments