Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,34 @@ async def main():

# Create a device manager that can discover devices.
device_manager = await create_device_manager(user_params, cache=cache)
devices = await device_manager.get_devices()

# Get all vacuum devices that support the v1 PropertiesApi
device_results = []
for device in devices:
if not device.v1_properties:
continue

# Refresh the current device status
status_trait = device.v1_properties.status
await status_trait.refresh()

# Print the device status as JSON
device_results.append(
{
"device": device.name,
"status": remove_none_values(dataclasses.asdict(status_trait)),
}
)

print(json.dumps(device_results, indent=2))

await cache.flush()
try:
devices = await device_manager.get_devices()

# Get all vacuum devices that support the v1 PropertiesApi
device_results = []
for device in devices:
if not device.v1_properties:
continue

# Refresh the current device status
status_trait = device.v1_properties.status
await status_trait.refresh()

# Print the device status as JSON
device_results.append(
{
"device": device.name,
"status": remove_none_values(dataclasses.asdict(status_trait)),
}
)

print(json.dumps(device_results, indent=2))

finally:
# Close device manager to cancel background tasks before flushing cache
await device_manager.close()
await cache.flush()


if __name__ == "__main__":
Expand Down
6 changes: 5 additions & 1 deletion roborock/devices/traits/v1/device_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ async def refresh(self) -> None:
return
# Save cached device features
await super().refresh()
cache_data.device_features = self
# Create a pure DeviceFeatures instance without runtime objects
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this was hacky when I added it in a hurry -- Is this resulting in a bug? I'd like to improve our tests to reflect the issue here since it may apply elsewhere etc.

device_features_data = DeviceFeatures()
for field in fields(DeviceFeatures):
setattr(device_features_data, field.name, getattr(self, field.name))
cache_data.device_features = device_features_data
await self._device_cache.set(cache_data)

def _parse_response(self, response: common.V1ResponseData) -> DeviceFeatures:
Expand Down
7 changes: 6 additions & 1 deletion roborock/devices/traits/v1/network_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import logging
from dataclasses import fields

from roborock.data import NetworkInfo
from roborock.devices.cache import DeviceCache
Expand Down Expand Up @@ -45,7 +46,11 @@ async def refresh(self) -> None:

# Update the cache with the new network info
device_cache_data = await self._device_cache.get()
device_cache_data.network_info = self
# Create a pure NetworkInfo instance without runtime objects
network_info_data = NetworkInfo(ip="")
for field in fields(NetworkInfo):
setattr(network_info_data, field.name, getattr(self, field.name))
device_cache_data.network_info = network_info_data
await self._device_cache.set(device_cache_data)

def _parse_response(self, response: common.V1ResponseData) -> NetworkInfo:
Expand Down