Skip to content

Commit

Permalink
add minimum BT reset time
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernst79 committed Dec 30, 2021
1 parent eb72ae0 commit d1ac420
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
40 changes: 24 additions & 16 deletions custom_components/ble_monitor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from homeassistant.helpers.entity_registry import (
async_entries_for_device,
)
import homeassistant.util.dt as dt_util

from .ble_parser import BleParser
from .const import (
Expand Down Expand Up @@ -496,6 +497,7 @@ def __init__(self, config, dataqueue):
self.sensor_whitelist = []
self.tracker_whitelist = []
self.report_unknown = False
self.last_bt_reset = dt_util.now()
if self.config[CONF_REPORT_UNKNOWN]:
self.report_unknown = self.config[CONF_REPORT_UNKNOWN]
_LOGGER.info(
Expand Down Expand Up @@ -609,14 +611,17 @@ def run(self):
btctrl[hci].send_scan_request(self._active)
)
except RuntimeError as error:
if CONF_BT_AUTO_RESTART:
_LOGGER.error(
"HCIdump thread: Runtime error while sending scan request on hci%i: %s. Resetting Bluetooth adapter %s and trying again.",
hci,
error,
BT_INTERFACES[hci],
)
reset_bluetooth(hci)
if CONF_BT_AUTO_RESTART is True:
ts_now = dt_util.now()
if ts_now - self.last_bt_reset > 60:
_LOGGER.error(
"HCIdump thread: Runtime error while sending scan request on hci%i: %s. Resetting Bluetooth adapter %s and trying again.",
hci,
error,
BT_INTERFACES[hci],
)
reset_bluetooth(hci)
self.last_bt_reset = ts_now
else:
_LOGGER.error(
"HCIdump thread: Runtime error while sending scan request on hci%i: %s.",
Expand All @@ -634,14 +639,17 @@ def run(self):
btctrl[hci].stop_scan_request()
)
except RuntimeError as error:
if CONF_BT_AUTO_RESTART:
_LOGGER.error(
"HCIdump thread: Runtime error while stop scan request on hci%i: %s Resetting Bluetooth adapter %s and trying again.",
hci,
error,
BT_INTERFACES[hci],
)
reset_bluetooth(hci)
if CONF_BT_AUTO_RESTART is True:
ts_now = dt_util.now()
if ts_now - self.last_bt_reset > 60:
_LOGGER.error(
"HCIdump thread: Runtime error while stop scan request on hci%i: %s Resetting Bluetooth adapter %s and trying again.",
hci,
error,
BT_INTERFACES[hci],
)
reset_bluetooth(hci)
self.last_bt_reset = ts_now
else:
_LOGGER.error(
"HCIdump thread: Runtime error while stop scan request on hci%i: %s.",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ble_monitor/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
],
"dependencies": [],
"codeowners": ["@Ernst79", "@Magalex2x14", "@Thrilleratplay"],
"version": "6.4.2-beta",
"version": "6.4.3-beta",
"iot_class": "local_polling"
}

0 comments on commit d1ac420

Please sign in to comment.