Skip to content

Commit 220ae8b

Browse files
authored
chore: set typing for from_code_optional to use Self (#761)
1 parent 9993407 commit 220ae8b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

roborock/data/code_mappings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ def from_code(cls, code: int) -> Self:
7777
raise ValueError(message)
7878

7979
@classmethod
80-
def from_code_optional(cls, code: int) -> RoborockModeEnum | None:
80+
def from_code_optional(cls, code: int) -> Self | None:
81+
"""Gracefully return None if the code does not exist."""
8182
try:
8283
return cls.from_code(code)
8384
except ValueError:

roborock/protocols/b01_q10_protocol.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ def _convert_datapoints(datapoints: dict[str, Any], message: RoborockMessage) ->
4545
except ValueError as e:
4646
raise ValueError(f"dps key is not a valid integer: {e} for {message.payload!r}") from e
4747
if (dps := B01_Q10_DP.from_code_optional(code)) is not None:
48-
# Update from_code to use `Self` on newer python version to remove this type ignore
49-
result[dps] = value # type: ignore[index]
48+
result[dps] = value
5049
return result
5150

5251

0 commit comments

Comments
 (0)