Skip to content

Commit 8f4b7d3

Browse files
authored
fix: status reworking (#121)
* fix: is_available true by default * fix: status type as class variable * fix: don't update status when it was none before listener * fix: reduce info logs
1 parent b9c2260 commit 8f4b7d3

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

roborock/api.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,18 @@ def __init__(self, endpoint: str, device_info: DeviceData, queue_timeout: int =
184184
device_cache[device_info.device.duid] = cache
185185
self.cache: dict[CacheableAttribute, AttributeCache] = cache
186186
self._listeners: list[Callable[[str, CacheableAttribute, RoborockBase], None]] = []
187-
self.is_available: bool = False
187+
self.is_available: bool = True
188188
self.queue_timeout = queue_timeout
189+
self._status_type: type[Status] = ModelStatus.get(self.device_info.model, S7MaxVStatus)
189190

190191
def __del__(self) -> None:
191192
self.release()
192193

194+
@property
195+
def status_type(self) -> type[Status]:
196+
"""Gets the status type for this device"""
197+
return self._status_type
198+
193199
def release(self):
194200
self.sync_disconnect()
195201
[item.stop() for item in self.cache.values()]
@@ -253,17 +259,14 @@ def on_message_received(self, messages: list[RoborockMessage]) -> None:
253259
data_protocol = RoborockDataProtocol(int(data_point_number))
254260
self._logger.debug(f"Got device update for {data_protocol.name}: {data_point}")
255261
if data_protocol in ROBOROCK_DATA_STATUS_PROTOCOL:
256-
_cls: type[Status] = ModelStatus.get(
257-
self.device_info.model, S7MaxVStatus
258-
) # Default to S7 MAXV if we don't have the data
259262
if self.cache[CacheableAttribute.status].value is None:
260263
self._logger.debug(
261264
f"Got status update({data_protocol.name}) before get_status was called."
262265
)
263-
self.cache[CacheableAttribute.status]._value = {}
266+
return
264267
value = self.cache[CacheableAttribute.status].value
265268
value[data_protocol.name] = data_point
266-
status = _cls.from_dict(value)
269+
status = self._status_type.from_dict(value)
267270
for listener in self._listeners:
268271
listener(self.device_info.device.duid, CacheableAttribute.status, status)
269272
elif data_protocol in ROBOROCK_DATA_CONSUMABLE_PROTOCOL:
@@ -272,7 +275,7 @@ def on_message_received(self, messages: list[RoborockMessage]) -> None:
272275
f"Got consumable update({data_protocol.name})"
273276
+ "before get_consumable was called."
274277
)
275-
self.cache[CacheableAttribute.consumable]._value = {}
278+
return
276279
value = self.cache[CacheableAttribute.consumable].value
277280
value[data_protocol.name] = data_point
278281
consumable = Consumable.from_dict(value)
@@ -406,10 +409,7 @@ async def send_command(
406409
return response
407410

408411
async def get_status(self) -> Status | None:
409-
_cls: type[Status] = ModelStatus.get(
410-
self.device_info.model, S7MaxVStatus
411-
) # Default to S7 MAXV if we don't have the data
412-
return _cls.from_dict(await self.cache[CacheableAttribute.status].async_value())
412+
return self._status_type.from_dict(await self.cache[CacheableAttribute.status].async_value())
413413

414414
async def get_dnd_timer(self) -> DnDTimer | None:
415415
return DnDTimer.from_dict(await self.cache[CacheableAttribute.dnd_timer].async_value())

roborock/cloud_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def sync_connect(self) -> tuple[bool, Task[tuple[Any, VacuumError | None]] | Non
138138
if self._mqtt_port is None or self._mqtt_host is None:
139139
raise RoborockException("Mqtt information was not entered. Cannot connect.")
140140

141-
self._logger.info("Connecting to mqtt")
141+
self._logger.debug("Connecting to mqtt")
142142
connected_future = asyncio.ensure_future(self._async_response(CONNECT_REQUEST_ID))
143143
super().connect(host=self._mqtt_host, port=self._mqtt_port, keepalive=KEEPALIVE)
144144

roborock/local_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async def async_connect(self) -> None:
5959
if not self.is_connected():
6060
self.sync_disconnect()
6161
async with async_timeout.timeout(self.queue_timeout):
62-
self._logger.info(f"Connecting to {self.host}")
62+
self._logger.debug(f"Connecting to {self.host}")
6363
self.transport, _ = await self.event_loop.create_connection( # type: ignore
6464
lambda: self, self.host, 58867
6565
)

0 commit comments

Comments
 (0)