-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Late-import base36 and QR code libraries; remove SUPPORT_QR_CODE flag #470
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
from typing import TYPE_CHECKING, Any, Callable, Dict, Iterable, List, Optional | ||
from uuid import UUID | ||
|
||
from . import SUPPORT_QR_CODE, util | ||
from . import util | ||
from .const import ( | ||
CATEGORY_BRIDGE, | ||
CATEGORY_OTHER, | ||
|
@@ -18,10 +18,6 @@ | |
from .iid_manager import IIDManager | ||
from .service import Service | ||
|
||
if SUPPORT_QR_CODE: | ||
import base36 | ||
from pyqrcode import QRCode | ||
|
||
|
||
if TYPE_CHECKING: | ||
from .accessory_driver import AccessoryDriver | ||
|
@@ -190,6 +186,12 @@ def xhm_uri(self) -> str: | |
|
||
:rtype: str | ||
""" | ||
try: | ||
import base36 | ||
except ImportError as ie: | ||
raise RuntimeError( | ||
"The base36 module is required to generate X-HM:// URIs" | ||
) from ie | ||
payload = 0 | ||
payload |= 0 & 0x7 # version | ||
|
||
|
@@ -253,7 +255,15 @@ def setup_message(self): | |
Installation through `pip install HAP-python[QRCode]` | ||
""" | ||
pincode = self.driver.state.pincode.decode() | ||
if SUPPORT_QR_CODE: | ||
try: | ||
from qrcode import QRCode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does blocking IO in the event loop |
||
except ImportError: | ||
print( | ||
"To use the QR Code feature, use 'pip install HAP-python[QRCode]'\n" | ||
f"Enter this code in your HomeKit app on your iOS device: {pincode}", | ||
flush=True, | ||
) | ||
else: | ||
xhm_uri = self.xhm_uri() | ||
print(f"Setup payload: {xhm_uri}", flush=True) | ||
print( | ||
|
@@ -264,15 +274,6 @@ def setup_message(self): | |
f"Or enter this code in your HomeKit app on your iOS device: {pincode}", | ||
flush=True, | ||
) | ||
else: | ||
print( | ||
"To use the QR Code feature, use 'pip install HAP-python[QRCode]'", | ||
flush=True, | ||
) | ||
print( | ||
f"Enter this code in your HomeKit app on your iOS device: {pincode}", | ||
flush=True, | ||
) | ||
|
||
@staticmethod | ||
def run_at_interval(seconds): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does blocking IO in the event loop