4
4
from typing import TYPE_CHECKING , Any , Callable , Dict , Iterable , List , Optional
5
5
from uuid import UUID
6
6
7
- from . import util
7
+ from . import SUPPORT_QR_CODE , util
8
8
from .const import (
9
9
CATEGORY_BRIDGE ,
10
10
CATEGORY_OTHER ,
18
18
from .iid_manager import IIDManager
19
19
from .service import Service
20
20
21
+ if SUPPORT_QR_CODE :
22
+ import base36
23
+ from pyqrcode import QRCode
24
+
21
25
22
26
if TYPE_CHECKING :
23
27
from .accessory_driver import AccessoryDriver
@@ -186,12 +190,6 @@ def xhm_uri(self) -> str:
186
190
187
191
:rtype: str
188
192
"""
189
- try :
190
- import base36
191
- except ImportError as ie :
192
- raise RuntimeError (
193
- "The base36 module is required to generate X-HM:// URIs"
194
- ) from ie
195
193
payload = 0
196
194
payload |= 0 & 0x7 # version
197
195
@@ -255,15 +253,7 @@ def setup_message(self):
255
253
Installation through `pip install HAP-python[QRCode]`
256
254
"""
257
255
pincode = self .driver .state .pincode .decode ()
258
- try :
259
- from qrcode import QRCode
260
- except ImportError :
261
- print (
262
- "To use the QR Code feature, use 'pip install HAP-python[QRCode]'\n "
263
- f"Enter this code in your HomeKit app on your iOS device: { pincode } " ,
264
- flush = True ,
265
- )
266
- else :
256
+ if SUPPORT_QR_CODE :
267
257
xhm_uri = self .xhm_uri ()
268
258
print (f"Setup payload: { xhm_uri } " , flush = True )
269
259
print (
@@ -274,6 +264,15 @@ def setup_message(self):
274
264
f"Or enter this code in your HomeKit app on your iOS device: { pincode } " ,
275
265
flush = True ,
276
266
)
267
+ else :
268
+ print (
269
+ "To use the QR Code feature, use 'pip install HAP-python[QRCode]'" ,
270
+ flush = True ,
271
+ )
272
+ print (
273
+ f"Enter this code in your HomeKit app on your iOS device: { pincode } " ,
274
+ flush = True ,
275
+ )
277
276
278
277
@staticmethod
279
278
def run_at_interval (seconds ):
0 commit comments