klali / ha-plejd

Plejd component for Home Assistant
Apache License 2.0
70 stars 17 forks source link

Frequently disconnecting #15

Closed iCarl closed 5 years ago

iCarl commented 5 years ago

Plejd has been disconnecting for a few couple of days.

The most recent log when this was happening is:

2019-08-25 17:25:54 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall light.turn_on (c:7a0c4081cef146499bf7ef7d07116164): entity_id=['light.badrum']>
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 1159, in _safe_execute
    await self._execute_service(handler, service_call)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 1172, in _execute_service
    await handler.func(service_call)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/light/__init__.py", line 295, in async_handle_light_on_service
    await light.async_turn_on(**pars)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/plejd/light.py", line 109, in turn_on
    plejd_write(pi, pi["handles"]["data"], plejd_enc_dec(pi["key"], pi["address"], payload))
  File "/home/homeassistant/.homeassistant/custom_components/plejd/light.py", line 292, in plejd_write
    pi["device"].writeCharacteristic(handle, data, wait)
  File "/srv/homeassistant/lib/python3.5/site-packages/bluepy/btle.py", line 543, in writeCharacteristic
    return self._getResp('wr')
  File "/srv/homeassistant/lib/python3.5/site-packages/bluepy/btle.py", line 407, in _getResp
    resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
  File "/srv/homeassistant/lib/python3.5/site-packages/bluepy/btle.py", line 338, in _waitResp
    if self._helper.poll() is not None:
AttributeError: 'NoneType' object has no attribute 'poll'
2019-08-25 17:25:54 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall light.turn_on (c:6ecba558a72946fca5eecd53887657b3): entity_id=['light.badrum']>
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 1159, in _safe_execute
    await self._execute_service(handler, service_call)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 1172, in _execute_service
    await handler.func(service_call)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/light/__init__.py", line 295, in async_handle_light_on_service
    await light.async_turn_on(**pars)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/plejd/light.py", line 109, in turn_on
    plejd_write(pi, pi["handles"]["data"], plejd_enc_dec(pi["key"], pi["address"], payload))
  File "/home/homeassistant/.homeassistant/custom_components/plejd/light.py", line 292, in plejd_write
    pi["device"].writeCharacteristic(handle, data, wait)
  File "/srv/homeassistant/lib/python3.5/site-packages/bluepy/btle.py", line 543, in writeCharacteristic
    return self._getResp('wr')
  File "/srv/homeassistant/lib/python3.5/site-packages/bluepy/btle.py", line 407, in _getResp
    resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
  File "/srv/homeassistant/lib/python3.5/site-packages/bluepy/btle.py", line 338, in _waitResp
    if self._helper.poll() is not None:
AttributeError: 'NoneType' object has no attribute 'poll'
2019-08-25 17:25:54 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall light.turn_on (c:e471a4254e5341fb83c49a7dafca3ff6): entity_id=['light.badrum']>
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 1159, in _safe_execute
    await self._execute_service(handler, service_call)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 1172, in _execute_service
    await handler.func(service_call)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/light/__init__.py", line 295, in async_handle_light_on_service
    await light.async_turn_on(**pars)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/plejd/light.py", line 109, in turn_on
    plejd_write(pi, pi["handles"]["data"], plejd_enc_dec(pi["key"], pi["address"], payload))
  File "/home/homeassistant/.homeassistant/custom_components/plejd/light.py", line 292, in plejd_write
    pi["device"].writeCharacteristic(handle, data, wait)
  File "/srv/homeassistant/lib/python3.5/site-packages/bluepy/btle.py", line 543, in writeCharacteristic
    return self._getResp('wr')
  File "/srv/homeassistant/lib/python3.5/site-packages/bluepy/btle.py", line 407, in _getResp
    resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
  File "/srv/homeassistant/lib/python3.5/site-packages/bluepy/btle.py", line 338, in _waitResp
    if self._helper.poll() is not None:
