Skip to content

Commit 1320282

Browse files
improve docs for some functions
1 parent 87f29ee commit 1320282

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

godice/demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ async def main():
3838
await dice.set_led(off_rgb, off_rgb)
3939

4040

41-
async def print_notification(stability_descr, number):
42-
print(f"Stability descriptor: {stability_descr}, number: {number}")
41+
async def print_notification(number, stability_descr):
42+
print(f"Number: {number}, stability descriptor: {stability_descr}")
4343

4444

4545
def filter_godice_devices(dev_advdata_tuples):

godice/dice.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import asyncio
55
import struct
66
import enum
7-
7+
from typing import Callable, Awaitable
88

99
class 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

164164
def _validate_rgb_tuple(rgb_tuple):

0 commit comments

Comments
 (0)