1- import datetime
21from abc import ABC , abstractmethod
32from collections .abc import Awaitable , Callable
43from dataclasses import dataclass
54
65from . import RoborockCommand
7- from .containers import Consumable , DeviceFeatures , DnDTimer , RoborockBase
6+ from .containers import DeviceFeatures , RoborockBase
87
98
109@dataclass
1110class DeviceTrait (ABC ):
1211 handle_command : RoborockCommand
13- _status_type : type [RoborockBase ] = RoborockBase
1412
1513 def __init__ (self , send_command : Callable [..., Awaitable [None ]]):
1614 self .send_command = send_command
@@ -22,8 +20,12 @@ def __init__(self, send_command: Callable[..., Awaitable[None]]):
2220 def supported (cls , features : DeviceFeatures ) -> bool :
2321 raise NotImplementedError
2422
23+ @abstractmethod
24+ def from_dict (cls , data : dict ) -> bool :
25+ raise NotImplementedError
26+
2527 def on_message (self , data : dict ) -> None :
26- self .status = self ._status_type . from_dict (data )
28+ self .status = self .from_dict (data )
2729 for callback in self .subscriptions :
2830 callback (self .status )
2931
@@ -36,44 +38,20 @@ def get(self):
3638 raise NotImplementedError
3739
3840
39- class DndTrait (DeviceTrait ):
40- handle_command : RoborockCommand = RoborockCommand .GET_DND_TIMER
41- _status_type : type [DnDTimer ] = DnDTimer
42- status : DnDTimer
43-
44- def __init__ (self , send_command : Callable [..., Awaitable [None ]]):
45- super ().__init__ (send_command )
46-
47- @classmethod
48- def supported (cls , features : DeviceFeatures ) -> bool :
49- return features .is_support_custom_dnd
50-
51- async def update_dnd (self , enabled : bool , start_time : datetime .time , end_time : datetime .time ) -> None :
52- if self .status .enabled and not enabled :
53- await self .send_command (RoborockCommand .CLOSE_DND_TIMER )
54- else :
55- start = start_time if start_time is not None else self .status .start_time
56- end = end_time if end_time is not None else self .status .end_time
57- await self .send_command (RoborockCommand .SET_DND_TIMER , [start .hour , start .minute , end .hour , end .minute ])
58-
59- async def get (self ) -> None :
60- await self .send_command (RoborockCommand .GET_DND_TIMER )
61-
62-
63- class ConsumableTrait (DeviceTrait ):
64- handle_command = RoborockCommand .GET_CONSUMABLE
65- _status_type : type [Consumable ] = DnDTimer
66- status : Consumable
67-
68- def __init__ (self , send_command : Callable [..., Awaitable [None ]]):
69- super ().__init__ (send_command )
70-
71- @classmethod
72- def supported (cls , features : DeviceFeatures ) -> bool :
73- return True
74-
75- async def reset_consumable (self , consumable : str ) -> None :
76- await self .send_command (RoborockCommand .RESET_CONSUMABLE , [consumable ])
77-
78- async def get (self ) -> None :
79- await self .send_command (RoborockCommand .GET_CONSUMABLE )
41+ # class ConsumableTrait(DeviceTrait):
42+ # handle_command = RoborockCommand.GET_CONSUMABLE
43+ # _status_type: type[Consumable] = DnDTimer
44+ # status: Consumable
45+ #
46+ # def __init__(self, send_command: Callable[..., Awaitable[None]]):
47+ # super().__init__(send_command)
48+ #
49+ # @classmethod
50+ # def supported(cls, features: DeviceFeatures) -> bool:
51+ # return True
52+ #
53+ # async def reset_consumable(self, consumable: str) -> None:
54+ # await self.send_command(RoborockCommand.RESET_CONSUMABLE, [consumable])
55+ #
56+ # async def get(self) -> None:
57+ # await self.send_command(RoborockCommand.GET_CONSUMABLE)
0 commit comments