'Thread that keeps connection alive.'

def run(self):

    import pygatt
    from pygatt.backends import Characteristic
    from pygatt.exceptions import BLEError, NotConnectedError, NotificationTimeout
    cached_char = Characteristic(BLE_TEMP_UUID, BLE_TEMP_HANDLE)
    adapter = pygatt.backends.GATTToolBackend()
    while True:
        try:
            _LOGGER.info('Connecting    to    %s', self.name)
            adapter.start(reset_on_start=False)
            with CONNECT_LOCK:
                device = adapter.connect(self.mac, CONNECT_TIMEOUT, pygatt.BLEAddressType.random)
            if SKIP_HANDLE_LOOKUP:
                device._characteristics[UUID(BLE_TEMP_UUID)] = cached_char
            device.char_write_handle(27, bytearray([255]), False)
            device.subscribe(BLE_TEMP_UUID, self._update)
            _LOGGER.info('Subscribed    to    %s', self.name)
            while self.keep_going:
                device.char_read(BLE_TEMP_UUID, timeout=CONNECT_TIMEOUT)
                self.event.wait(60)
            break
        except (BLEError, NotConnectedError, NotificationTimeout) as ex:
            _LOGGER.error('Exception:    %s    ', str(ex))
        finally:
            adapter.stop()
