Skip to content

Commit

Permalink
More control on threads.
Browse files Browse the repository at this point in the history
If at the time of data processing not all the threads are completed,
then we skip the current iteration of processing and do not spawn new threads.
  • Loading branch information
Magalex2x14 committed Apr 5, 2020
1 parent 79e76b6 commit b352895
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ This custom component is an alternative for the standard build in [mitemp_bt](ht

- LYWSD03MMC

(small square body, segment LCD, broadcasts temperature and humidity once in about 10 minutes and battery once in an hour, advertisements are encrypted, therefore you need to set the key in your configuration, see for instructions the [encryptors](#configuration-variables) option.
(small square body, segment LCD, broadcasts temperature and humidity once in about 10 minutes and battery once in an hour, advertisements are encrypted, therefore you need to set the key in your configuration, see for instructions the [encryptors](#configuration-variables) option)

- CGD1

(Cleargrass (Qingping) CGD1 alarm clock, segment LCD, broadcasts temperature and humidity (once in a 3 minutes?), and the battery (we do not have accurate periodicity information yet), advertisements are encrypted, therefore you need to set the key in your configuration, the procedure is similar to the LYWSD03MMC sensor.
(Cleargrass (Qingping) CGD1 alarm clock, segment LCD, broadcasts temperature and humidity (once in a 3 minutes?), and the battery (we do not have accurate periodicity information yet), advertisements are encrypted, therefore you need to set the key in your configuration, the procedure is similar to the LYWSD03MMC sensor)

- JQJCY01YM

(Xiaomi Honeywell Formaldehyde Sensor, OLED display, broadcasts temperature, humidity, formaldehyde (mg/m³) and the battery, total about 50 messages per minute.
(Xiaomi Honeywell Formaldehyde Sensor, OLED display, broadcasts temperature, humidity, formaldehyde (mg/m³) and the battery, total about 50 messages per minute)

*The amount of actually received data is highly dependent on the reception conditions (like distance and electromagnetic ambiance), readings numbers are indicated for good RSSI (Received Signal Strength Indicator) of about -75 till -70dBm.*

Expand Down
21 changes: 17 additions & 4 deletions custom_components/mitemp_bt/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def run(self):
self._event_loop.close()
_LOGGER.debug("HCIdump thread: Run finished")

def join(self, timeout=5):
def join(self, timeout=10):
"""Join HCIdump thread."""
_LOGGER.debug("HCIdump thread: joining")
try:
Expand Down Expand Up @@ -360,9 +360,19 @@ def start(self, config):

def stop(self):
"""Stop HCIdump thread(s)."""
result = True
for dumpthread in self.dumpthreads:
dumpthread.join()
self.dumpthreads.clear()
if dumpthread.isAlive():
dumpthread.join()
if dumpthread.isAlive():
result = False
_LOGGER.error(
"Waiting for the HCIdump thread to finish took too long! (>10s)"
)
if result is True:
self.dumpthreads.clear()
return result


def shutdown_handler(self, event):
"""Run homeassistant_stop event handler."""
Expand Down Expand Up @@ -484,7 +494,10 @@ def discover_ble_devices(config, aeskeyslist):
rssi = {}
macs = {} # all found macs
_LOGGER.debug("Getting data from HCIdump thread")
scanner.stop()
jres = scanner.stop()
if jres is False:
_LOGGER.error("HCIdump thread(s) is not completed, interrupting data processing!")
return []
hcidump_raw = [*scanner.hcidump_data]
scanner.start(config) # minimum delay between HCIdumps
report_unknown = config[CONF_REPORT_UNKNOWN]
Expand Down

0 comments on commit b352895

Please sign in to comment.