11"""Status trait for Q10 B01 devices."""
22
33import logging
4+ from collections .abc import Callable
5+ from typing import Any
46
7+ from roborock .callbacks import CallbackList
8+ from roborock .data .b01_q10 .b01_q10_code_mappings import B01_Q10_DP
59from roborock .data .b01_q10 .b01_q10_containers import Q10Status
610
711from .common import DpsDataConverter
@@ -19,8 +23,23 @@ class StatusTrait(Q10Status):
1923 New values can be requited through the `Q10PropertiesApi`'s `refresh` method.
2024 """
2125
22- def update_from_dps (self , decoded_dps : dict ) -> None :
26+ def __init__ (self ) -> None :
27+ """Initialize the status trait."""
28+ super ().__init__ ()
29+ self ._update_callbacks : CallbackList [dict [B01_Q10_DP , Any ]] = CallbackList (
30+ logger = _LOGGER
31+ )
32+
33+ def add_update_listener (
34+ self , callback : Callable [[dict [B01_Q10_DP , Any ]], None ]
35+ ) -> Callable [[], None ]:
36+ """Register a callback for decoded DPS updates.
37+
38+ Returns a callable to remove the listener.
39+ """
40+ return self ._update_callbacks .add_callback (callback )
41+
42+ def update_from_dps (self , decoded_dps : dict [B01_Q10_DP , Any ]) -> None :
2343 """Update the trait from raw DPS data."""
2444 _CONVERTER .update_from_dps (self , decoded_dps )
25- # In the future we can register listeners and notify them here on update
26- # if `update_from_dps` performed any updates.
45+ self ._update_callbacks (decoded_dps )
0 commit comments