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
@@ -16,11 +20,22 @@ class StatusTrait(Q10Status):
1620
1721 This is a thin wrapper around Q10Status that provides the Trait interface.
1822 The current values reflect the most recently received data from the device.
19- New values can be requited through the `Q10PropertiesApi`'s `refresh` method.
23+ New values can be requested 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 (logger = _LOGGER )
30+
31+ def add_update_listener (self , callback : Callable [[dict [B01_Q10_DP , Any ]], None ]) -> Callable [[], None ]:
32+ """Register a callback for decoded DPS updates.
33+
34+ Returns a callable to remove the listener.
35+ """
36+ return self ._update_callbacks .add_callback (callback )
37+
38+ def update_from_dps (self , decoded_dps : dict [B01_Q10_DP , Any ]) -> None :
2339 """Update the trait from raw DPS data."""
2440 _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.
41+ self ._update_callbacks (decoded_dps )
0 commit comments