def value(self, val) -> None: adapter.await_bleak( # pylint: disable=protected-access self.characteristic.service.connection._bleak_client.write_gatt_descriptor( self.uuid.string, val ) )
def value(self) -> bytes: """The value of this descriptor.""" return adapter.await_bleak( # pylint: disable=protected-access self.characteristic.service.connection._bleak_client.read_gatt_descriptor( self.uuid.string ) )
def readinto(self, buf: Buf) -> Union[int, None]: """Read bytes into the ``buf``. Read at most ``len(buf)`` bytes. :return: number of bytes read and stored into ``buf`` """ length = len(buf) idx = 0 end = time.time() + self._timeout while idx < length and time.time() < end: try: buf[idx] = self._queue.get_nowait() idx += 1 except queue.Empty: # Let the BLE code run for a bit, and try again. adapter.await_bleak(asyncio.sleep(0.1)) return idx
def readline(self, ) -> Buf: """Read a line, ending in a newline character. :return: the line read """ line = bytearray() end = time.time() + self._timeout while time.time() < end: try: b = self._queue.get_nowait() line.append(b) except queue.Empty: # Let the BLE code run for a bit, and try again. adapter.await_bleak(asyncio.sleep(0.1)) continue if b == 0x0A: # newline break return line