Core: Homekit Controller Koogeek

Created on 3 Dec 2018  ·  87Comments  ·  Source: home-assistant/core

I have this error running hassio.io 0.83.1 :

Error executing service <ServiceCall configurator.configure (c:3f56736447fb48d2b9cd8615f566f639): configure_id=1902096688-2, fields=code=xxx-xx-xxx>
Traceback (most recent call last):
  File “/usr/local/lib/python3.6/site-packages/homeassistant/core.py”, line 1177, in _event_to_service_call
    await service_handler.func(service_call)
  File “/usr/local/lib/python3.6/site-packages/homeassistant/components/configurator.py”, line 221, in async_handle_service_call
    call.data.get(ATTR_FIELDS, {}))
  File “/usr/local/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File “/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/init.py”, line 192, in device_config_callback
    pairing_id)
  File “/usr/local/lib/python3.6/site-packages/homekit/protocol.py”, line 69, in perform_pair_setup
    connection.request(‘POST’, ‘/pair-setup’, request_tlv, headers)
  File “/usr/local/lib/python3.6/http/client.py”, line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File “/usr/local/lib/python3.6/http/client.py”, line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File “/usr/local/lib/python3.6/http/client.py”, line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File “/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/init.py”, line 64, in homekit_http_send
    self.send(msg)
  File “/usr/local/lib/python3.6/http/client.py”, line 964, in send
    self.connect()
  File “/usr/local/lib/python3.6/http/client.py”, line 936, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File “/usr/local/lib/python3.6/socket.py”, line 724, in create_connection
    raise err
  File “/usr/local/lib/python3.6/socket.py”, line 713, in create_connection
    sock.connect(sa)
socket.timeout: timed out

How Can I fix it?

homekit_controller

Most helpful comment

Alpine Linux v3.9 is now official: https://alpinelinux.org/posts/Alpine-3.9.0-released.html

The Docker tag is also updated. Hope the team uses it soon 😢

All 87 comments

What does your homekit configuration look like?

I have the same problem:

Error executing service <ServiceCall configurator.configure (c:bdfdcfa65e5e4cb08daa69936298f7d9): configure_id=1867467760-2, fields=code=xxx-xx-xxx>

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/core.py", line 1177, in _event_to_service_call
    await service_handler.func(service_call)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/configurator.py", line 221, in async_handle_service_call
    call.data.get(ATTR_FIELDS, {}))
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 192, in device_config_callback
    pairing_id)
  File "/usr/local/lib/python3.6/site-packages/homekit/protocol.py", line 94, in perform_pair_setup
    resp = connection.getresponse()
  File "/usr/local/lib/python3.6/http/client.py", line 1331, in getresponse
    response.begin()
  File "/usr/local/lib/python3.6/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.6/http/client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/local/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

Config:

homekit:
discovery:
  enable:
    - homekit

I have a Koogeek P1EU and LS1 and both have the same problem, can't pair with HASS.

EDIT: I thin is the same as #18241

I have the exact same issue as @rdelcampog (and same configuration)

@arkan @cgarwood @NDNELSON I've just found the problem. Since version 0.79.0 the homekit_controller introduces a 5 seconds timeout. If device needs more than 5 seconds to pair or configure, connection is closed.

Workaround: create the folders: /custom_components/homekit_controller inside /config, create a new file "__init__.py", copy and paste contents of the library: https://raw.githubusercontent.com/home-assistant/home-assistant/dev/homeassistant/components/homekit_controller/__init__.py and change the line 42 from "REQUEST_TIMEOUT = 5" to "REQUEST_TIMEOUT = 60".

@rdelcampog thanks it works but I have another problem : entity id not shows in my devices list I dont know where is it. And this is my log file:

Error executing service <ServiceCall configurator.configure (c:e8e3fdbb619144429a3690e1138def77): configure_id=1899397168-4, fields=code=XXX-XX-XXX>
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/core.py", line 1177, in _event_to_service_call
    await service_handler.func(service_call)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/configurator.py", line 221, in async_handle_service_call
    call.data.get(ATTR_FIELDS, {}))
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/homekit_controller/__init__.py", line 215, in device_config_callback
    self.accessory_setup()
  File "/config/custom_components/homekit_controller/__init__.py", line 137, in accessory_setup
    data = self.get_json('/accessories')
  File "/config/custom_components/homekit_controller/__init__.py", line 164, in get_json
    response = self.securecon.get(target)
AttributeError: 'NoneType' object has no attribute 'get'

@arkan @cgarwood @NDNELSON I've just found the problem. Since version 0.79.0 the homekit_controller introduces a 5 seconds timeout. If device needs more than 5 seconds to pair or configure, connection is closed.

Workaround: create the folders: /custom_components/homekit_controller inside /config, create a new file "init.py", copy and paste contents of the library: https://raw.githubusercontent.com/home-assistant/home-assistant/dev/homeassistant/components/homekit_controller/__init__.py and change the line 42 from "REQUEST_TIMEOUT = 5" to "REQUEST_TIMEOUT = 60".

I tried the same but it won’t add it I’m afraid my output is:

Error handling message: {'type': 'call_service', 'domain': 'configurator', 'service': 'configure', 'service_data': {'configure_id': '140101190929488-1', 'fields': {'code': 'xxx-xx-xxx'}}, 'id': 17}
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/websocket_api/decorators.py", line 16, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/app/homeassistant/components/websocket_api/commands.py", line 148, in handle_call_service
    connection.context(msg))
  File "/usr/src/app/homeassistant/core.py", line 1121, in async_call
    self._execute_service(handler, service_call))
  File "/usr/src/app/homeassistant/core.py", line 1143, in _execute_service
    await handler.func(service_call)
  File "/usr/src/app/homeassistant/components/configurator.py", line 221, in async_handle_service_call
    call.data.get(ATTR_FIELDS, {}))
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/components/homekit_controller/__init__.py", line 192, in device_config_callback
    pairing_id)
  File "/config/deps/lib/python3.6/site-packages/homekit/protocol.py", line 69, in perform_pair_setup
    connection.request('POST', '/pair-setup', request_tlv, headers)
  File "/usr/local/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/src/app/homeassistant/components/homekit_controller/__init__.py", line 64, in homekit_http_send
    self.send(msg)
  File "/usr/local/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/usr/local/lib/python3.6/http/client.py", line 936, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/local/lib/python3.6/socket.py", line 724, in create_connection
    raise err
  File "/usr/local/lib/python3.6/socket.py", line 713, in create_connection
    sock.connect(sa)
socket.timeout: timed out

Also if I name the init.py file as _init_.py I receive the following:

Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/components/sensor/waze_travel_time.py", line 74, in <lambda>
    EVENT_HOMEASSISTANT_START, lambda _: sensor.update())
  File "/usr/src/app/homeassistant/components/sensor/waze_travel_time.py", line 204, in update
    routes = params.calc_all_routes_info(real_time=self._realtime)
  File "/usr/local/lib/python3.6/site-packages/WazeRouteCalculator/WazeRouteCalculator.py", line 145, in calc_all_routes_info
    routes = self.get_route(npaths, time_delta)
  File "/usr/local/lib/python3.6/site-packages/WazeRouteCalculator/WazeRouteCalculator.py", line 95, in get_route
    response_json = response.json()
  File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.6/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python3.6/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I tryed to extend the timeout and it worked.
But i get a new error

Sun Jan 06 2019 23:13:03 GMT+0100 (Centraleuropæisk normaltid)

homekit_controller: Error on device update!
Traceback (most recent call last):
  File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py”, line 248, in _async_add_entity
    await entity.async_device_update(warning=False)
  File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py”, line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File “/usr/local/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File “/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/init.py”, line 251, in update
    data = self._accessory.get_json(’/accessories’)
AttributeError: ‘HKDevice’ object has no attribute ‘get_json’

After updating HASS its working... but after a couple of hours it stops responding with this error:


2019-01-11 17:03:08 ERROR (MainThread) [homeassistant.helpers.entity] Update for switch.p1eu_4 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
    return self._read_response()
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 131, in _read_response
    data = self.sock.recv(exp_len)
socket.timeout: timed out

Then after i reboot HASS it works again for some time ?

Woo - it looks like my pull request helped a little bit. I've been working on homekit_controller to get it ready for bluetooth homekit devices and so the HTTP requests that were failing for you are now hidden in the homekit library hass uses (http://github.com/jlusiardi/homekit_python). I guess the implementation has changed a little bit and the timeout is now a bit longer than it used to be.

Can I just check a few assumptions:

  • How often have you had to restart it so far?
  • Do you just restart HASS or do you restart the homekit device as well?
  • Do you see multiple tracebacks like this or does it stop entirely after the first traceback?
  • When it breaks, do you see an error like this about once a minute or are they spread out over a random period of time?

