Skip to content

Commit 742a382

Browse files
authored
fix: correctly handle unknown categories (#755)
1 parent 1455d77 commit 742a382

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

roborock/data/code_mappings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,10 @@ class RoborockCategory(Enum):
173173
WET_DRY_VAC = "roborock.wetdryvac"
174174
VACUUM = "robot.vacuum.cleaner"
175175
WASHING_MACHINE = "roborock.wm"
176+
MOWER = "roborock.mower"
176177
UNKNOWN = "UNKNOWN"
177178

178-
def __missing__(self, key):
179-
_LOGGER.warning("Missing key %s from category", key)
179+
@classmethod
180+
def _missing_(cls, value):
181+
_LOGGER.warning("Missing code %s from category", value)
180182
return RoborockCategory.UNKNOWN

tests/data/test_code_mappings.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66

7+
from roborock import HomeDataProduct, RoborockCategory
78
from roborock.data.b01_q10.b01_q10_code_mappings import B01_Q10_DP
89

910

@@ -49,3 +50,18 @@ def test_invalid_from_value() -> None:
4950
"""Test invalid from_value method."""
5051
with pytest.raises(ValueError, match="invalid_value is not a valid value for B01_Q10_DP"):
5152
B01_Q10_DP.from_value("invalid_value")
53+
54+
55+
def test_homedata_product_unknown_category():
56+
"""Test that HomeDataProduct can handle unknown categories."""
57+
data = {
58+
"id": "unknown_cat_id",
59+
"name": "Unknown Device",
60+
"model": "roborock.vacuum.a87",
61+
"category": "roborock.random.category",
62+
"schema": [],
63+
}
64+
65+
product = HomeDataProduct.from_dict(data)
66+
assert product.id == "unknown_cat_id"
67+
assert product.category == RoborockCategory.UNKNOWN

0 commit comments

Comments
 (0)