Skip to content
Merged
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
6 changes: 4 additions & 2 deletions roborock/data/code_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ class RoborockCategory(Enum):
WET_DRY_VAC = "roborock.wetdryvac"
VACUUM = "robot.vacuum.cleaner"
WASHING_MACHINE = "roborock.wm"
MOWER = "roborock.mower"
UNKNOWN = "UNKNOWN"

def __missing__(self, key):
_LOGGER.warning("Missing key %s from category", key)
@classmethod
def _missing_(cls, value):
_LOGGER.warning("Missing code %s from category", value)
return RoborockCategory.UNKNOWN
16 changes: 16 additions & 0 deletions tests/data/test_code_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest

from roborock import HomeDataProduct, RoborockCategory
from roborock.data.b01_q10.b01_q10_code_mappings import B01_Q10_DP


Expand Down Expand Up @@ -49,3 +50,18 @@ def test_invalid_from_value() -> None:
"""Test invalid from_value method."""
with pytest.raises(ValueError, match="invalid_value is not a valid value for B01_Q10_DP"):
B01_Q10_DP.from_value("invalid_value")


def test_homedata_product_unknown_category():
"""Test that HomeDataProduct can handle unknown categories."""
data = {
"id": "unknown_cat_id",
"name": "Unknown Device",
"model": "roborock.vacuum.a87",
"category": "roborock.random.category",
"schema": [],
}

product = HomeDataProduct.from_dict(data)
assert product.id == "unknown_cat_id"
assert product.category == RoborockCategory.UNKNOWN
Loading