How comfortable are you making changes to the code yourself?

One limitation I think I can see with the current code (I need to dig in some more) is i'm not sure how it would handle things if the IP of the homekit device got a different IP address from DHCP whilst HASS was running. In that scenario, restarting HASS and only hass would fix it. Are you able to set up a static DHCP lease for this device to rule that out?

I've ordered a Koogeek LS1 to see if I can debug some of the Koogeek issues on this github, but i'm in the middle of quite a few other HASS/homekit changes so it might take me a bit to get at this properly.

Hello Jc2k. thank you for your reply :-)

How often have you had to restart it so far?
Many times a day. Dont know how many. but i think it only works 1-3 of hours before it needs reboot.

Do you just restart HASS or do you restart the homekit device as well?
I only need to restart HASS
Do you see multiple tracebacks like this or does it stop entirely after the first traceback?
It keeps going to next reboot

When it breaks, do you see an error like this about once a minute or are they spread out over a random period of time?
Evert minut.


Update for switch.p1eu_4 fails
09.52 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_3 fails
09.52 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu fails
09.52 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_2 fails
09.52 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu fails
09.52 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_3 fails
09.52 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_2 fails
09.52 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_4 fails
09.52 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_4 fails
09.51 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_2 fails
09.51 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu fails
09.51 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_3 fails
09.51 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_3 fails
09.51 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_2 fails
09.51 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_4 fails
09.51 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu fails
09.51 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_2 fails
09.50 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu fails
09.50 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_3 fails
09.50 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_4 fails
09.50 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_2 fails
09.50 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_4 fails
09.50 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu fails
09.50 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_3 fails
09.50 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu fails
09.49 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)

Sat Jan 12 2019 09:52:41 GMT+0100 (Centraleuropæisk normaltid)

Update for switch.p1eu_4 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 88, in _handle_request
    self.sock.send(len_bytes + ciper_and_mac[0] + ciper_and_mac[1])
BrokenPipeError: [Errno 32] Broken pipe

How comfortable are you making changes to the code yourself? Dont think it would be a problem :-) Just want it working :-D. So if you tell me where and i will be happy to test and give info back.

They already running with static dhcp ip

If you can find the time i will be very happy. but im glad just to know someone is looking in to it :-)

I also get this error


Mon Jan 14 2019 21:21:54 GMT+0100 (Centraleuropæisk normaltid)

Update for switch.p1eu_4 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
    return self._read_response()
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 154, in _read_response
    response.parse(decrypted)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/response.py", line 38, in parse
    self._raw_response += part
TypeError: can't concat bool to bytearray

Thanks for the update @bncbnc83. This 2nd error is tricky. I know that the decryption code sometimes returns False (e.g. if messages are decrypted in the wrong order). So it's like that code isn't handling a failed decryption properly. I've raised a bug for that here, but I think the timeout is the issue to concentrate on first. I have a few ideas - i'll try to put together some more tests to try as soon as i can.

@bncbnc83 I've put together a PR for the timeout issue. It closes the secure session and opens another if the current one fails. This should stop it failing entirely like it is doing now, if a single update fails the next one should reconnect. But there might be intermittent connection dropouts still that it recovers from.

I haven't tested it yet (away from my HK devices) but the tests still pass. If you want to try it you should be able to install it direct from my github with something like:

pip install https://github.com/Jc2k/homekit_python/archive/90_recover_from_tcp_failure.zip

@Jc2k thank you for your work:-)
I tryed to update now i get new errors (or maybe its the same errors...i dont know :-) )


homekit_controller: Error on device update!
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 248, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
    return self._read_response()
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 131, in _read_response
    data = self.sock.recv(exp_len)
socket.timeout: timed out
______________________________
Tue Jan 15 2019 21:56:08 GMT+0100 (Centraleuropæisk normaltid)

Update for switch.p1eu_2 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
    return self._read_response()
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 131, in _read_response
    data = self.sock.recv(exp_len)
socket.timeout: timed out
_______________________
Update for switch.p1eu_2 fails
21.57 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_2 fails
21.56 deps/lib/python3.6/site-packages/homekit/http_impl/response.py (ERROR)
Update for switch.p1eu_2 fails
21.56 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_2 fails
21.56 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
homekit_controller: Error on device update!
21.54 deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
______________________________
Update for switch.p1eu_2 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
    return self._read_response()
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 154, in _read_response
    response.parse(decrypted)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/response.py", line 38, in parse
    self._raw_response += part
TypeError: can't concat bool to bytearray

Hmmm I’m not sure if the upgrade worked - can you try again but pass —upgrade to pip? (2 dashes, my phone keeps turning it into one). If it still doesn’t work do a pip uninstall homekit before the install.

Hello :-)
tryed again. But i think it still fail.

here is what i did(Dont know if its the right way)
My server is running on my server (Hyper-V)
i connect to the server
use user root
type login to get to shell
Type docker exec -it homeassistant /bin/bash
type pip install https://github.com/Jc2k/homekit_python/archive/90_recover_from_tcp_failure.zip
also tryed uninstall before.
and also tryed to reboot the docker homeassistant afterwards
am i doing something wrong ?

Hi folks,

I also got some issues with the koogeek items (3x switch.p1eu & 1x switch.kh02cn). After some time the items may lose the connection or whatever. They are unreachable over the frontend, the switch immediately turn from on to off or reversed after operated. They appear as ON in the Home app, but won't react to any action. If I restart HASS (0.85 via Synology Docker) it's working for a period of time, but then still runs in the same error.

Update for switch.p1eu_2 fails
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/app/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
    return self._read_response()
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 154, in _read_response
    response.parse(decrypted)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/response.py", line 38, in parse
    self._raw_response += part
TypeError: can't concat bool to bytearray

Hey @bncbnc83 - when you install from my PR you should see something like:

pip install --upgrade https://github.com/Jc2k/homekit_python/archive/90_recover_from_tcp_failure.zip
Collecting https://github.com/Jc2k/homekit_python/archive/90_recover_from_tcp_failure.zip
  Downloading https://github.com/Jc2k/homekit_python/archive/90_recover_from_tcp_failure.zip
     / 1.4MB 11.9MB/s
Requirement already up-to-date: ed25519 in ./venv/lib/python3.6/site-packages (from homekit==0.12.0)
Requirement already up-to-date: gmpy2 in ./venv/lib/python3.6/site-packages (from homekit==0.12.0)
Requirement already up-to-date: hkdf in ./venv/lib/python3.6/site-packages (from homekit==0.12.0)
Requirement already up-to-date: py25519 in ./venv/lib/python3.6/site-packages (from homekit==0.12.0)
Requirement already up-to-date: zeroconf in ./venv/lib/python3.6/site-packages (from homekit==0.12.0)
Requirement already up-to-date: cffi-utils in ./venv/lib/python3.6/site-packages (from py25519->homekit==0.12.0)
Requirement already up-to-date: ifaddr in ./venv/lib/python3.6/site-packages (from zeroconf->homekit==0.12.0)
Requirement already up-to-date: cffi>=1.0.0 in ./venv/lib/python3.6/site-packages (from cffi-utils->py25519->homekit==0.12.0)
Requirement already up-to-date: pycparser in ./venv/lib/python3.6/site-packages (from cffi>=1.0.0->cffi-utils->py25519->homekit==0.12.0)
Installing collected packages: homekit
  Found existing installation: homekit 0.12.0
    Uninstalling homekit-0.12.0:
      Successfully uninstalled homekit-0.12.0
  Running setup.py install for homekit ... done
Successfully installed homekit-0.12.0

In paricular, did it say it uninstalled it and reinstalled it?

With the first command I gave you it probably looked like it did something but:

  Requirement already satisfied (use --upgrade to upgrade): homekit==0.12.0 from https://github.com/J...

if it says that it didn't actually change anything!

If i use the command I gave in this comment and restart HASS then I deliberately break my connection I now get this:

2019-01-16 12:25:46 ERROR (MainThread) [homeassistant.helpers.entity] Update for light.ls1 fails
Traceback (most recent call last):
  File "/home/john/homekit_python/homekit/http_impl/secure_http.py", line 92, in _handle_request
    return self._read_response()
  File "/home/john/homekit_python/homekit/http_impl/secure_http.py", line 136, in _read_response
    data = self.sock.recv(exp_len)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/john/home-assistant/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/home/john/home-assistant/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/john/home-assistant/homeassistant/components/homekit_controller/__init__.py", line 248, in update
    new_values_dict = pairing.get_characteristics(self._chars_to_poll)
  File "/home/john/homekit_python/homekit/controller.py", line 375, in get_characteristics
    response = self.session.get(url)
  File "/home/john/homekit_python/homekit/controller.py", line 614, in get
    return self.sec_http.get(url)
  File "/home/john/homekit_python/homekit/http_impl/secure_http.py", line 66, in get
    return self._handle_request(data)
  File "/home/john/homekit_python/homekit/http_impl/secure_http.py", line 94, in _handle_request
    raise exceptions.AccessoryDisconnectedError(str(e))
