Skip to content

Commit ac40271

Browse files
committed
refactor: Migrate to typing.Self and remove __future__ annotations.
1 parent 44ee75e commit ac40271

File tree

13 files changed

+14
-34
lines changed

13 files changed

+14
-34
lines changed

roborock/broadcast_protocol.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
import asyncio
42
import hashlib
53
import json

roborock/data/code_mappings.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
import logging
42
from collections import namedtuple
53
from enum import Enum, IntEnum, StrEnum
@@ -17,7 +15,7 @@ def name(self) -> str:
1715
return super().name.lower()
1816

1917
@classmethod
20-
def _missing_(cls: type[RoborockEnum], key) -> RoborockEnum:
18+
def _missing_(cls: type[Self], key) -> Self:
2119
if hasattr(cls, "unknown"):
2220
warning = f"Missing {cls.__name__} code: {key} - defaulting to 'unknown'"
2321
if warning not in completed_warnings:
@@ -32,23 +30,23 @@ def _missing_(cls: type[RoborockEnum], key) -> RoborockEnum:
3230
return default_value
3331

3432
@classmethod
35-
def as_dict(cls: type[RoborockEnum]):
33+
def as_dict(cls: type[Self]):
3634
return {i.name: i.value for i in cls if i.name != "missing"}
3735

3836
@classmethod
39-
def as_enum_dict(cls: type[RoborockEnum]):
37+
def as_enum_dict(cls: type[Self]):
4038
return {i.value: i for i in cls if i.name != "missing"}
4139

4240
@classmethod
43-
def values(cls: type[RoborockEnum]) -> list[int]:
41+
def values(cls: type[Self]) -> list[int]:
4442
return list(cls.as_dict().values())
4543

4644
@classmethod
47-
def keys(cls: type[RoborockEnum]) -> list[str]:
45+
def keys(cls: type[Self]) -> list[str]:
4846
return list(cls.as_dict().keys())
4947

5048
@classmethod
51-
def items(cls: type[RoborockEnum]):
49+
def items(cls: type[Self]):
5250
return cls.as_dict().items()
5351

5452

roborock/data/v1/v1_code_mappings.py

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

35

@@ -91,7 +93,7 @@ class RoborockStartType(RoborockEnum):
9193

9294
class RoborockDssCodes(RoborockEnum):
9395
@classmethod
94-
def _missing_(cls: type[RoborockEnum], key) -> RoborockEnum:
96+
def _missing_(cls: type[Self], key) -> Self:
9597
# If the calculated value is not provided, then it should be viewed as okay.
9698
# As the math will sometimes result in you getting numbers that don't matter.
9799
return cls.okay # type: ignore

roborock/devices/rpc/b01_q10_channel.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Thin wrapper around the MQTT channel for Roborock B01 Q10 devices."""
22

3-
from __future__ import annotations
4-
53
import logging
64
from collections.abc import AsyncGenerator
75
from typing import Any

roborock/devices/traits/b01/q7/clean_summary.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
and a `record_list` whose items contain a JSON string in `detail`.
55
"""
66

7-
from __future__ import annotations
8-
97
import logging
108

119
from roborock import CleanRecordDetail, CleanRecordList, CleanRecordSummary

roborock/devices/traits/v1/network_info.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Trait for device network information."""
22

3-
from __future__ import annotations
4-
53
import logging
64

75
from roborock.data import NetworkInfo

roborock/diagnostics.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
DeviceManager.
1010
"""
1111

12-
from __future__ import annotations
13-
1412
import time
1513
from collections import Counter
1614
from collections.abc import Generator, Mapping
@@ -49,7 +47,7 @@ def as_dict(self) -> Mapping[str, Any]:
4947
data[k] = v
5048
return data
5149

52-
def subkey(self, key: str) -> Diagnostics:
50+
def subkey(self, key: str) -> "Diagnostics":
5351
"""Return sub-Diagnostics object with the specified subkey.
5452
5553
This will create a new Diagnostics object if one does not already exist

roborock/exceptions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Roborock exceptions."""
22

3-
from __future__ import annotations
4-
53

64
class RoborockException(Exception):
75
"""Class for Roborock exceptions."""

roborock/protocol.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
import binascii
42
import gzip
53
import hashlib

roborock/roborock_message.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
from __future__ import annotations
2-
31
from dataclasses import dataclass, field
42
from enum import StrEnum
3+
from typing import Self
54

65
from roborock import RoborockEnum
76
from roborock.util import get_next_int, get_timestamp
@@ -37,7 +36,7 @@ class RoborockDataProtocol(RoborockEnum):
3736
OFFLINE_STATUS = 135
3837

3938
@classmethod
40-
def _missing_(cls: type[RoborockEnum], key) -> RoborockEnum:
39+
def _missing_(cls: type[Self], key) -> Self:
4140
raise ValueError("%s not a valid key for Data Protocol", key)
4241

4342

0 commit comments

Comments
 (0)