44import asyncio
55import struct
66import enum
7-
7+ from typing import Callable , Awaitable
88
99class Color (enum .Enum ):
1010 """
@@ -44,7 +44,6 @@ def __init__(self, ble_client) -> None:
4444 self ._nop_cb = lambda _ : None
4545 self ._position_upd_cb = self ._nop_cb
4646
47-
4847 async def connect (self ):
4948 await self ._client .connect ()
5049 self ._tx_char = self ._client .services .get_characteristic (
@@ -82,9 +81,9 @@ async def pulse_led(self, pulse_count, on_time_ms, off_time_ms, rgb_tuple):
8281 """
8382 Pulses the die's leds for set time
8483 :param pulse_count: How many pulses
85- :param on_time : How much time to spend on (units of 10 ms)
86- :param off_time : How much time to spend off (units of 10 ms)
87- :param rgb: List of RGB values to set die to pulse to
84+ :param on_time_ms : How much time to spend on (units of 10 ms)
85+ :param off_time_ms : How much time to spend off (units of 10 ms)
86+ :param rgb_tuple: tuple of RGB values set to pulse
8887 """
8988 _validate_rgb_tuple (rgb_tuple )
9089
@@ -118,16 +117,17 @@ async def get_battery_level(self):
118117 await self ._client .write_gatt_char (self ._tx_char , msg )
119118 return await self ._battery_lvl_upd_q .get ()
120119
121- async def subscribe_number_notification (self , cb ):
120+ async def subscribe_number_notification (self , callback : Callable [[ int , StabilityDescriptor ], Awaitable [ None ]] ):
122121 """
123122 Subscribe to receiving position change notifications
123+ :param callback: callback function receiving number update notifications
124124 """
125- self ._position_upd_cb = cb
125+ self ._position_upd_cb = callback
126126
127127 async def _handle_upd (self , _char , data : bytearray ):
128128 first_byte = data [0 ]
129129 if first_byte == 82 :
130- await self ._position_upd_cb (StabilityDescriptor .ROLLING , 0 )
130+ await self ._position_upd_cb (0 , StabilityDescriptor .ROLLING )
131131 return
132132
133133 second_byte = data [1 ]
@@ -143,22 +143,22 @@ async def _handle_upd(self, _char, data: bytearray):
143143 if first_byte == 83 :
144144 xyz = _get_xyz_from_bytes (data [1 :4 ])
145145 rolled_value = self ._xyz_interpret_fn (xyz )
146- await self ._position_upd_cb (StabilityDescriptor .STABLE , rolled_value )
146+ await self ._position_upd_cb (rolled_value , StabilityDescriptor .STABLE )
147147 return
148148
149149 if second_byte == 83 :
150150 xyz = _get_xyz_from_bytes (data [2 :5 ])
151151 rolled_value = self ._xyz_interpret_fn (xyz )
152- move_spec = None
152+ descr = None
153153 if first_byte == 70 :
154- move_spec = StabilityDescriptor .FAKE_STABLE
154+ descr = StabilityDescriptor .FAKE_STABLE
155155 elif first_byte == 84 :
156- move_spec = StabilityDescriptor .TILT_STABLE
156+ descr = StabilityDescriptor .TILT_STABLE
157157 elif first_byte == 77 :
158- move_spec = StabilityDescriptor .MOVE_STABLE
158+ descr = StabilityDescriptor .MOVE_STABLE
159159 else :
160- move_spec = None
161- await self ._position_upd_cb (move_spec , rolled_value )
160+ descr = None
161+ await self ._position_upd_cb (rolled_value , descr )
162162
163163
164164def _validate_rgb_tuple (rgb_tuple ):
0 commit comments