home-assistant / core

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

BT issues when device tracking and polling other devices. #19760

Closed hitokiri8x closed 5 years ago

hitokiri8x commented 5 years ago

Home Assistant release with the issue: 0.84.6

Last working Home Assistant release (if known): maybe none

Operating environment (Hass.io/Docker/Windows/etc.): raspbian installation on RPi 2 b+ with BT dongle ( asus BT-400 ) all step to run bt stack as home-assistant user are done

Component/platform: https://www.home-assistant.io/components/device_tracker.bluetooth_le_tracker/ and https://www.home-assistant.io/components/sensor.mitemp_bt/

Description of problem: when activating both of the 2 components the devices tracking feature stops to work ( reporting only for the firsts scan present then always no-presence ), running just one of them works flawlessy:

Traceback (if applicable):

2019-01-04 08:52:49 ERROR (Thread-18) [pygatt.backends.gatttool.gatttool] Unexpected error when scanning: LE Scan ...
11:11:11:11:11:11 (unknown)
11:11:11:11:11:11 [AV] Soggiorno
22:22:22:22:22:22 (unknown)
22:22:22:22:22:22 (unknown)
33:33:33:33:33:33 (unknown)
33:33:33:33:33:33 (unknown)
44:44:44:44:44:44 (unknown)
44:44:44:44:44:44(unknown)
55:55:55:55:55:55 (unknown)
55:55:55:55:55:55 (unknown)
66:66:66:66:66:66 MJ_HT_V1
66:66:66:66:66:66 (unknown)
4C:65:A8:DA:83:41 (unknown)
Disable scan failed: Input/output error

2019-01-04 08:52:56 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.sensore_temperature is taking over 10 seconds
2019-01-04 08:54:09 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/pexpect/spawnbase.py", line 166, in read_nonblocking
    s = os.read(self.child_fd, size)
OSError: [Errno 5] Input/output error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/pexpect/expect.py", line 111, in expect_loop
    incoming = spawn.read_nonblocking(spawn.maxread, timeout)
  File "/srv/homeassistant/lib/python3.5/site-packages/pexpect/pty_spawn.py", line 485, in read_nonblocking
    return super(spawn, self).read_nonblocking(size)
  File "/srv/homeassistant/lib/python3.5/site-packages/pexpect/spawnbase.py", line 171, in read_nonblocking
    raise EOF('End Of File (EOF). Exception style platform.')
pexpect.exceptions.EOF: End Of File (EOF). Exception style platform.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/pygatt/backends/gatttool/gatttool.py", line 315, in scan
    scan.expect('foooooo', timeout=timeout)
  File "/srv/homeassistant/lib/python3.5/site-packages/pexpect/spawnbase.py", line 341, in expect
    timeout, searchwindowsize, async_)
  File "/srv/homeassistant/lib/python3.5/site-packages/pexpect/spawnbase.py", line 369, in expect_list
    return exp.expect_loop(timeout)
  File "/srv/homeassistant/lib/python3.5/site-packages/pexpect/expect.py", line 117, in expect_loop
    return self.eof(e)
  File "/srv/homeassistant/lib/python3.5/site-packages/pexpect/expect.py", line 63, in eof
    raise EOF(msg)
pexpect.exceptions.EOF: End Of File (EOF). Exception style platform.
<pexpect.pty_spawn.spawn object at 0x66865550>
command: /usr/bin/hcitool
args: ['/usr/bin/hcitool', '-i', 'hci0', 'lescan']
buffer (last 100 chars): b''
before (last 100 chars): b'\r\n66:66:66:66:66:66 MJ_HT_V1\r\n66:66:66:66:66:66  (unknown)\r\nDisable scan failed: Input/output error\r\n'
after: <class 'pexpect.exceptions.EOF'>
match: None
match_index: None
exitstatus: 1
flag_eof: True
pid: 7684
child_fd: 23
closed: False
timeout: 30
delimiter: <class 'pexpect.exceptions.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
searcher: searcher_re:
    0: re.compile(b'foooooo')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/bluetooth_le_tracker.py", line 96, in update_ble
    devs = discover_ble_devices()
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/bluetooth_le_tracker.py", line 58, in discover_ble_devices
    devs = adapter.scan()
  File "/srv/homeassistant/lib/python3.5/site-packages/pygatt/backends/gatttool/gatttool.py", line 326, in scan
    raise BLEError(message)
pygatt.exceptions.BLEError: Unexpected error when scanning: LE Scan ...
11:11:11:11:11:11 (unknown)
11:11:11:11:11:11 [AV] Soggiorno
22:22:22:22:22:22 (unknown)
22:22:22:22:22:22 (unknown)
33:33:33:33:33:33 (unknown)
33:33:33:33:33:33 (unknown)
44:44:44:44:44:44 (unknown)
44:44:44:44:44:44(unknown)
55:55:55:55:55:55 (unknown)
55:55:55:55:55:55 (unknown)
66:66:66:66:66:66 MJ_HT_V1
66:66:66:66:66:66 (unknown)
Disable scan failed: Input/output error

2019-01-04 09:14:07 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.sensore_humidity is taking over 10 seconds
2019-01-04 09:30:44 ERROR (MainThread) [aiohttp.access] Error in logging
Traceback (most recent call last):
  File "aiohttp\_helpers.pyx", line 24, in aiohttp._helpers.reify.__get__
KeyError: 'remote'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/aiohttp/helpers.py", line 462, in log
    for key, value in fmt_info:
  File "/srv/homeassistant/lib/python3.5/site-packages/aiohttp/helpers.py", line 454, in <genexpr>
    for key, method in self._methods)
  File "/srv/homeassistant/lib/python3.5/site-packages/aiohttp/helpers.py", line 412, in _format_a
    ip = request.remote
  File "aiohttp\_helpers.pyx", line 32, in aiohttp._helpers.reify.__get__
  File "aiohttp\_helpers.pyx", line 26, in aiohttp._helpers.reify.__get__
  File "/srv/homeassistant/lib/python3.5/site-packages/aiohttp/web_request.py", line 343, in remote
    peername = self.transport.get_extra_info('peername')
  File "/usr/lib/python3.5/asyncio/sslproto.py", line 306, in get_extra_info
    return self._ssl_protocol._get_extra_info(name, default)
  File "/usr/lib/python3.5/asyncio/sslproto.py", line 546, in _get_extra_info
    return self._transport.get_extra_info(name, default)
AttributeError: 'NoneType' object has no attribute 'get_extra_info'
2019-01-04 09:41:55 ERROR (MainThread) [homeassistant.components.updater] Got unexpected response: None

Additional information:

I think the problem is due bt locks: device bt le tracke start to search for devices with gattools ( and waiting for 10seconds), meanwhile xiaomi temperature component with btlewrap.base try to access bt, and close the other connection. Running hcitools lescan somethimes also replay the same case: "Disable scan failed: Input/output error".

maybe related to #19592 and #19406

dannyb78 commented 5 years ago

same problem here. I also use a xiaomi BT sensor and BLE scan.