Skip to content

Commit 17dd1a9

Browse files
committed
refactor(YXCleanType): move legacy values to a separate dictionary and update from_value method
1 parent 3bfadcc commit 17dd1a9

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

roborock/data/b01_q10/b01_q10_code_mappings.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Self
2+
13
from ..code_mappings import RoborockModeEnum
24

35

@@ -155,6 +157,13 @@ class YXRoomMaterial(RoborockModeEnum):
155157
OTHER = "other", 255
156158

157159

160+
_YX_CLEAN_TYPE_LEGACY_VALUES: dict[str, str] = {
161+
"bothwork": "vac_and_mop",
162+
"onlysweep": "vacuum",
163+
"onlymop": "mop",
164+
}
165+
166+
158167
class YXCleanType(RoborockModeEnum):
159168
UNKNOWN = "unknown", -1
160169
VAC_AND_MOP = "vac_and_mop", 1
@@ -167,14 +176,9 @@ class YXCleanType(RoborockModeEnum):
167176
ONLY_MOP = MOP
168177

169178
@classmethod
170-
def from_value(cls, value: str):
179+
def from_value(cls, value: str) -> Self:
171180
"""Find enum member by string value with legacy support."""
172-
legacy_values = {
173-
"bothwork": "vac_and_mop",
174-
"onlysweep": "vacuum",
175-
"onlymop": "mop",
176-
}
177-
normalized_value = legacy_values.get(value.lower(), value)
181+
normalized_value = _YX_CLEAN_TYPE_LEGACY_VALUES.get(value.lower(), value)
178182
return super().from_value(normalized_value)
179183

180184

0 commit comments

Comments
 (0)