Skip to content

Commit ad4d055

Browse files
committed
chore: fix style and comments
1 parent fde1d0f commit ad4d055

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

roborock/callbacks.py

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ def wrapper(value: V) -> None:
3030

3131

3232
class CallbackMap(Generic[K, V]):
33-
"""A mapping of callbacks for specific keys."""
33+
"""A mapping of callbacks for specific keys.
34+
35+
This allows for registering multiple callbacks for different keys and invoking them
36+
when a value is received for a specific key.
37+
"""
3438

3539
def __init__(self, logger: logging.Logger | None = None) -> None:
3640
self._callbacks: dict[K, list[Callable[[V], None]]] = {}
@@ -69,7 +73,11 @@ def __call__(self, key: K, value: V) -> None:
6973

7074

7175
class CallbackList(Generic[V]):
72-
"""A list of callbacks for specific keys."""
76+
"""A list of callbacks that can be invoked.
77+
78+
This combines a list of callbacks into a single callable. Callers can add
79+
additional callbacks to the list at any time.
80+
"""
7381

7482
def __init__(self, logger: logging.Logger | None = None) -> None:
7583
self._callbacks: list[Callable[[V], None]] = []
@@ -97,31 +105,10 @@ def decoder_callback(
97105
) -> Callable[[K], None]:
98106
"""Create a callback that decodes messages using a decoder and invokes a callback.
99107
100-
Any failures during decoding will be logged.
101-
"""
102-
if logger is None:
103-
logger = _LOGGER
104-
105-
safe_cb = safe_callback(callback, logger)
106-
107-
def wrapper(data: K) -> None:
108-
if not (messages := decoder(data)):
109-
logger.warning("Failed to decode message: %s", data)
110-
return
111-
for message in messages:
112-
_LOGGER.debug("Decoded message: %s", message)
113-
safe_cb(message)
114-
115-
return wrapper
116-
117-
118-
119-
def dipspatch_callback(
120-
callback: Callable[[V], None], logger: logging.Logger | None = None
121-
) -> Callable[[list[V]], None]:
122-
"""Create a callback that decodes messages using a decoder and invokes a callback.
108+
The decoder converts a value into a list of values. The callback is then invoked
109+
for each value in the list.
123110
124-
Any failures during decoding will be logged.
111+
Any failures during decoding or invoking the callbacks will be logged.
125112
"""
126113
if logger is None:
127114
logger = _LOGGER

0 commit comments

Comments
 (0)