|
8 | 8 | import logging |
9 | 9 | import time |
10 | 10 | from collections.abc import Callable |
| 11 | +from dataclasses import asdict |
11 | 12 | from typing import Any |
12 | 13 | from unittest.mock import Mock |
13 | 14 |
|
14 | 15 | from roborock.data import HomeDataDevice, HomeDataProduct |
15 | 16 | from roborock.data.v1 import RoborockStateCode |
| 17 | +from roborock.data.v1.v1_containers import Consumable |
16 | 18 | from roborock.devices.cache import DeviceCache, InMemoryCache |
17 | 19 | from roborock.devices.rpc.v1_channel import V1Channel |
18 | 20 | from roborock.protocols.v1_protocol import SecurityData |
@@ -107,16 +109,16 @@ def __init__( |
107 | 109 | self.dss = dss |
108 | 110 | self.dock_type = dock_type |
109 | 111 |
|
110 | | - self.consumables = { |
111 | | - "main_brush_work_time": 74382, |
112 | | - "side_brush_work_time": 74383, |
113 | | - "filter_work_time": 74384, |
114 | | - "filter_element_work_time": 0, |
115 | | - "sensor_dirty_time": 74385, |
116 | | - "strainer_work_times": 65, |
117 | | - "dust_collection_work_times": 25, |
118 | | - "cleaning_brush_work_times": 66, |
119 | | - } |
| 112 | + self.consumables = Consumable( |
| 113 | + main_brush_work_time=74382, |
| 114 | + side_brush_work_time=74383, |
| 115 | + filter_work_time=74384, |
| 116 | + filter_element_work_time=0, |
| 117 | + sensor_dirty_time=74385, |
| 118 | + strainer_work_times=65, |
| 119 | + dust_collection_work_times=25, |
| 120 | + cleaning_brush_work_times=66, |
| 121 | + ) |
120 | 122 |
|
121 | 123 | self.dnd_timer = { |
122 | 124 | "start_hour": 22, |
@@ -153,7 +155,7 @@ def __init__( |
153 | 155 | # Set up default handlers dictionary |
154 | 156 | self.default_handlers: dict[str, Callable[[Any], Any]] = { |
155 | 157 | "get_status": lambda params: [self.get_status_dict()], |
156 | | - "get_consumable": lambda params: [self.consumables], |
| 158 | + "get_consumable": lambda params: [{k: v for k, v in asdict(self.consumables).items() if v is not None}], |
157 | 159 | "get_dnd_timer": lambda params: self.dnd_timer, |
158 | 160 | "get_clean_summary": lambda params: self.clean_summary, |
159 | 161 | "get_clean_record": lambda params: self.last_clean_record, |
@@ -282,8 +284,8 @@ def _handle_set_water_box_custom_mode(self, params: Any) -> str: |
282 | 284 | def _handle_reset_consumable(self, params: Any) -> str: |
283 | 285 | if isinstance(params, list) and len(params) > 0: |
284 | 286 | consumable_name = params[0] |
285 | | - if consumable_name in self.consumables: |
286 | | - self.consumables[consumable_name] = 0 |
| 287 | + if hasattr(self.consumables, consumable_name): |
| 288 | + setattr(self.consumables, consumable_name, 0) |
287 | 289 | return "ok" |
288 | 290 |
|
289 | 291 | def _handle_app_get_init_status(self, params: Any) -> list[dict[str, Any]]: |
|
0 commit comments