Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions homeassistant/components/homekit_controller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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]
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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 UnknownError is thrown the only message that's displayed is "Received an unknown error. [...]" and debugging an issue is going to be difficult with just that error message.

Maybe replace the return on the line below withraise so that a) the configurator still shows an error but b) the complete stack trace is shown?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

raise

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"
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ holidays==0.9.4
home-assistant-frontend==20180420.0

# homeassistant.components.homekit_controller
# homekit==0.5
# homekit==0.6

# homeassistant.components.homematicip_cloud
homematicip==0.8
Expand Down