homekit.exceptions.AccessoryDisconnectedError: [Errno 104] Connection reset by peer

Not quite the same as a timeout but is an idea of what i'm expecting to happen in your case.

Although the error is still logged it recovers from this (not like before where it was broken until a restart).

To be clear - there will still be an exception logged, but this branch should mean it recovers from the failure to some degree.

@dave-castle hi! thanks for reaching out. yes, it looks like you are hitting the same issue. the PR i'm talking about should stop the failure from requiring a HA restart. But I could do with feedback from a HA user first. If you are comfortable making changes to a running container then you can do something like:

$ docker exec -it yourcontainer bash
# pip install --upgrade https://github.com/Jc2k/homekit_python/archive/90_recover_from_tcp_failure.zip

If it works you should see:

Installing collected packages: homekit
  Found existing installation: homekit 0.12.0
    Uninstalling homekit-0.12.0:
      Successfully uninstalled homekit-0.12.0
Successfully installed homekit-0.12.0

Then restart your container and let me know how you get on. You will still see some timeouts - but they should no longer be fatal.

@Jc2k i think that did the trick :-D 👍
it keeps working right now...
but i still get errors


Press the button to load the full Home Assistant log.

2019-01-16 22:43:43 ERROR (MainThread) [homeassistant.helpers.entity] Update for switch.p1eu_4 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
    return self._read_response()
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 131, in _read_response
    data = self.sock.recv(exp_len)
socket.timeout: timed out
2019-01-16 22:44:13 ERROR (MainThread) [homeassistant.helpers.entity] Update for switch.p1eu_4 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
    return self._read_response()
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 131, in _read_response
    data = self.sock.recv(exp_len)
socket.timeout: timed out
2019-01-16 22:44:43 ERROR (MainThread) [homeassistant.helpers.entity] Update for switch.p1eu_4 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
    return self._read_response()
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 154, in _read_response
    response.parse(decrypted)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/response.py", line 38, in parse
    self._raw_response += part
TypeError: can't concat bool to bytearray
2019-01-16 22:45:14 ERROR (MainThread) [homeassistant.helpers.entity] Update for switch.p1eu_4 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
    return self._read_response()
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 154, in _read_response
    response.parse(decrypted)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/response.py", line 38, in parse
    self._raw_response += part
TypeError: can't concat bool to bytearray
2019-01-16 22:45:45 ERROR (MainThread) [homeassistant.helpers.entity] Update for switch.p1eu_4 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
    return self._read_response()
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 131, in _read_response
    data = self.sock.recv(exp_len)
socket.timeout: timed out
2019-01-16 22:46:15 ERROR (MainThread) [homeassistant.helpers.entity] Update for switch.p1eu_4 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
    return self._read_response()
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 154, in _read_response
    response.parse(decrypted)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/response.py", line 38, in parse
    self._raw_response += part
TypeError: can't concat bool to bytearray
2019-01-16 22:46:46 ERROR (MainThread) [homeassistant.helpers.entity] Update for switch.p1eu_4 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
    return self._read_response()
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 154, in _read_response
    response.parse(decrypted)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/response.py", line 38, in parse
    self._raw_response += part
TypeError: can't concat bool to bytearray
2019-01-16 22:47:17 ERROR (MainThread) [homeassistant.helpers.entity] Update for switch.p1eu_4 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
    return self._read_response()
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 131, in _read_response
    data = self.sock.recv(exp_len)
socket.timeout: timed out
2019-01-16 22:47:48 ERROR (MainThread) [homeassistant.helpers.entity] Update for switch.p1eu_4 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
    return self._read_response()
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 154, in _read_response
    response.parse(decrypted)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/response.py", line 38, in parse
    self._raw_response += part
TypeError: can't concat bool to bytearray
2019-01-16 22:48:19 ERROR (MainThread) [homeassistant.helpers.entity] Update for switch.p1eu_4 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
    return self._read_response()
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 131, in _read_response
    data = self.sock.recv(exp_len)
socket.timeout: timed out
2019-01-16 22:48:50 ERROR (MainThread) [homeassistant.helpers.entity] Update for switch.p1eu_4 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
    return self._read_response()
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 154, in _read_response
    response.parse(decrypted)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/response.py", line 38, in parse
    self._raw_response += part
TypeError: can't concat bool to bytearray
2019-01-16 22:49:21 ERROR (MainThread) [homeassistant.helpers.entity] Update for switch.p1eu_4 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
    return self._read_response()
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 154, in _read_response
    response.parse(decrypted)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/response.py", line 38, in parse
    self._raw_response += part
TypeError: can't concat bool to bytearray

Afterwards i tryed quick turning on/off a couple of times then it stops responding and i had to reboot. (not included in the pasted log)

But for now it respons when turn on/off as you normal would use it
i will give an update tomorrow about if it keeps working after some hours

@Jc2k no still the same 😔

Same here 😢

Even the update to 0.85.1 brought no improvement

In the logs posted you are still not seeing a AccessoryDisconnectedError. That’s unexpected. You are seeing socket.timeout, which is a subclass of OSError since python 3.3, which the new code is supposed to be catching :/ ill have another look..

@Jc2k thank you :-) 👍

@bncbnc83 Ok have reproduced a related error here, amended my PR and am seeing if it recurs. Hope to give you an updated download to try.. soonish. But still haven't seen a socket.timeout in my environment :(.

@Jc2k its not hard to get here :-D
Is there any info i can give you to help ?

Btw if i type pip uninstall homekit and reboots its still adds and give the samme errors ?


Update for switch.p1eu_2 fails
4:23 PM deps/lib/python3.6/site-packages/homekit/http_impl/response.py (ERROR)
Update for switch.p1eu_3 fails
4:23 PM deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_2 fails
4:23 PM deps/lib/python3.6/site-packages/homekit/http_impl/response.py (ERROR)
Update for switch.p1eu_2 fails
4:22 PM deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)
Update for switch.p1eu_2 fails
4:22 PM deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py (ERROR)


How can it still "Work" after removing homekit ?
if type pip uninstall homekit it say its not installed ?

So the deps/ folder contains pip packages it installed itself, but normal pip doesn't know about them. Even if you did delete it, it would reinstall the 'stable' released version again. I don't know which folder has precedence. It's possible this auto-installed one is taking precedence and thats the problem. You could do the pip install and then rm deps/lib/python3.6/site-packages/homekit and see if that helps?

I think it works after i removed the other homekit folder :-D 👍
No errors yet :-D

You should still see at least one error if its hit the timeout! It should just stop spamming them and recover from it... Need to do a change against homeassistant to get it fixed entirely.

@Jc2k 👍
I will update later to with info about if it keeps working :-)

EDIT:
Just a early update - its still working but i got some errors


Update for switch.p1eu_3 fails
4:51 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
4:51 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
4:49 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
4:48 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
4:47 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
4:47 PM components/homekit_controller/__init__.py (ERROR)
_________________________________________
Thu Jan 17 2019 16:47:18 GMT+0100 (Centraleuropæisk normaltid)

Update for switch.p1eu_3 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/usr/local/lib/python3.6/site-packages/homekit/controller.py", line 274, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/usr/local/lib/python3.6/site-packages/homekit/controller.py", line 614, in get
    return self.sec_http.get(url)
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 66, in get
    return self._handle_request(data)
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 92, in _handle_request
    return self._read_response()
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 159, in _read_response
    response.parse(decrypted)
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/response.py", line 38, in parse
    self._raw_response += part
TypeError: can't concat bool to bytearray
__________________________________________
Thu Jan 17 2019 16:47:44 GMT+0100 (Centraleuropæisk normaltid)

Update for switch.p1eu_3 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 92, in _handle_request
    return self._read_response()
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 136, in _read_response
    data = self.sock.recv(exp_len)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/usr/local/lib/python3.6/site-packages/homekit/controller.py", line 274, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/usr/local/lib/python3.6/site-packages/homekit/controller.py", line 614, in get
    return self.sec_http.get(url)
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 66, in get
    return self._handle_request(data)
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 94, in _handle_request
    raise exceptions.AccessoryDisconnectedError(str(e))
homekit.exceptions.AccessoryDisconnectedError: timed out

It's weird, but automations are workin' without problems, just switching on/off in Home or in the HASS frontend are broken 🤔

