toio.cube.api.base_class module

class toio.cube.api.base_class.CubeCommand[source]

Bases: object

abstract __bytes__() bytes[source]

Returns the byte representation of this class to be sent to cube.

Returns:

byte representation of this class to be sent to cube.

Return type:

bytes

class toio.cube.api.base_class.CubeResponse[source]

Bases: object

abstract static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

class toio.cube.api.base_class.CubeCharacteristic(interface: CubeInterface, uuid: UUID, device: Any = None)[source]

Bases: object

abstract static is_my_data(payload: bytearray) CubeResponse | None[source]

If payload is my characteristic response, this function returns CubeResponse object. Otherwise, it returns None.

Parameters:

payload (GattReadData) – received data from the cube.

__init__(interface: CubeInterface, uuid: UUID, device: Any = None)[source]
async register_notification_handler(handler: Callable[[bytearray], None] | Callable[[bytearray], Awaitable[None]] | Callable[[bytearray, Any], None] | Callable[[bytearray, Any], Awaitable[None]], misc: Any = None) bool[source]

User interface to GATT for registering handler function.

Note

Type of the notification handler function must be
Callable[[bytearray], None]
# sync without NotificationHandlerInfo (v1.0.0 or later)
or
Callable[[bytearray], Awaitable[None]]
# async without NotificationHandlerInfo (v1.0.0 or later)
or
Callable[[bytearray, ToioNotificationHandlerInfo], None]
# sync with NotificationHandlerInfo (v1.1.0 or later)
or
Callable[[bytearray, ToioNotificationHandlerInfo], Awaitable[None]]
# async with NotificationHandlerInfo (v1.1.0 or later)

NotificationHandlerInfo has device, interface and misc attributes. device attribute is the ToioCoreCube instance that received the notification. interface attribute is the CubeInterface instance that received the notification. misc attribute is set to the misc argument of this function.

If you want to use some cube api in the notification handler, you must define the notification handler as async function. In this case, you can await the cube api in the notification handler.

Parameters:
  • handler (ToioCoreCubeNotificationHandler) – handler function

  • misc (Any) – data given to the handler function as NotificationHandlerInfo.misc

Return type:

bool

async unregister_notification_handler(handler: Callable[[bytearray], None] | Callable[[bytearray], Awaitable[None]] | Callable[[bytearray, Any], None] | Callable[[bytearray, Any], Awaitable[None]]) bool[source]

User interface to GATT for unregistering handler function.