home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.56k stars 30.73k forks source link

Unable to pair homekit devices to homeassistant #31443

Closed zarboz closed 4 years ago

zarboz commented 4 years ago

Home Assistant release with the issue:

arch : unk dev : false docker : true hassio : true os_name : Linux python_version : 3.8 version : 0.195 virtualenv : true

Last working Home Assistant release (if known):

Operating environment (Hass.io/Docker/Windows/etc.): hassio on raspberry pi 3B

Integration: https://www.home-assistant.io/integrations/homekit_controller/

Description of problem: Homekit devices are discovered but are unable to be paired

Steps to reproduce:

  1. set Homekit device into pairing mode
  2. start homeassistant
  3. click notification to setup
  4. enter pairing code.
  5. pairing fails

Logs attached

2020-02-01 17:21:38 ERROR (MainThread) [homeassistant.components.homekit_controller.config_flow] Pairing attempt failed with an unhandled exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/config_flow.py", line 333, in async_step_pair
    start_pairing, self.hkid, self.hkid
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.7/site-packages/homekit/controller/controller.py", line 383, in start_pairing
    salt, pub_key = perform_pair_setup_part1(write_fun)
  File "/usr/local/lib/python3.7/site-packages/homekit/protocol/__init__.py", line 113, in perform_pair_setup_part1
    response_tlv = write_fun(request_tlv, step2_expectations)
  File "/usr/local/lib/python3.7/site-packages/homekit/protocol/__init__.py", line 64, in write_http
    connection.endheaders(request)
  File "/usr/local/lib/python3.7/http/client.py", line 1247, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.7/site-packages/homekit/http_impl/http_client.py", line 44, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.7/http/client.py", line 966, in send
    self.connect()
  File "/usr/local/lib/python3.7/http/client.py", line 938, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/local/lib/python3.7/socket.py", line 728, in create_connection
    raise err
  File "/usr/local/lib/python3.7/socket.py", line 716, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 110] Operation timed out
2020-02-01 17:21:50 ERROR (MainThread) [homeassistant.components.homekit_controller.config_flow] Pairing attempt failed with an unhandled exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/config_flow.py", line 299, in async_step_pair
    await self.hass.async_add_executor_job(self.finish_pairing, code)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
TypeError: 'NoneType' object is not callable
2020-02-01 17:22:24 ERROR (MainThread) [homeassistant.components.homekit_controller.config_flow] Pairing attempt failed with an unhandled exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/config_flow.py", line 333, in async_step_pair
    start_pairing, self.hkid, self.hkid
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.7/site-packages/homekit/controller/controller.py", line 383, in start_pairing
    salt, pub_key = perform_pair_setup_part1(write_fun)
  File "/usr/local/lib/python3.7/site-packages/homekit/protocol/__init__.py", line 113, in perform_pair_setup_part1
    response_tlv = write_fun(request_tlv, step2_expectations)
  File "/usr/local/lib/python3.7/site-packages/homekit/protocol/__init__.py", line 64, in write_http
    connection.endheaders(request)
  File "/usr/local/lib/python3.7/http/client.py", line 1247, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.7/site-packages/homekit/http_impl/http_client.py", line 44, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.7/http/client.py", line 966, in send
    self.connect()
  File "/usr/local/lib/python3.7/http/client.py", line 938, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/local/lib/python3.7/socket.py", line 728, in create_connection
    raise err
  File "/usr/local/lib/python3.7/socket.py", line 716, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 110] Operation timed out
2020-02-01 17:40:15 ERROR (MainThread) [homeassistant.components.homekit_controller.config_flow] Pairing attempt failed with an unhandled exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/config_flow.py", line 333, in async_step_pair
    start_pairing, self.hkid, self.hkid
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.7/site-packages/homekit/controller/controller.py", line 383, in start_pairing
    salt, pub_key = perform_pair_setup_part1(write_fun)
  File "/usr/local/lib/python3.7/site-packages/homekit/protocol/__init__.py", line 113, in perform_pair_setup_part1
    response_tlv = write_fun(request_tlv, step2_expectations)
  File "/usr/local/lib/python3.7/site-packages/homekit/protocol/__init__.py", line 64, in write_http
    connection.endheaders(request)
  File "/usr/local/lib/python3.7/http/client.py", line 1247, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.7/site-packages/homekit/http_impl/http_client.py", line 44, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.7/http/client.py", line 966, in send
    self.connect()
  File "/usr/local/lib/python3.7/http/client.py", line 938, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/local/lib/python3.7/socket.py", line 728, in create_connection
    raise err
  File "/usr/local/lib/python3.7/socket.py", line 716, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 110] Operation timed out
probot-home-assistant[bot] commented 4 years ago

Hey there @Jc2k, mind taking a look at this issue as its been labeled with a integration (homekit_controller) you are listed as a codeowner for? Thanks!

Hukuma1 commented 4 years ago

Does your device hang with the circle spinning until it errors out? You can try this quick edit to see if your issue was like mine.

https://github.com/home-assistant/home-assistant/issues/30592#issuecomment-574048154

Btw @Jc2k, I see that the tlv file was edited again and went back to \x01. Are you still working on this fix? I've manually edited the flag back to \x00 in the mean time.

zarboz commented 4 years ago

more on this issue:

When running homeassistant as native OS I can pair homekit device

when virtualizing using VMDK install I cannot pair a homekit device and receive above error

@hukuma1 the error I get is a little different

It sits and thinks then prompts for pin and fails pairing

Use case is a LG WebOS TV that is homekit enabled

am able to add to iphone homekit app directly.

I ended up just pairing the TV using webos pairing but it would be nice to figure out why i cant pair Home kit stuff to the HASS.IO vmdk install

Jc2k commented 4 years ago

@Hukuma1 Don't worry about that reverting, now that you are paired it will continue to work. The fix is stalled upstream though - we don't know how to tell which devices need a 0 and which need a 1.

@zarboz This looks like an environment issue rather than a homekit_controller thing. You see the error originates inside python:

  File "/usr/local/lib/python3.7/socket.py", line 716, in create_connection
    sock.connect(sa)

That's a timeout waiting for the OS to reach from your failing environment to the homekit device. I'm not really sure about how to help you go about resolving something like that - no amount of changes of the homekit protocol code will help if its failing before the protocol even starts executing! :-(

Note that even if we got this to pair the Television type is currently not supported either :-(

Jc2k commented 4 years ago

(Next step is probably to take this to the homekit_python project (https://github.com/jlusiardi/homekit_python/) - report a bug there if the CLI there also fails in the same way).

zarboz commented 4 years ago

@Jc2k thanks will continue bug report there if I can find more details about incident

mickae1 commented 1 year ago

Hi, I've the same problem on the native OS:

Logger: homeassistant.components.homekit_controller.config_flow
Source: components/homekit_controller/config_flow.py:453
Integration: homekit_controller (documentation, issues)
First occurred: 06:15:34 (4 occurrences)
Last logged: 06:23:11

Pairing attempt failed with an unhandled exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/config_flow.py", line 453, in async_step_pair
    pairing = await self.finish_pairing(code)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohomekit/controller/ip/discovery.py", line 83, in finish_pairing
    response = await self.connection.post_tlv(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohomekit/controller/ip/connection.py", line 416, in post_tlv
    response = await self.post(
               ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohomekit/controller/ip/connection.py", line 377, in post
    return await self.request(
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohomekit/controller/ip/connection.py", line 440, in request
    raise AccessoryDisconnectedError(
aiohomekit.exceptions.AccessoryDisconnectedError: Connection lost before request could be sent