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
8 changes: 8 additions & 0 deletions roborock/devices/traits/v1/device_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from roborock.devices.traits.v1 import common
from roborock.roborock_typing import RoborockCommand

# Qrevo 2 Pro uses single-line laser obstacle sensing without an RGB camera.
_MODELS_WITHOUT_OBSTACLE_PHOTOS = frozenset({"roborock.vacuum.a294"})

# Cache of metadata for each trait class
_metadata_cache: dict[type[RoborockBase], dict[str, dict[str, Any]]] = {}

Expand Down Expand Up @@ -71,6 +74,11 @@ def __init__(self, product: HomeDataProduct, device_cache: DeviceCache) -> None:
for field in fields(self):
setattr(self, field.name, False)

@property
def is_obstacle_photo_download_supported(self) -> bool:
"""Return whether obstacle-photo downloads are supported for trait discovery."""
return self.is_ai_recognition_obstacle_supported and self._product.model not in _MODELS_WITHOUT_OBSTACLE_PHOTOS

def is_field_supported(self, cls: type[RoborockBase], field_name: FieldNameBase) -> bool:
"""Determines if the specified field is supported by this device.

Expand Down
2 changes: 1 addition & 1 deletion roborock/devices/traits/v1/obstacle_photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ObstaclePhotoTrait(RoborockBase, common.V1TraitMixin):
command = RoborockCommand.GET_PHOTO
converter = ObstaclePhotoConverter()
blob_rpc_channel = True
requires_feature = "is_ai_recognition_obstacle_supported"
requires_feature = "is_obstacle_photo_download_supported"

def __init__(self, standard_rpc_channel: V1RpcChannel) -> None:
"""Initialize the obstacle photo trait."""
Expand Down
24 changes: 23 additions & 1 deletion tests/devices/traits/v1/test_obstacle_photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pytest

from roborock.data import HomeDataDevice
from roborock.devices.device import RoborockDevice
from roborock.devices.traits.v1.obstacle_photos import (
ObstaclePhotoTrait,
Expand All @@ -15,6 +16,7 @@
from roborock.protocols.v1_protocol import create_blob_response_decoder
from roborock.roborock_message import RoborockMessage, RoborockMessageProtocol
from roborock.roborock_typing import RoborockCommand
from tests import mock_data

PNG_BYTES = b"\x89PNG\r\n\x1a\nphoto-bytes"
JPEG_BYTES = b"\xff\xd8\xff\xe0photo-bytes"
Expand Down Expand Up @@ -114,7 +116,27 @@ def test_decode_blob_response_does_not_wrap_unexpected_errors() -> None:
def test_obstacle_photo_trait_metadata() -> None:
"""Test obstacle photos use the blob RPC channel when discovered."""
assert ObstaclePhotoTrait.blob_rpc_channel is True
assert ObstaclePhotoTrait.requires_feature == "is_ai_recognition_obstacle_supported"
assert ObstaclePhotoTrait.requires_feature == "is_obstacle_photo_download_supported"


@pytest.mark.parametrize(
("device_info", "photos_supported"),
[
(mock_data.DEVICE_PRODUCT_PAIRS["home_data_device_qrevo_2_pro.json"][0], False),
(mock_data.DEVICE_PRODUCT_PAIRS["home_data_device_s7_maxv.json"][0], True),
],
ids=["qrevo_2_pro", "s7_maxv"],
)
async def test_obstacle_photo_discovery(
device_info: HomeDataDevice,
photos_supported: bool,
device: RoborockDevice,
discover_features_fixture: None,
) -> None:
"""Discover photo downloads separately from generic obstacle recognition."""
assert device.v1_properties is not None
assert device.v1_properties.device_features.is_ai_recognition_obstacle_supported is True
assert (device.v1_properties.obstacle_photos is not None) is photos_supported


async def test_get_enabled(obstacle_photo_trait: ObstaclePhotoTrait, mock_rpc_channel: AsyncMock) -> None:
Expand Down
Loading