Still not seen a timeout over here! My instance has been running since a couple of hours before you updated as well. Wonder what the underlying reason is...

Anyway - this is great. I need to get this fix into a homekit release before I can do the corresponding homeassistant bit. Will update my PR with your success.

@dave-castle that is weird 🤔 are you seeing the same errors as before? do you see any errors in the logs when automations run?

Mine keeps working after upgrading the fixed homekit and removed homekit from deps.
Now i also got the Peer timeout + some others (But it keeps working :-DDD 👍 )


Thu Jan 17 2019 17:50:54 GMT+0100 (Centraleuropæisk normaltid)

Update for switch.p1eu_4 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 92, in _handle_request
    return self._read_response()
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 136, in _read_response
    data = self.sock.recv(exp_len)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/usr/local/lib/python3.6/site-packages/homekit/controller.py", line 274, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/usr/local/lib/python3.6/site-packages/homekit/controller.py", line 614, in get
    return self.sec_http.get(url)
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 66, in get
    return self._handle_request(data)
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 94, in _handle_request
    raise exceptions.AccessoryDisconnectedError(str(e))
homekit.exceptions.AccessoryDisconnectedError: [Errno 104] Connection reset by peer
_______________________________________

Log Details (ERROR)
Thu Jan 17 2019 17:57:02 GMT+0100 (Centraleuropæisk normaltid)

Update for switch.p1eu_3 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 92, in _handle_request
    return self._read_response()
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 136, in _read_response
    data = self.sock.recv(exp_len)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/usr/local/lib/python3.6/site-packages/homekit/controller.py", line 274, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/usr/local/lib/python3.6/site-packages/homekit/controller.py", line 614, in get
    return self.sec_http.get(url)
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 66, in get
    return self._handle_request(data)
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 94, in _handle_request
    raise exceptions.AccessoryDisconnectedError(str(e))
homekit.exceptions.AccessoryDisconnectedError: timed out
______________________________________
Thu Jan 17 2019 17:47:49 GMT+0100 (Centraleuropæisk normaltid)

Update for switch.p1eu_3 fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/usr/local/lib/python3.6/site-packages/homekit/controller.py", line 274, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/usr/local/lib/python3.6/site-packages/homekit/controller.py", line 614, in get
    return self.sec_http.get(url)
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 66, in get
    return self._handle_request(data)
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 92, in _handle_request
    return self._read_response()
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 159, in _read_response
    response.parse(decrypted)
  File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/response.py", line 38, in parse
    self._raw_response += part
TypeError: can't concat bool to bytearray
_______________________
Update for switch.p1eu_3 fails
5:57 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:55 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:52 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu fails
5:51 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_4 fails
5:50 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:50 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_2 fails
5:50 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:49 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:49 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:48 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:47 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:47 PM components/homekit_controller/__init__.py (ERROR)
Update of switch.p1eu_3 is taking over 10 seconds
5:47 PM util/async_.py (WARNING)
Update for switch.p1eu_3 fails
5:46 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:44 PM components/homekit_controller/__init__.py (ERROR)
Update of switch.p1eu_3 is taking over 10 seconds
5:42 PM util/async_.py (WARNING)
Update for switch.p1eu_3 fails
5:42 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:40 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:40 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:39 PM components/homekit_controller/__init__.py (ERROR)
Update of switch.p1eu_3 is taking over 10 seconds
5:39 PM util/async_.py (WARNING)
Update for switch.p1eu_3 fails
5:39 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:37 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:35 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:34 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:33 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:32 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:31 PM components/homekit_controller/__init__.py (ERROR)
Update of switch.p1eu_3 is taking over 10 seconds
5:31 PM util/async_.py (WARNING)
Update for switch.p1eu_3 fails
5:30 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:26 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:24 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:23 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:22 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:21 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:20 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:20 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:18 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:16 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:15 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:11 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:10 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:06 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:04 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:03 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:02 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:01 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_4 fails
5:00 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
5:00 PM components/homekit_controller/__init__.py (ERROR)
Update for switch.p1eu_3 fails
4:59 PM components/homekit_controller/__init__.py (ERROR)

Dont know if it give more errors when i turn on/off

@Jc2k your my new hero ;-)

I'll check it later within my Docker environment!
Is it going to be fixed in the next HASS release?

@dave-castle that is weird 🤔 are you seeing the same errors as before? do you see any errors in the logs when automations run?

Traceback (most recent call last):
  File "/usr/src/app/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/app/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/components/homekit_controller/__init__.py", line 197, in update
    data = pairing.list_accessories_and_characteristics()
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
    response = self.session.get('/accessories')
  File "/config/deps/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
    return self.sec_http.get(url)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
    return self._handle_request(data)
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
    return self._read_response()
  File "/config/deps/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 131, in _read_response
    data = self.sock.recv(exp_len)
socket.timeout: timed out

Can't promise when it will be fixed - I'm not a HA maintainer or a homekit_python maintainer and I have to get PR's accepted into both to properly address this. But it looks like i'm on the right track and I have had other PR's accepted into both projects already so its not impossible.

@dave-castle looks like your still are running from deps

@Jc2k Still working without reboots 👍 :-)

@bncbnc83 this is great news!

This part of the fix just got rolled into a new release of homekit. It's got a few other changes rolled into it so i'd appreciate it if you could switch to it and give me some feedback.

It should be enough to do:

pip install homekit==0.12.2

Make sure you don't do --upgrade this time.

I'll start putting together the corresponding HA change today/tomorrow.

@Jc2k

Awesome, really appreciate your work!!!
So I’ll wait for official HA fix.

Thanks!!!

@Jc2k
Hello :-)
Now i get


Tue Jan 22 2019 13:19:52 GMT+0100 (Centraleuropæisk normaltid)

Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 290, in discovery_dispatch
    device = HKDevice(hass, host, port, model, hkid, config_num, config)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 91, in __init__
    self.accessory_setup()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 104, in accessory_setup
    data = self.pairing.list_accessories_and_characteristics()
  File "/usr/local/lib/python3.6/site-packages/homekit/controller.py", line 272, in list_accessories_and_characteristics
    self.session = Session(self.pairing_data)
  File "/usr/local/lib/python3.6/site-packages/homekit/controller.py", line 604, in __init__
    c2a_key, a2c_key = get_session_keys(conn, pairing_data)
  File "/usr/local/lib/python3.6/site-packages/homekit/protocol/__init__.py", line 247, in get_session_keys
    ios_key = x25519.X25519PrivateKey.generate()
  File "/usr/local/lib/python3.6/site-packages/cryptography/hazmat/primitives/asymmetric/x25519.py", line 39, in generate
    _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM
cryptography.exceptions.UnsupportedAlgorithm: X25519 is not supported by this version of OpenSSL.

Ick. 1 step forward 2 step back.

Upstream homekit is using cryptography now. That was to run on a wider range of OS's and to let me add tests to HA to stop future regressions. This is a change from py25519 that hasn't had a release in years, won't install at all on some OS's.. It's a bit of a pain dependency for adding tests to HA too. Now if you install cryptography with wheel support it has a version of OpenSSL built in that supports X25519. And I double checked, HA won't start unless it has cryptography==2.3.1. So you should definitely have the right version, and that version works on my linux vms, macs, the HA docker container, even a raspberry pi from 2011. The only thing I can think of is that it didn't use a wheel and instead compiled against your system openssl, and you are on a distro old enough for that to be a problem. If its that then reinstalling it as a wheel will fix it.

What OS are you installing on? Is this the Docker container or bare metal? Arm or Intel/AMD? Can you give me the output of pip freeze | grep cryptography. And also maybe pip freeze | grep wheel.

@Jc2k
Was running in HyperV - Hassio VHDX (beta) image
Now i changed it to Hyper-v - ubuntu and running it from docker
still same error


Log Details (ERROR)
Tue Jan 22 2019 22:06:56 GMT+0100 (Centraleuropæisk normaltid)

Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 290, in discovery_dispatch
    device = HKDevice(hass, host, port, model, hkid, config_num, config)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 91, in __init__
    self.accessory_setup()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 104, in accessory_setup
    data = self.pairing.list_accessories_and_characteristics()
  File "/usr/local/lib/python3.6/site-packages/homekit/controller.py", line 272, in list_accessories_and_characteristics
    self.session = Session(self.pairing_data)
  File "/usr/local/lib/python3.6/site-packages/homekit/controller.py", line 604, in __init__
    c2a_key, a2c_key = get_session_keys(conn, pairing_data)
  File "/usr/local/lib/python3.6/site-packages/homekit/protocol/__init__.py", line 247, in get_session_keys
    ios_key = x25519.X25519PrivateKey.generate()
  File "/usr/local/lib/python3.6/site-packages/cryptography/hazmat/primitives/asymmetric/x25519.py", line 39, in generate
    _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM
