14
14
from chacha20poly1305_reuseable import ChaCha20Poly1305Reusable as ChaCha20Poly1305
15
15
16
16
from pyhap import tlv
17
+
17
18
from pyhap .const import (
18
19
CATEGORY_BRIDGE ,
19
20
HAP_PERMISSIONS ,
@@ -416,7 +417,11 @@ def _pairing_five(self, client_username, client_ltpk, encryption_key):
416
417
cipher = ChaCha20Poly1305 (encryption_key )
417
418
aead_message = bytes (cipher .encrypt (self .PAIRING_5_NONCE , bytes (message ), b"" ))
418
419
419
- client_uuid = uuid .UUID (str (client_username , "utf-8" ))
420
+ client_username_str = str (client_username , "utf-8" )
421
+ client_uuid = uuid .UUID (client_username_str )
422
+ logger .debug (
423
+ "Finishing pairing with admin %s uuid=%s" , client_username_str , client_uuid
424
+ )
420
425
should_confirm = self .accessory_handler .pair (
421
426
client_uuid , client_ltpk , HAP_PERMISSIONS .ADMIN
422
427
)
@@ -668,11 +673,18 @@ def handle_pairings(self):
668
673
669
674
def _handle_add_pairing (self , tlv_objects ):
670
675
"""Update client information."""
671
- logger .debug ("%s: Adding client pairing." , self .client_address )
672
676
client_username = tlv_objects [HAP_TLV_TAGS .USERNAME ]
677
+ client_username_str = str (client_username , "utf-8" )
673
678
client_public = tlv_objects [HAP_TLV_TAGS .PUBLIC_KEY ]
674
679
permissions = tlv_objects [HAP_TLV_TAGS .PERMISSIONS ]
675
- client_uuid = uuid .UUID (str (client_username , "utf-8" ))
680
+ client_uuid = uuid .UUID (client_username_str )
681
+ logger .debug (
682
+ "%s: Adding client pairing for %s uuid=%s with permissions %s." ,
683
+ self .client_address ,
684
+ client_username_str ,
685
+ client_uuid ,
686
+ permissions ,
687
+ )
676
688
should_confirm = self .accessory_handler .pair (
677
689
client_uuid , client_public , permissions
678
690
)
@@ -685,10 +697,17 @@ def _handle_add_pairing(self, tlv_objects):
685
697
686
698
def _handle_remove_pairing (self , tlv_objects ):
687
699
"""Remove pairing with the client."""
688
- logger .debug ("%s: Removing client pairing." , self .client_address )
689
700
client_username = tlv_objects [HAP_TLV_TAGS .USERNAME ]
690
- client_uuid = uuid .UUID (str (client_username , "utf-8" ))
701
+ client_username_str = str (client_username , "utf-8" )
702
+ client_uuid = uuid .UUID (client_username_str )
691
703
was_paired = self .state .paired
704
+ logger .debug (
705
+ "%s: Removing client pairing (%s) uuid=%s (was previously paired=%s)." ,
706
+ self .client_address ,
707
+ client_username_str ,
708
+ client_uuid ,
709
+ was_paired ,
710
+ )
692
711
# If the client does not exist, we must
693
712
# respond with success per the spec
694
713
if client_uuid in self .state .paired_clients :
@@ -713,7 +732,10 @@ def _handle_list_pairings(self):
713
732
response .extend (
714
733
[
715
734
HAP_TLV_TAGS .USERNAME ,
716
- str (client_uuid ).encode ("utf-8" ),
735
+ # iOS 16+ requires the username to be uppercase
736
+ # or it will unpair the accessory because it thinks
737
+ # the username is invalid
738
+ str (client_uuid ).encode ("utf-8" ).upper (),
717
739
HAP_TLV_TAGS .PUBLIC_KEY ,
718
740
client_public ,
719
741
HAP_TLV_TAGS .PERMISSIONS ,
0 commit comments