-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Handle HomeKit configuration failure more cleanly #14041
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |
| from homeassistant.helpers import discovery | ||
| from homeassistant.helpers.entity import Entity | ||
|
|
||
| REQUIREMENTS = ['homekit==0.5'] | ||
| REQUIREMENTS = ['homekit==0.6'] | ||
|
|
||
| DOMAIN = 'homekit_controller' | ||
| HOMEKIT_DIR = '.homekit' | ||
|
|
@@ -133,10 +133,31 @@ def device_config_callback(self, callback_data): | |
| import homekit | ||
| pairing_id = str(uuid.uuid4()) | ||
| code = callback_data.get('code').strip() | ||
| self.pairing_data = homekit.perform_pair_setup( | ||
| self.conn, code, pairing_id) | ||
| try: | ||
| self.pairing_data = homekit.perform_pair_setup(self.conn, code, | ||
| pairing_id) | ||
| except homekit.exception.UnavailableError: | ||
| error_msg = "This accessory is already paired to another device. \ | ||
| Please reset the accessory and try again." | ||
| _configurator = self.hass.data[DOMAIN+self.hkid] | ||
| self.configurator.notify_errors(_configurator, error_msg) | ||
| return | ||
| except homekit.exception.AuthenticationError: | ||
| error_msg = "Incorrect HomeKit code for {}. Please check it and \ | ||
| try again.".format(self.model) | ||
| _configurator = self.hass.data[DOMAIN+self.hkid] | ||
|
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. indentation contains mixed spaces and tabs |
||
| self.configurator.notify_errors(_configurator, error_msg) | ||
| return | ||
| except homekit.exception.UnknownError: | ||
| error_msg = "Received an unknown error. Please file a bug." | ||
| _configurator = self.hass.data[DOMAIN+self.hkid] | ||
| self.configurator.notify_errors(_configurator, error_msg) | ||
|
Member
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. If it's an unknown error, wouldn't it be good to print the stack trace? If I understand correctly, when an Maybe replace the
Contributor
Author
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. That seems reasonable. The problem with UnknownError is that the device literally returned what the HomeKit spec defines as an unknown error, so it's unlikely that we're going to get much more from the stack trace, but it's going to be better than nothing. |
||
| return | ||
|
|
||
| if self.pairing_data is not None: | ||
| homekit.save_pairing(self.pairing_file, self.pairing_data) | ||
| _configurator = self.hass.data[DOMAIN+self.hkid] | ||
| self.configurator.request_done(_configurator) | ||
| self.accessory_setup() | ||
| else: | ||
| error_msg = "Unable to pair, please try again" | ||
|
|
||
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.
indentation contains mixed spaces and tabs