cryptography.exceptions.UnsupportedAlgorithm: X25519 is not supported by this version of OpenSSL.

This is what i get from your commands


cryptography==2.3.1
And nothing from wheel¨


Weird - the upstream Docker image works for me. The line of code that fails for you working on the official Docker image:

$ docker run --rm -it homeassistant/home-assistant python
Python 3.6.8 (default, Jan  9 2019, 04:19:48) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from cryptography.hazmat.primitives.asymmetric import x25519
>>> x25519.X25519PrivateKey.generate().public_key().public_bytes()
b'K\x98\n\xb1\xa3F\x1d\x91v.\xe3}\xa1>\xc7\xdd:C\xa7\xab\xfa\x02<\xc4R\rv\x84o~Y6'

It's also working on an Ubuntu 18.04 image:

$ python3 -m venv venv-bncbnc83
$ source venv-bncbnc83/bin/activate
$ pip install --no-cache cryptography==2.3.1
Collecting cryptography==2.3.1
  Downloading https://files.pythonhosted.org/packages/59/32/92cade62c645756a83598edf56289e9b19aae5370642a7ce690cd06bc72f/cryptography-2.3.1-cp34-abi3-manylinux1_x86_64.whl (2.1MB)
    100% |████████████████████████████████| 2.1MB 3.5MB/s 
Collecting idna>=2.1 (from cryptography==2.3.1)
  Downloading https://files.pythonhosted.org/packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 3.3MB/s 
Collecting six>=1.4.1 (from cryptography==2.3.1)
  Downloading https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting cffi!=1.11.3,>=1.7 (from cryptography==2.3.1)
  Downloading https://files.pythonhosted.org/packages/6d/c0/47db8f624f3e4e2f3f27be03a93379d1ba16a1450a7b1aacfa0366e2c0dd/cffi-1.11.5-cp36-cp36m-manylinux1_x86_64.whl (421kB)
    100% |████████████████████████████████| 430kB 3.7MB/s 
Collecting asn1crypto>=0.21.0 (from cryptography==2.3.1)
  Downloading https://files.pythonhosted.org/packages/ea/cd/35485615f45f30a510576f1a56d1e0a7ad7bd8ab5ed7cdc600ef7cd06222/asn1crypto-0.24.0-py2.py3-none-any.whl (101kB)
    100% |████████████████████████████████| 102kB 3.5MB/s 
Collecting pycparser (from cffi!=1.11.3,>=1.7->cryptography==2.3.1)
  Downloading https://files.pythonhosted.org/packages/68/9e/49196946aee219aead1290e00d1e7fdeab8567783e83e1b9ab5585e6206a/pycparser-2.19.tar.gz (158kB)
    100% |████████████████████████████████| 163kB 3.1MB/s 
Installing collected packages: idna, six, pycparser, cffi, asn1crypto, cryptography
  Running setup.py install for pycparser ... done
Successfully installed asn1crypto-0.24.0 cffi-1.11.5 cryptography-2.3.1 idna-2.8 pycparser-2.19 six-1.12.0
$ python
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from cryptography.hazmat.primitives.asymmetric import x25519
>>> x25519.X25519PrivateKey.generate().public_key().public_bytes()
b'\xbd\x0c\x9aJ\x1fv\xf1\x8b\x0e\xc7\xbch\x8a\x056N\x9aY\xf7,st\x96\xe9A\xe4\xcb\xcex\x07W*'
>>> 

Tried something similar on Debian Stretch and it worked there too.

What do you get if you do this?

# ls /usr/local/lib/python3.6/site-packages/cryptography*
# ls /usr/local/lib/python3.6/site-packages/cryptography/hazmat/bindings/

And what is the output if you do this:

pip uninstall cryptography
pip install cryptography==2.3.1

(And does it work after doing that)

Oh and hey - if you put triple back ticks around your output GitHub will format it nicer:

```
Like this
```

strange :-)
Btw its ubuntu 18.04 i run docker on

bash-4.4# ls /usr/local/lib/python3.6/site-packages/cryptography*
/usr/local/lib/python3.6/site-packages/cryptography:
__about__.py   __init__.py    __pycache__    exceptions.py  fernet.py      hazmat         utils.py       x509

/usr/local/lib/python3.6/site-packages/cryptography-2.3.1-py3.6.egg-info:
PKG-INFO              SOURCES.txt           dependency_links.txt  installed-files.txt   not-zip-safe          requires.txt          top_level.txt
bash-4.4# ls /usr/local/lib/python3.6/site-packages/cryptography/hazmat/bindings/
__init__.py             __pycache__             _constant_time.abi3.so  _openssl.abi3.so        _padding.abi3.so        openssl

Now i hit errors after reinstalling

  Failed building wheel for cryptography
  Running setup.py clean for cryptography
Failed to build cryptography
Command "/usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-4jbcfj5a/cryptography/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-0y_dtf3q/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-4jbcfj5a/cryptography/

Full log