AttributeError: 'NoneType' object has no attribute 'poll'
2019-08-25 17:25:54 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall light.turn_on (c:3a53b9e1c0e54288970c9fb6421773ce): entity_id=['light.badrum']>
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 1159, in _safe_execute
    await self._execute_service(handler, service_call)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 1172, in _execute_service
    await handler.func(service_call)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/light/__init__.py", line 295, in async_handle_light_on_service
    await light.async_turn_on(**pars)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/plejd/light.py", line 109, in turn_on
    plejd_write(pi, pi["handles"]["data"], plejd_enc_dec(pi["key"], pi["address"], payload))
  File "/home/homeassistant/.homeassistant/custom_components/plejd/light.py", line 292, in plejd_write
    pi["device"].writeCharacteristic(handle, data, wait)
  File "/srv/homeassistant/lib/python3.5/site-packages/bluepy/btle.py", line 543, in writeCharacteristic
    return self._getResp('wr')
  File "/srv/homeassistant/lib/python3.5/site-packages/bluepy/btle.py", line 407, in _getResp
    resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
  File "/srv/homeassistant/lib/python3.5/site-packages/bluepy/btle.py", line 338, in _waitResp
    if self._helper.poll() is not None:
AttributeError: 'NoneType' object has no attribute 'poll'
2019-08-25 17:25:56 WARNING (Thread-2) [custom_components.plejd.light] failed connecting to device '***MAC-adress***' : 'Failed to connect to peripheral ***MAC-adress***, addr type: random'
2019-08-25 17:25:56 WARNING (Thread-2) [custom_components.plejd.light] no device found on iteration 1
2019-08-25 17:25:58 WARNING (Thread-2) [custom_components.plejd.light] failed connecting to device '***MAC-adress***' : 'Failed to connect to peripheral ***MAC-adress***, addr type: random'
2019-08-25 17:25:58 WARNING (Thread-2) [custom_components.plejd.light] no device found on iteration 2
2019-08-25 17:25:59 WARNING (Thread-2) [custom_components.plejd.light] failed connecting to device '***MAC-adress***' : 'Failed to connect to peripheral ***MAC-adress***, addr type: random'
2019-08-25 17:25:59 WARNING (Thread-2) [custom_components.plejd.light] no device found on iteration 3
2019-08-25 17:26:01 WARNING (Thread-2) [custom_components.plejd.light] failed connecting to device '***MAC-adress***' : 'Failed to connect to peripheral ***MAC-adress***, addr type: random'
2019-08-25 17:26:01 WARNING (Thread-2) [custom_components.plejd.light] no device found on iteration 4
2019-08-25 17:26:03 WARNING (Thread-2) [custom_components.plejd.light] failed connecting to device '***MAC-adress***' : 'Failed to connect to peripheral ***MAC-adress***, addr type: random'
2019-08-25 17:26:03 WARNING (Thread-2) [custom_components.plejd.light] no device found on iteration 5
2019-08-25 17:26:05 WARNING (Thread-2) [custom_components.plejd.light] failed connecting to device '***MAC-adress***' : 'Failed to connect to peripheral ***MAC-adress***, addr type: random'
2019-08-25 17:26:05 WARNING (Thread-2) [custom_components.plejd.light] no device found on iteration 6
2019-08-25 17:26:07 WARNING (Thread-2) [custom_components.plejd.light] failed connecting to device '***MAC-adress***' : 'Failed to connect to peripheral ***MAC-adress***, addr type: random'
2019-08-25 17:26:07 WARNING (Thread-2) [custom_components.plejd.light] no device found on iteration 7
2019-08-25 17:26:09 WARNING (Thread-2) [custom_components.plejd.light] failed connecting to device '***MAC-adress***' : 'Failed to connect to peripheral ***MAC-adress***, addr type: random'
2019-08-25 17:26:09 WARNING (Thread-2) [custom_components.plejd.light] no device found on iteration 8

It won't always reconnect, bud it did this time, What could be the cause?

klali commented 5 years ago

bluepy leaves things to be desired.. Could you try adding AttributeError to the errors caught on line 293 ?

When it goes through the failed connecting steps, is it always the same mac adress? What range do you have from where you're running this to the closest plejd? Could you try to run it closer (to several of them?)

iCarl commented 5 years ago

In this house I just have a Plejd CTR-01. It's about 2 meters and a wall between the Plejd and my Pi 3B.

klali commented 5 years ago

Any effect by trying to catch that AttributeError ?

iCarl commented 5 years ago

It reconnects nicely, but sometimes it still won’t respond.

iCarl commented 5 years ago

Seems to be solved since your with the last update and with the addition on line 293. Works great!

klali commented 5 years ago

So running with catching the AttributeError as well on line 293? I wonder if that's needed, do you get log lines with "Write failed: AttributeError" or similar?

iCarl commented 5 years ago

No it doesn't. But it seems to reconnect more often, it might just be my imagination.