2222import logging
2323import os
2424import re
25- import socket
2625import sys
2726import tempfile
28- import time
2927import threading
28+ import time
29+ from typing import Optional
3030
3131from zeroconf import ServiceInfo
3232from zeroconf .asyncio import AsyncZeroconf
3333
3434from pyhap import util
35- from pyhap .accessory import get_topic
35+ from pyhap .accessory import Accessory , get_topic
3636from pyhap .characteristic import CharacteristicError
3737from pyhap .const import (
3838 HAP_PERMISSION_NOTIFY ,
4141 HAP_REPR_AID ,
4242 HAP_REPR_CHARS ,
4343 HAP_REPR_IID ,
44- HAP_REPR_TTL ,
4544 HAP_REPR_PID ,
4645 HAP_REPR_STATUS ,
46+ HAP_REPR_TTL ,
4747 HAP_REPR_VALUE ,
4848 STANDALONE_AID ,
4949)
@@ -122,7 +122,7 @@ class AccessoryMDNSServiceInfo(ServiceInfo):
122122
123123 def __init__ (self , accessory , state , zeroconf_server = None ):
124124 self .accessory = accessory
125- self .state = state
125+ self .state : State = state
126126
127127 adv_data = self ._get_advert_data ()
128128 valid_name = self ._valid_name ()
@@ -139,7 +139,7 @@ def __init__(self, accessory, state, zeroconf_server=None):
139139 weight = 0 ,
140140 priority = 0 ,
141141 properties = adv_data ,
142- addresses = [ socket . inet_aton ( self .state .address )] ,
142+ parsed_addresses = self .state .addresses ,
143143 )
144144
145145 def _valid_name (self ):
@@ -244,10 +244,10 @@ def __init__(
244244 If not given, the value of the address parameter will be used.
245245 :type listen_address: str
246246
247- :param advertised_address: The address of the HAPServer announced via mDNS.
247+ :param advertised_address: The addresses of the HAPServer announced via mDNS.
248248 This can be used to announce an external address from behind a NAT.
249249 If not given, the value of the address parameter will be used.
250- :type advertised_address: str
250+ :type advertised_address: str | list[str]
251251
252252 :param interface_choice: The zeroconf interfaces to listen on.
253253 :type InterfacesType: [InterfaceChoice.Default, InterfaceChoice.All]
@@ -279,7 +279,7 @@ def __init__(
279279
280280 self .loop = loop
281281
282- self .accessory = None
282+ self .accessory : Optional [ Accessory ] = None
283283 self .advertiser = async_zeroconf_instance
284284 self .zeroconf_server = zeroconf_server
285285 self .interface_choice = interface_choice
@@ -366,9 +366,9 @@ async def async_start(self):
366366 self .aio_stop_event = asyncio .Event ()
367367
368368 logger .info (
369- "Starting accessory %s on address %s, port %s." ,
369+ "Starting accessory %s on addresses %s, port %s." ,
370370 self .accessory .display_name ,
371- self .state .address ,
371+ self .state .addresses ,
372372 self .state .port ,
373373 )
374374
@@ -428,7 +428,7 @@ async def async_stop(self):
428428 logger .info (
429429 "Stopping accessory %s on address %s, port %s." ,
430430 self .accessory .display_name ,
431- self .state .address ,
431+ self .state .addresses ,
432432 self .state .port ,
433433 )
434434
@@ -643,7 +643,9 @@ def persist(self):
643643 ) as file_handle :
644644 tmp_filename = file_handle .name
645645 self .encoder .persist (file_handle , self .state )
646- if os .name == 'nt' : # Or `[WinError 5] Access Denied` will be raised on Windows
646+ if (
647+ os .name == "nt"
648+ ): # Or `[WinError 5] Access Denied` will be raised on Windows
647649 os .chmod (tmp_filename , 0o644 )
648650 os .chmod (self .persist_file , 0o644 )
649651 os .replace (tmp_filename , self .persist_file )
@@ -663,13 +665,18 @@ def load(self):
663665 self .encoder .load_into (file_handle , self .state )
664666
665667 @callback
666- def pair (self , client_uuid , client_public , client_permissions ):
668+ def pair (
669+ self ,
670+ client_username_bytes : bytes ,
671+ client_public : bytes ,
672+ client_permissions : bytes ,
673+ ) -> bool :
667674 """Called when a client has paired with the accessory.
668675
669676 Persist the new accessory state.
670677
671- :param client_uuid : The client uuid .
672- :type client_uuid: uuid.UUID
678+ :param client_username_bytes : The client username bytes .
679+ :type client_username_bytes: bytes
673680
674681 :param client_public: The client's public key.
675682 :type client_public: bytes
@@ -681,9 +688,13 @@ def pair(self, client_uuid, client_public, client_permissions):
681688 :rtype: bool
682689 """
683690 logger .info (
684- "Paired with %s with permissions %s." , client_uuid , client_permissions
691+ "Paired with %s with permissions %s." ,
692+ client_username_bytes ,
693+ client_permissions ,
694+ )
695+ self .state .add_paired_client (
696+ client_username_bytes , client_public , client_permissions
685697 )
686- self .state .add_paired_client (client_uuid , client_public , client_permissions )
687698 self .async_persist ()
688699 return True
689700
0 commit comments