From 8286eca0aac127e857f2d8c4da2a729458d28720 Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 1 Feb 2026 17:09:44 -0500 Subject: [PATCH] chore: set typing for from_code_optional to use Self --- roborock/data/code_mappings.py | 3 ++- roborock/protocols/b01_q10_protocol.py | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/roborock/data/code_mappings.py b/roborock/data/code_mappings.py index f0279b33..4794a2c5 100644 --- a/roborock/data/code_mappings.py +++ b/roborock/data/code_mappings.py @@ -77,7 +77,8 @@ def from_code(cls, code: int) -> Self: raise ValueError(message) @classmethod - def from_code_optional(cls, code: int) -> RoborockModeEnum | None: + def from_code_optional(cls, code: int) -> Self | None: + """Gracefully return None if the code does not exist.""" try: return cls.from_code(code) except ValueError: diff --git a/roborock/protocols/b01_q10_protocol.py b/roborock/protocols/b01_q10_protocol.py index 06d57921..94a1e7b3 100644 --- a/roborock/protocols/b01_q10_protocol.py +++ b/roborock/protocols/b01_q10_protocol.py @@ -45,8 +45,7 @@ def _convert_datapoints(datapoints: dict[str, Any], message: RoborockMessage) -> except ValueError as e: raise ValueError(f"dps key is not a valid integer: {e} for {message.payload!r}") from e if (dps := B01_Q10_DP.from_code_optional(code)) is not None: - # Update from_code to use `Self` on newer python version to remove this type ignore - result[dps] = value # type: ignore[index] + result[dps] = value return result