Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions roborock/broadcast_protocol.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import asyncio
import hashlib
import json
Expand Down
14 changes: 6 additions & 8 deletions roborock/data/code_mappings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import logging
from collections import namedtuple
from enum import Enum, IntEnum, StrEnum
Expand All @@ -17,7 +15,7 @@ def name(self) -> str:
return super().name.lower()

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

@classmethod
def as_dict(cls: type[RoborockEnum]):
def as_dict(cls: type[Self]):
return {i.name: i.value for i in cls if i.name != "missing"}

@classmethod
def as_enum_dict(cls: type[RoborockEnum]):
def as_enum_dict(cls: type[Self]):
return {i.value: i for i in cls if i.name != "missing"}

@classmethod
def values(cls: type[RoborockEnum]) -> list[int]:
def values(cls: type[Self]) -> list[int]:
return list(cls.as_dict().values())

@classmethod
def keys(cls: type[RoborockEnum]) -> list[str]:
def keys(cls: type[Self]) -> list[str]:
return list(cls.as_dict().keys())

@classmethod
def items(cls: type[RoborockEnum]):
def items(cls: type[Self]):
return cls.as_dict().items()


Expand Down
4 changes: 3 additions & 1 deletion roborock/data/v1/v1_code_mappings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Self

from ..code_mappings import RoborockEnum


Expand Down Expand Up @@ -91,7 +93,7 @@ class RoborockStartType(RoborockEnum):

class RoborockDssCodes(RoborockEnum):
@classmethod
def _missing_(cls: type[RoborockEnum], key) -> RoborockEnum:
def _missing_(cls: type[Self], key) -> Self:
# If the calculated value is not provided, then it should be viewed as okay.
# As the math will sometimes result in you getting numbers that don't matter.
return cls.okay # type: ignore
Expand Down
6 changes: 2 additions & 4 deletions roborock/device_features.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from __future__ import annotations

from dataclasses import dataclass, field, fields
from enum import IntEnum, StrEnum
from typing import Any
from typing import Any, Self

from roborock.data.code_mappings import RoborockProductNickname
from roborock.data.containers import RoborockBase
Expand Down Expand Up @@ -566,7 +564,7 @@ def from_feature_flags(
new_feature_info_str: str,
feature_info: list[int],
product_nickname: RoborockProductNickname | None,
) -> DeviceFeatures:
) -> Self:
"""Creates a DeviceFeatures instance from raw feature flags.
:param new_feature_info: A int from get_init_status (sometimes can be found in homedata, but it is not always)
:param new_feature_info_str: A hex string from get_init_status or home_data.
Expand Down
2 changes: 0 additions & 2 deletions roborock/devices/rpc/b01_q10_channel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Thin wrapper around the MQTT channel for Roborock B01 Q10 devices."""

from __future__ import annotations

import logging
from collections.abc import AsyncGenerator
from typing import Any
Expand Down
2 changes: 0 additions & 2 deletions roborock/devices/traits/b01/q7/clean_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
and a `record_list` whose items contain a JSON string in `detail`.
"""

from __future__ import annotations

import logging

from roborock import CleanRecordDetail, CleanRecordList, CleanRecordSummary
Expand Down
2 changes: 0 additions & 2 deletions roborock/devices/traits/v1/network_info.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Trait for device network information."""

from __future__ import annotations

import logging

from roborock.data import NetworkInfo
Expand Down
10 changes: 4 additions & 6 deletions roborock/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
DeviceManager.
"""

from __future__ import annotations

import time
from collections import Counter
from collections.abc import Generator, Mapping
from contextlib import contextmanager
from typing import Any, TypeVar, cast
from typing import Any, Self, TypeVar, cast


class Diagnostics:
Expand All @@ -28,7 +26,7 @@ class Diagnostics:
def __init__(self) -> None:
"""Initialize Diagnostics."""
self._counter: Counter = Counter()
self._subkeys: dict[str, Diagnostics] = {}
self._subkeys: dict[str, Self] = {}

def increment(self, key: str, count: int = 1) -> None:
"""Increment a counter for the specified key/event."""
Expand All @@ -49,7 +47,7 @@ def as_dict(self) -> Mapping[str, Any]:
data[k] = v
return data

def subkey(self, key: str) -> Diagnostics:
def subkey(self, key: str) -> Self:
"""Return sub-Diagnostics object with the specified subkey.

This will create a new Diagnostics object if one does not already exist
Expand All @@ -63,7 +61,7 @@ def subkey(self, key: str) -> Diagnostics:
The Diagnostics object for the specified subkey.
"""
if key not in self._subkeys:
self._subkeys[key] = Diagnostics()
self._subkeys[key] = type(self)()
return self._subkeys[key]

@contextmanager
Expand Down
2 changes: 0 additions & 2 deletions roborock/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Roborock exceptions."""

from __future__ import annotations


class RoborockException(Exception):
"""Class for Roborock exceptions."""
Expand Down
2 changes: 0 additions & 2 deletions roborock/protocol.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import binascii
import gzip
import hashlib
Expand Down
7 changes: 3 additions & 4 deletions roborock/roborock_message.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

from dataclasses import dataclass, field
from enum import StrEnum
from typing import Self

from roborock import RoborockEnum
from roborock.util import get_next_int, get_timestamp
Expand Down Expand Up @@ -37,8 +36,8 @@ class RoborockDataProtocol(RoborockEnum):
OFFLINE_STATUS = 135

@classmethod
def _missing_(cls: type[RoborockEnum], key) -> RoborockEnum:
raise ValueError("%s not a valid key for Data Protocol", key)
def _missing_(cls: type[Self], key) -> Self:
raise ValueError(f"{key} not a valid key for Data Protocol")


class RoborockDyadDataProtocol(RoborockEnum):
Expand Down
5 changes: 2 additions & 3 deletions roborock/roborock_typing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

from dataclasses import dataclass, field
from enum import Enum, StrEnum
from typing import Self

from .data import (
CleanRecord,
Expand Down Expand Up @@ -368,7 +367,7 @@ def __post_init__(self) -> None:
):
self.dust_collection_mode_name = self.dock_summary.dust_collection_mode.mode.name

def update(self, device_prop: DeviceProp) -> None:
def update(self, device_prop: Self) -> None:
if device_prop.status:
self.status = device_prop.status
if device_prop.clean_summary:
Expand Down
2 changes: 0 additions & 2 deletions roborock/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import logging
import math
import time
Expand Down
2 changes: 0 additions & 2 deletions roborock/web_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import base64
import hashlib
import hmac
Expand Down
Loading