def init(self): """macOS init function for NSObject""" self = objc.super(CentralManagerDelegate, self).init() if self is None: return None self.event_loop = asyncio.get_event_loop() self.connected_peripheral_delegate = None self.connected_peripheral = None self._connection_state = CMDConnectionState.DISCONNECTED self.powered_on_event = asyncio.Event() self.devices = {} self.callbacks = {} self.disconnected_callback = None if not self.compliant(): logger.warning("CentralManagerDelegate is not compliant") self.central_manager = CBCentralManager.alloc( ).initWithDelegate_queue_( self, dispatch_queue_create(b"bleak.corebluetooth", DISPATCH_QUEUE_SERIAL)) return self
def init(self): """macOS init function for NSObject""" self = objc.super(CentralManagerDelegate, self).init() if self is None: return None self.event_loop = asyncio.get_event_loop() self.connected_peripheral_delegate = None self.connected_peripheral = None self._connection_state = CMDConnectionState.DISCONNECTED self.devices = {} self.callbacks = {} self.disconnected_callback = None self._connection_state_changed = asyncio.Event() self._did_update_state_event = threading.Event() self.central_manager = CBCentralManager.alloc().initWithDelegate_queue_( self, dispatch_queue_create(b"bleak.corebluetooth", DISPATCH_QUEUE_SERIAL) ) # according to CoreBluetooth docs, it is not valid to call CBCentral # methods until the centralManagerDidUpdateState_() delegate method # is called and the current state is CBManagerStatePoweredOn. # It doesn't take long for the callback to occur, so we should be able # to do a blocking wait here without anyone complaining. self._did_update_state_event.wait(1) if self.central_manager.state() != CBManagerStatePoweredOn: raise BleakError("Bluetooth device is turned off") return self
def init(self): """macOS init function for NSObject""" self = objc.super(CentralManagerDelegate, self).init() if self is None: return None self.central_manager = CBCentralManager.alloc( ).initWithDelegate_queue_(self, None) self.connected_peripheral_delegate = None self.connected_peripheral = None self._connection_state = CMDConnectionState.DISCONNECTED self.ready = False self.devices = {} if not self.compliant(): logger.warning("CentralManagerDelegate is not compliant") return self
print('Noise:' + str(noise)) disco = decode_value(value[13:15], 0.01) print('Disco:' + str(disco)) heat = decode_value(value[15:17], 0.01) print('Heat:' + str(heat)) batt = decode_value(value[17:19], 0.001) print('Battery:' + str(batt)) if "__main__" == __name__: import argparse parser = argparse.ArgumentParser(description='Monitor BLE') parser.add_argument("--debug", action='store_true', help="Run in debugger mode") args = parser.parse_args() central_manager = CBCentralManager.alloc() central_manager.initWithDelegate_queue_options_(MyBLE(debug=args.debug), None, None) try: AppHelper.runConsoleEventLoop() except (KeyboardInterrupt, SystemExit) as e: print(e) except OC_PythonException as e: print(e) pass