bash-4.4# pip uninstall cryptography
Uninstalling cryptography-2.3.1:
  Would remove:
    /usr/local/lib/python3.6/site-packages/cryptography-2.3.1-py3.6.egg-info
    /usr/local/lib/python3.6/site-packages/cryptography/*
Proceed (y/n)? y
  Successfully uninstalled cryptography-2.3.1
You are using pip version 18.0, however version 19.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
bash-4.4# pip install cryptography==2.3.1
Collecting cryptography==2.3.1
  Downloading https://files.pythonhosted.org/packages/22/21/233e38f74188db94e8451ef6385754a98f3cad9b59bedf3a8e8b14988be4/cryptography-2.3.1.tar.gz (449kB)
    100% |████████████████████████████████| 450kB 7.7MB/s
Requirement already satisfied: idna>=2.1 in /usr/local/lib/python3.6/site-packages (from cryptography==2.3.1) (2.8)
Requirement already satisfied: asn1crypto>=0.21.0 in /usr/local/lib/python3.6/site-packages (from cryptography==2.3.1) (0.24.0)
Requirement already satisfied: six>=1.4.1 in /usr/local/lib/python3.6/site-packages (from cryptography==2.3.1) (1.12.0)
Requirement already satisfied: cffi!=1.11.3,>=1.7 in /usr/local/lib/python3.6/site-packages (from cryptography==2.3.1) (1.11.5)
Requirement already satisfied: pycparser in /usr/local/lib/python3.6/site-packages (from cffi!=1.11.3,>=1.7->cryptography==2.3.1) (2.19)
Building wheels for collected packages: cryptography
  Running setup.py bdist_wheel for cryptography ... error
  Complete output from command /usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-4jbcfj5a/cryptography/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-buy8z8vh --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.6
  creating build/lib.linux-x86_64-3.6/cryptography
  copying src/cryptography/__about__.py -> build/lib.linux-x86_64-3.6/cryptography
  copying src/cryptography/utils.py -> build/lib.linux-x86_64-3.6/cryptography
  copying src/cryptography/exceptions.py -> build/lib.linux-x86_64-3.6/cryptography
  copying src/cryptography/fernet.py -> build/lib.linux-x86_64-3.6/cryptography
  copying src/cryptography/__init__.py -> build/lib.linux-x86_64-3.6/cryptography
  creating build/lib.linux-x86_64-3.6/cryptography/hazmat
  copying src/cryptography/hazmat/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat
  creating build/lib.linux-x86_64-3.6/cryptography/x509
  copying src/cryptography/x509/base.py -> build/lib.linux-x86_64-3.6/cryptography/x509
  copying src/cryptography/x509/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/x509
  copying src/cryptography/x509/oid.py -> build/lib.linux-x86_64-3.6/cryptography/x509
  copying src/cryptography/x509/certificate_transparency.py -> build/lib.linux-x86_64-3.6/cryptography/x509
  copying src/cryptography/x509/name.py -> build/lib.linux-x86_64-3.6/cryptography/x509
  copying src/cryptography/x509/general_name.py -> build/lib.linux-x86_64-3.6/cryptography/x509
  copying src/cryptography/x509/extensions.py -> build/lib.linux-x86_64-3.6/cryptography/x509
  creating build/lib.linux-x86_64-3.6/cryptography/hazmat/bindings
  copying src/cryptography/hazmat/bindings/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/bindings
  creating build/lib.linux-x86_64-3.6/cryptography/hazmat/backends
  copying src/cryptography/hazmat/backends/interfaces.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends
  copying src/cryptography/hazmat/backends/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends
  creating build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/hashes.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/padding.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/constant_time.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/hmac.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/mac.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/serialization.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/keywrap.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
  copying src/cryptography/hazmat/primitives/cmac.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
  creating build/lib.linux-x86_64-3.6/cryptography/hazmat/bindings/openssl
  copying src/cryptography/hazmat/bindings/openssl/_conditional.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/bindings/openssl
  copying src/cryptography/hazmat/bindings/openssl/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/bindings/openssl
  copying src/cryptography/hazmat/bindings/openssl/binding.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/bindings/openssl
  creating build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/hashes.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/utils.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/ciphers.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/aead.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/rsa.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/x509.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/hmac.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/x25519.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/encode_asn1.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/dsa.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/ec.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/dh.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/backend.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/decode_asn1.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
  copying src/cryptography/hazmat/backends/openssl/cmac.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
  creating build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/kdf
  copying src/cryptography/hazmat/primitives/kdf/pbkdf2.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/kdf
  copying src/cryptography/hazmat/primitives/kdf/kbkdf.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/kdf
  copying src/cryptography/hazmat/primitives/kdf/hkdf.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/kdf
  copying src/cryptography/hazmat/primitives/kdf/concatkdf.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/kdf
  copying src/cryptography/hazmat/primitives/kdf/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/kdf
  copying src/cryptography/hazmat/primitives/kdf/scrypt.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/kdf
  copying src/cryptography/hazmat/primitives/kdf/x963kdf.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/kdf
  creating build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/twofactor
  copying src/cryptography/hazmat/primitives/twofactor/hotp.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/twofactor
  copying src/cryptography/hazmat/primitives/twofactor/utils.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/twofactor
  copying src/cryptography/hazmat/primitives/twofactor/totp.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/twofactor
  copying src/cryptography/hazmat/primitives/twofactor/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/twofactor
  creating build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/ciphers
  copying src/cryptography/hazmat/primitives/ciphers/base.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/ciphers
  copying src/cryptography/hazmat/primitives/ciphers/modes.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/ciphers
  copying src/cryptography/hazmat/primitives/ciphers/aead.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/ciphers
  copying src/cryptography/hazmat/primitives/ciphers/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/ciphers
  copying src/cryptography/hazmat/primitives/ciphers/algorithms.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/ciphers
  creating build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/utils.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/padding.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/rsa.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/x25519.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/dsa.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/ec.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/asymmetric
  copying src/cryptography/hazmat/primitives/asymmetric/dh.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/asymmetric
  running egg_info
  writing src/cryptography.egg-info/PKG-INFO
  writing dependency_links to src/cryptography.egg-info/dependency_links.txt
  writing requirements to src/cryptography.egg-info/requires.txt
  writing top-level names to src/cryptography.egg-info/top_level.txt
  reading manifest file 'src/cryptography.egg-info/SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  no previously-included directories found matching 'docs/_build'
  warning: no previously-included files matching '*' found under directory 'vectors'
  writing manifest file 'src/cryptography.egg-info/SOURCES.txt'
  running build_ext
  generating cffi module 'build/temp.linux-x86_64-3.6/_padding.c'
  creating build/temp.linux-x86_64-3.6
  generating cffi module 'build/temp.linux-x86_64-3.6/_constant_time.c'
  generating cffi module 'build/temp.linux-x86_64-3.6/_openssl.c'
  building '_openssl' extension
  creating build/temp.linux-x86_64-3.6/build
  creating build/temp.linux-x86_64-3.6/build/temp.linux-x86_64-3.6
  gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/local/include/python3.6m -c build/temp.linux-x86_64-3.6/_openssl.c -o build/temp.linux-x86_64-3.6/build/temp.linux-x86_64-3.6/_openssl.o -Wconversion -Wno-error=sign-conversion
  unable to execute 'gcc': No such file or directory
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for cryptography
  Running setup.py clean for cryptography
Failed to build cryptography
Installing collected packages: cryptography
  Running setup.py install for cryptography ... error
    Complete output from command /usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-4jbcfj5a/cryptography/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-0y_dtf3q/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/cryptography
    copying src/cryptography/__about__.py -> build/lib.linux-x86_64-3.6/cryptography
    copying src/cryptography/utils.py -> build/lib.linux-x86_64-3.6/cryptography
    copying src/cryptography/exceptions.py -> build/lib.linux-x86_64-3.6/cryptography
    copying src/cryptography/fernet.py -> build/lib.linux-x86_64-3.6/cryptography
    copying src/cryptography/__init__.py -> build/lib.linux-x86_64-3.6/cryptography
    creating build/lib.linux-x86_64-3.6/cryptography/hazmat
    copying src/cryptography/hazmat/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat
    creating build/lib.linux-x86_64-3.6/cryptography/x509
    copying src/cryptography/x509/base.py -> build/lib.linux-x86_64-3.6/cryptography/x509
    copying src/cryptography/x509/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/x509
    copying src/cryptography/x509/oid.py -> build/lib.linux-x86_64-3.6/cryptography/x509
    copying src/cryptography/x509/certificate_transparency.py -> build/lib.linux-x86_64-3.6/cryptography/x509
    copying src/cryptography/x509/name.py -> build/lib.linux-x86_64-3.6/cryptography/x509
    copying src/cryptography/x509/general_name.py -> build/lib.linux-x86_64-3.6/cryptography/x509
    copying src/cryptography/x509/extensions.py -> build/lib.linux-x86_64-3.6/cryptography/x509
    creating build/lib.linux-x86_64-3.6/cryptography/hazmat/bindings
    copying src/cryptography/hazmat/bindings/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/bindings
    creating build/lib.linux-x86_64-3.6/cryptography/hazmat/backends
    copying src/cryptography/hazmat/backends/interfaces.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends
    copying src/cryptography/hazmat/backends/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends
    creating build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
    copying src/cryptography/hazmat/primitives/hashes.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
    copying src/cryptography/hazmat/primitives/padding.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
    copying src/cryptography/hazmat/primitives/constant_time.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
    copying src/cryptography/hazmat/primitives/hmac.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
    copying src/cryptography/hazmat/primitives/mac.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
    copying src/cryptography/hazmat/primitives/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
    copying src/cryptography/hazmat/primitives/serialization.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
    copying src/cryptography/hazmat/primitives/keywrap.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
    copying src/cryptography/hazmat/primitives/cmac.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives
    creating build/lib.linux-x86_64-3.6/cryptography/hazmat/bindings/openssl
    copying src/cryptography/hazmat/bindings/openssl/_conditional.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/bindings/openssl
    copying src/cryptography/hazmat/bindings/openssl/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/bindings/openssl
    copying src/cryptography/hazmat/bindings/openssl/binding.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/bindings/openssl
    creating build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
    copying src/cryptography/hazmat/backends/openssl/hashes.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
    copying src/cryptography/hazmat/backends/openssl/utils.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
    copying src/cryptography/hazmat/backends/openssl/ciphers.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
    copying src/cryptography/hazmat/backends/openssl/aead.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
    copying src/cryptography/hazmat/backends/openssl/rsa.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
    copying src/cryptography/hazmat/backends/openssl/x509.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
    copying src/cryptography/hazmat/backends/openssl/hmac.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
    copying src/cryptography/hazmat/backends/openssl/x25519.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
    copying src/cryptography/hazmat/backends/openssl/encode_asn1.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
    copying src/cryptography/hazmat/backends/openssl/dsa.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
    copying src/cryptography/hazmat/backends/openssl/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
    copying src/cryptography/hazmat/backends/openssl/ec.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
    copying src/cryptography/hazmat/backends/openssl/dh.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
    copying src/cryptography/hazmat/backends/openssl/backend.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
    copying src/cryptography/hazmat/backends/openssl/decode_asn1.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
    copying src/cryptography/hazmat/backends/openssl/cmac.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/backends/openssl
    creating build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/kdf
    copying src/cryptography/hazmat/primitives/kdf/pbkdf2.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/kdf
    copying src/cryptography/hazmat/primitives/kdf/kbkdf.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/kdf
    copying src/cryptography/hazmat/primitives/kdf/hkdf.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/kdf
    copying src/cryptography/hazmat/primitives/kdf/concatkdf.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/kdf
    copying src/cryptography/hazmat/primitives/kdf/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/kdf
    copying src/cryptography/hazmat/primitives/kdf/scrypt.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/kdf
    copying src/cryptography/hazmat/primitives/kdf/x963kdf.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/kdf
    creating build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/twofactor
    copying src/cryptography/hazmat/primitives/twofactor/hotp.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/twofactor
    copying src/cryptography/hazmat/primitives/twofactor/utils.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/twofactor
    copying src/cryptography/hazmat/primitives/twofactor/totp.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/twofactor
    copying src/cryptography/hazmat/primitives/twofactor/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/twofactor
    creating build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/ciphers
    copying src/cryptography/hazmat/primitives/ciphers/base.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/ciphers
    copying src/cryptography/hazmat/primitives/ciphers/modes.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/ciphers
    copying src/cryptography/hazmat/primitives/ciphers/aead.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/ciphers
    copying src/cryptography/hazmat/primitives/ciphers/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/ciphers
    copying src/cryptography/hazmat/primitives/ciphers/algorithms.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/ciphers
    creating build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/asymmetric
    copying src/cryptography/hazmat/primitives/asymmetric/utils.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/asymmetric
    copying src/cryptography/hazmat/primitives/asymmetric/padding.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/asymmetric
    copying src/cryptography/hazmat/primitives/asymmetric/rsa.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/asymmetric
    copying src/cryptography/hazmat/primitives/asymmetric/x25519.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/asymmetric
    copying src/cryptography/hazmat/primitives/asymmetric/dsa.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/asymmetric
    copying src/cryptography/hazmat/primitives/asymmetric/__init__.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/asymmetric
    copying src/cryptography/hazmat/primitives/asymmetric/ec.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/asymmetric
    copying src/cryptography/hazmat/primitives/asymmetric/dh.py -> build/lib.linux-x86_64-3.6/cryptography/hazmat/primitives/asymmetric
    running egg_info
    writing src/cryptography.egg-info/PKG-INFO
    writing dependency_links to src/cryptography.egg-info/dependency_links.txt
    writing requirements to src/cryptography.egg-info/requires.txt
    writing top-level names to src/cryptography.egg-info/top_level.txt
    reading manifest file 'src/cryptography.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    no previously-included directories found matching 'docs/_build'
    warning: no previously-included files matching '*' found under directory 'vectors'
    writing manifest file 'src/cryptography.egg-info/SOURCES.txt'
    running build_ext
    generating cffi module 'build/temp.linux-x86_64-3.6/_padding.c'
    creating build/temp.linux-x86_64-3.6
    generating cffi module 'build/temp.linux-x86_64-3.6/_constant_time.c'
    generating cffi module 'build/temp.linux-x86_64-3.6/_openssl.c'
    building '_openssl' extension
    creating build/temp.linux-x86_64-3.6/build
    creating build/temp.linux-x86_64-3.6/build/temp.linux-x86_64-3.6
    gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/local/include/python3.6m -c build/temp.linux-x86_64-3.6/_openssl.c -o build/temp.linux-x86_64-3.6/build/temp.linux-x86_64-3.6/_openssl.o -Wconversion -Wno-error=sign-conversion
    unable to execute 'gcc': No such file or directory
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-4jbcfj5a/cryptography/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-0y_dtf3q/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-4jbcfj5a/cryptography/

Thanks for the tip...I learn new things every day :-D

Ah it looks like for whatever reason this environment doesn’t have wheel support.

Try ‘pip install wheel’ (haven’t figured out backticks on my phone) then the pip install cryptography command (with the version)

@Jc2k

bash-4.4# pip install wheel
Requirement already satisfied: wheel in /usr/local/lib/python3.6/site-packages (0.32.0)
You are using pip version 18.0, however version 19.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
bash-4.4# pip uninstall wheel
Uninstalling wheel-0.32.0:
  Would remove:
    /usr/local/bin/wheel
    /usr/local/lib/python3.6/site-packages/wheel-0.32.0.dist-info/*
    /usr/local/lib/python3.6/site-packages/wheel/*
Proceed (y/n)? y
  Successfully uninstalled wheel-0.32.0
You are using pip version 18.0, however version 19.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
bash-4.4# pip install wheel
Collecting wheel
  Using cached https://files.pythonhosted.org/packages/ff/47/1dfa4795e24fd6f93d5d58602dd716c3f101cfd5a77cd9acbe519b44a0a9/wheel-0.32.3-py2.py3-none-any.whl
Installing collected packages: wheel
Successfully installed wheel-0.32.3

It still comes with same error after uninstall/install wheel

So after installing wheel if you install cryptography it still downloads a .tar.gz instead of a .whl?

yes it downloads a tar.gz when you install cryptography

bash-4.4# pip install wheel
Collecting wheel
  Using cached https://files.pythonhosted.org/packages/ff/47/1dfa4795e24fd6f93d5d58602dd716c3f101cfd5a77cd9acbe519b44a0a9/wheel-0.32.3-py2.py3-none-any.whl
Installing collected packages: wheel
Successfully installed wheel-0.32.3
You are using pip version 18.0, however version 19.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
bash-4.4# pip uninstall cryptography
Uninstalling cryptography-2.3.1:
  Would remove:
    /usr/local/lib/python3.6/site-packages/cryptography-2.3.1-py3.6.egg-info
    /usr/local/lib/python3.6/site-packages/cryptography/*
Proceed (y/n)? y
  Successfully uninstalled cryptography-2.3.1
You are using pip version 18.0, however version 19.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
bash-4.4# pip install cryptography==2.3.1
Collecting cryptography==2.3.1
  Downloading https://files.pythonhosted.org/packages/22/21/233e38f74188db94e8451ef6385754a98f3cad9b59bedf3a8e8b14988be4/cryptography-2.3.1.tar.gz (449kB)
    100% |████████████████████████████████| 450kB 12.6MB/s
Requirement already satisfied: idna>=2.1 in /usr/local/lib/python3.6/site-packages (from cryptography==2.3.1) (2.8)
Requirement already satisfied: asn1crypto>=0.21.0 in /usr/local/lib/python3.6/site-packages (from cryptography==2.3.1) (0.24.0)
Requirement already satisfied: six>=1.4.1 in /usr/local/lib/python3.6/site-packages (from cryptography==2.3.1) (1.12.0)
Requirement already satisfied: cffi!=1.11.3,>=1.7 in /usr/local/lib/python3.6/site-packages (from cryptography==2.3.1) (1.11.5)
Requirement already satisfied: pycparser in /usr/local/lib/python3.6/site-packages (from cffi!=1.11.3,>=1.7->cryptography==2.3.1) (2.19)
Building wheels for collected packages: cryptography
  Running setup.py bdist_wheel for cryptography ... error
  Complete output from command /usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-6hebk6hy/cryptography/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-terfvc9y --python-tag cp36:

So I need to know how to get a system like this to test on. Is this inside a Docker container? What image? You mentioned Ubuntu - is that the host? Is it 18.04? Your vm layer shouldn’t matter.

Yes its the host im running on now - Ubuntu 18.04 Server

http://releases.ubuntu.com/18.04.1.0/ubuntu-18.04.1.0-live-server-amd64.iso?_ga=2.189575976.261634082.1548233321-1630654955.1548233321

After that i installed with this script:

curl -sL https://bit.ly/2yEElES | bash -

And moved my configuration from my old hyper-V who run Hassio own image to Ubuntu 18.04 - Both running docker :-)

As a virtual appliance:

VMDK (VMWare Workstation)
VHDX (beta) <--- My old image with same problem
VDI (beta)
OVA (not available at this time!)

And the pip commands i've been asking you to run - thats inside a Docker container that this script creates?

yes

Ok thanks - now I have enough to recreate this on my end:

>>> from cryptography.hazmat.primitives.asymmetric import x25519
>>> x25519.X25519PrivateKey.generate().public_key().public_bytes()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/cryptography/hazmat/primitives/asymmetric/x25519.py", line 39, in generate
    _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM
cryptography.exceptions.UnsupportedAlgorithm: X25519 is not supported by this version of OpenSSL.

This has been a bit of a pain to figure out and i'm afraid I don't have especially good news.

Recap:

homekit_python has switched to cryptography for its x25519 implementation because its supported (active security team, regular releases, unlike old library which has had no activity in years) and because its easy to install on the homeassistant CI. It's actually much easier to install on all of the environments that were tested. The code that makes this work has been out there since 2016, worked with the homeassistant docker image, worked on stretch, worked on bionic, worked on raspbian on a Pi from 2011, even worked on macs. Win all round.

There are 2 ways for the cryptography installation to work:

  • Install the wheel - it has a new enough version of ssl baked into it (a so called manylinux1 wheel). Upstream ship wheels for amd64 and i386 linux platforms, macos and even windows. The raspberry pi team ship wheels for Raspbian via piwheels.org.
  • Run on a distro that has openssl 1.1.0 or higher (which was released August 2016) such as Ubuntu 18.04 or Debian Squeeze.

pip will always use the wheel if it can, so either wheel support is broken in that distro or pip doesnt think it is manylinux1 compatible.

manylinux1 tries to define a common minimum. A manylinux1 wheel is built in a RHEL5 (centos, technically) Docker container. The idea is that using a 2007 (yes, 2007) era build environment should maximise the number of platforms a manylinux1 wheel runs on. So pretty much any supported glibc based Linux distribution should run a manylinux1 wheel.

Ok - the official homeassistant container i'm using is homeassistant/home-assistant. It's based on Debian, and thats where the wheels just work. It's Debian stretch, so if they didn't I could use an sdist and it work work.

HASS.io is something different. It installs a container homeassistant/qemux86-64-homeassistant. This is based on alpine3.8, not Debian. Crucially alpine uses musl libc, not glibc. I think we can start to see now where this is going.

Looking inside the container, cryptrography 2.3.1 is preinstalled, and its preinstalled as an egg not a wheel. This is expected because its based on alpine it can't actually use python manylinux1 wheels. It has to use sdists. The cryptography wheel ships with all its dependencies inside it. A sdist installation relies on the host to provide its dependencies.

/usr/local/lib/python3.6/site-packages/cryptography/hazmat/bindings # ldd _openssl.abi3.so 
    ldd (0x7f56a91f3000)
    libssl.so.45 => /lib/libssl.so.45 (0x7f56a8cdd000)
    libcrypto.so.43 => /lib/libcrypto.so.43 (0x7f56a8932000)
    libpython3.6m.so.1.0 => /usr/local/lib/libpython3.6m.so.1.0 (0x7f56a83f9000)
    libc.musl-x86_64.so.1 => ldd (0x7f56a91f3000)

^ The sdist package relies on alpine to provide a libssl that is build correctly.

Alpine 3.8 has openssl 1.0.x. This is an LTS release so it gets security updates, but not for much longer (Alpine has 11 months to stop using it). Alas it does not get new features such as X25519 that have existed since 2016 in openssl 1.1.x. 1.1.x is what you need for things to work again.

There is some cause for optimism. A large number of Docker containers use alpine, and if they want TLS 1.3 support they will need to upgrade openssl. The edge release of Alpine linux already has a good enough version of openssl. Alpine has a 6 month release cycle. Accord to this:

  • Their last release was 26 June 2018
  • A release is just a snapshot of edge

So edge has openssl 1.1.1 and if they are going to take a snapshot of it soon then it will have the right version. (Here is them tagging RC3 of 3.9, i poked around in their Git and found its the right version). So hopefully this will be resolved soon in Alpine.

TL;DR. When HASS moves to alpine v3.9 (which should be out any day now, I have no idea how long HASS will take to move to it) it should work. In the mean time, you need to use the homeassistant Docker image directly or on bare Ubuntu 18.04/Debian Stretch/Raspbian.

@Jc2k That was one of the best github issue posts I've ever read. So much good info! Thanks for the awesome support!

@MartinHjelmare thanks :) I just want to get the homekit_controller stuff into the best shape I can ready for my BLE patches :-)

@Jc2k Thank you for the great effort :-D
do you know if there will be other problems running homeassistant Docker image directly instead of qemux86-64-homeassistant when it automatic choose it for the installation?

or else will my solution be running it on a bare ubuntu to check the changes :-)

@Jc2k i works with the homeassistant/home-assistant also with updated to homekit==0.12.2 👍
but still with timeout errors. but they should still be there right ?

@bncbnc83 yep - there are some extra tweaks in the pull request that was just merged on top of upgrading to 0.12.2 that deal with the errors on the homeassistant side. So when the dev branch of HA is released the errors should fully go away.

Re: Docker images - i used homeassistant/home-assistant for my environment without any problems. It's a VM on an ESX server running Ubuntu 18.04 as the host. I don't know what other changes are in the qemux one.

Thank you :-)

I removed hassio and just used homeassistant/home-assistant.
Thank you for big commitment and support👍

Issues still there with 0.8.6 😞

@dave-castle my pr was merged after the release process started unfortunately. It might be 0.87 before it’s in a release.

After I upgrade my hassio to .86.2 I am getting this error

Fri Jan 25 2019 23:22:49 GMT-0600 (CST)

homekit_controller: Error on device update!
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 248, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 203, in update
    pairing = self._accessory.pairing
AttributeError: 'HKDevice' object has no attribute 'pairing'

How can I do please I need help.

@NDNELSON Hi - are there any other errors in your log related to homekit_controller? Can you please confirm that you have removed the custom component you created earlier in this thread? (https://github.com/home-assistant/home-assistant/issues/18949#issuecomment-444341751)

Looking at the current code a HKDevice will always have a pairing attribute (it is set during __init__, if it failed then the HKDevice would error instead of being created).

So the only thing I can think of is if you restarted HA from within the web interface and this is some weird artificat of that OR there is conflicting code in your environment somehow.

Do I have to remove my Custom component?

If you have the custom homekit_controller described earlier in this ticket here - yes you do.

That custom component is essentially causing 2 versions of homekit_controller code to be loaded at once. You are using the HKDevice from December but HomeKitEntity is getting pulled in from 0.86.2. which would explain your pairing attribute issue.

Ok I will try it and give you a response a bout my issue thanks

I just noticed you are using hass.io - if you have a hass.io setup like the one earlier in the thread (that uses Docker containers based on Alpine 3.8) it will probably still not work. There isn't a fix for that right now, using the homeassistant Docker install works though (home-assistant/home-assistant). See this comment in particular.

And how do I know if my hassio uses Docker containers based on Alpine 3.8?

I'm just a fellow user trying to make homekit_controller work so I only know how my homeassistant is set up. My live setup uses the Docker container homeassistant/home-assistant and that works. If you use homeassistant/qemux86-64-homeassistant (has Alpine, has too old openssl). I know that won't work thanks to others in this thread. If you don't use Docker and installed it on Debian Stretch or Ubuntu 18.04 that will also work.

FWIW, I have also tested the underlying homekit library on a Raspberry Pi from 2011 with latest Rasbpian and it works there, but haven't done a homeassistant install there.

I’m running in a raspberry pi 3 image download in home assistant oficial page and burn in sd with etcher

I suspect that will have the issue too, but i've not used it myself.

I will try it because it worked before upgrade hassio from .84 to .86

I've raised a bug in HASS.io to try and get the dependency issue solved (https://github.com/home-assistant/hassio/issues/903).

I don't really understand a lot of what @Jc2k is saying.
So as a noob running Hass.io on a RPi2, I will basically just have to wait and hope that hass.io gets updated to use "alpine v3.9"?

Its working again . Just remove Developer Custom file . Thanks for the support!

Alpine Linux v3.9 is now official: https://alpinelinux.org/posts/Alpine-3.9.0-released.html

The Docker tag is also updated. Hope the team uses it soon 😢

Thank god! 🎂

I think I'm having the same issue but with ihome outlet isp5. This is within my hass.io setup. My isp5 controller is connected to HA and I can control it there, but it doesn't get forwarded back to homekit on my iphone so I can't control it with the home app/SIRI. I can't even find the site-packages/homeassisant folder from within the HASS configurator...doesn't exist.

>  Update for switch.isp5 fails
> Traceback (most recent call last):
>   File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
>     await self.async_device_update()
>   File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update
>     await self.hass.async_add_executor_job(self.update)
>   File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
>     result = self.fn(*self.args, **self.kwargs)
>   File "/usr/local/lib/python3.6/site-packages/homeassistant/components/homekit_controller/__init__.py", line 204, in update
>     data = pairing.list_accessories_and_characteristics()
>   File "/usr/local/lib/python3.6/site-packages/homekit/controller.py", line 273, in list_accessories_and_characteristics
>     response = self.session.get('/accessories')
>   File "/usr/local/lib/python3.6/site-packages/homekit/controller.py", line 573, in get
>     return self.sec_http.get(url)
>   File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 65, in get
>     return self._handle_request(data)
>   File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 89, in _handle_request
>     return self._read_response()
>   File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/secure_http.py", line 154, in _read_response
>     response.parse(decrypted)
>   File "/usr/local/lib/python3.6/site-packages/homekit/http_impl/response.py", line 38, in parse
>     self._raw_response += part
> TypeError: can't concat bool to bytearray"

@Jc2k do you have eny idea why it does not discover koogeek after upgrade to 0.94.3
When i make a downgrade to 0.93.2 home assistant finds them again ?

@bncbnc83 got two koogeek plugs and got no problems currently. is discovery for homekit enabled in your configuration? if so, you may delete it as homekit auto discovery is implemented now

@dave-castle yes it was enabled. but i also tryed to remove it as stated in the error log.
But it made no difference.

Specifically you have to have zeroconf enabled not discovery - see the release notes about how HA is deprecating the discovery module

Was this page helpful?
0 / 5 - 0 ratings

Related issues

missedtheapex picture missedtheapex  ·  3Comments

Konstigt picture Konstigt  ·  3Comments

flsabourin picture flsabourin  ·  3Comments

arangates picture arangates  ·  3Comments

coolriku picture coolriku  ·  3Comments