Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: typing and versioning #134

Merged
merged 4 commits into from
Oct 29, 2023
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ venv
.venv
.idea
roborock/__pycache__
poetry.lock
*.pyc
.coverage

Expand Down
1,280 changes: 1,280 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ construct = "^2.10.56"


[build-system]
requires = ["poetry-core==1.6.1"]
requires = ["poetry-core==1.7.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.group.dev.dependencies]
Expand Down
6 changes: 3 additions & 3 deletions roborock/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def _async_response(

def _get_payload(
self,
method: RoborockCommand,
method: RoborockCommand | str,
params: list | dict | None = None,
secured=False,
):
Expand Down Expand Up @@ -377,15 +377,15 @@ async def send_message(self, roborock_message: RoborockMessage):

async def _send_command(
self,
method: RoborockCommand,
method: RoborockCommand | str,
params: list | dict | None = None,
):
raise NotImplementedError

@final
async def send_command(
self,
method: RoborockCommand,
method: RoborockCommand | str,
params: list | dict | None = None,
return_type: type[RT] | None = None,
) -> RT:
Expand Down
2 changes: 1 addition & 1 deletion roborock/cloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ async def send_message(self, roborock_message: RoborockMessage):

async def _send_command(
self,
method: RoborockCommand,
method: RoborockCommand | str,
params: list | dict | None = None,
):
request_id, timestamp, payload = super()._get_payload(method, params, True)
Expand Down
6 changes: 3 additions & 3 deletions roborock/command_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ def get_change_commands(attr: RoborockAttribute) -> list[RoborockCommand]:
return [command for command in commands if command is not None]


cache_map_by_get_command: dict[RoborockCommand, CacheableAttribute] = {
cache_map_by_get_command: dict[RoborockCommand | str, CacheableAttribute] = {
attribute.get_command: cacheable_attribute for cacheable_attribute, attribute in cache_map.items()
}

cache_map_by_change_command: dict[RoborockCommand, CacheableAttribute] = {
cache_map_by_change_command: dict[RoborockCommand | str, CacheableAttribute] = {
command: cacheable_attribute
for cacheable_attribute, attribute in cache_map.items()
for command in get_change_commands(attribute)
Expand All @@ -195,7 +195,7 @@ class CacheableAttributeResult:
type: CommandType


def find_cacheable_attribute(method: RoborockCommand) -> CacheableAttributeResult | None:
def find_cacheable_attribute(method: RoborockCommand | str) -> CacheableAttributeResult | None:
if method is None:
return None

Expand Down
18 changes: 9 additions & 9 deletions roborock/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime
import logging
import re
from dataclasses import asdict, dataclass
from dataclasses import asdict, dataclass, field
from datetime import timezone
from enum import Enum
from typing import Any, NamedTuple
Expand Down Expand Up @@ -168,10 +168,10 @@ class HomeDataProductSchema(RoborockBase):

@dataclass
class HomeDataProduct(RoborockBase):
id: str | None = None
name: str | None = None
id: str
name: str
model: str
code: str | None = None
model: str | None = None
iconurl: str | None = None
attribute: Any | None = None
capability: int | None = None
Expand Down Expand Up @@ -216,14 +216,14 @@ class HomeDataRoom(RoborockBase):

@dataclass
class HomeData(RoborockBase):
id: int | None = None
name: str | None = None
id: int
name: str
products: list[HomeDataProduct] = field(default_factory=lambda: [])
devices: list[HomeDataDevice] = field(default_factory=lambda: [])
received_devices: list[HomeDataDevice] = field(default_factory=lambda: [])
lon: Any | None = None
lat: Any | None = None
geo_name: Any | None = None
products: list[HomeDataProduct] | None = None
devices: list[HomeDataDevice] | None = None
received_devices: list[HomeDataDevice] | None = None
rooms: list[HomeDataRoom] | None = None

def get_all_devices(self) -> list[HomeDataDevice]:
Expand Down
6 changes: 4 additions & 2 deletions roborock/local_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ async def async_disconnect(self) -> None:
async with self._mutex:
self.sync_disconnect()

def build_roborock_message(self, method: RoborockCommand, params: list | dict | None = None) -> RoborockMessage:
def build_roborock_message(
self, method: RoborockCommand | str, params: list | dict | None = None
) -> RoborockMessage:
secured = True if method in COMMANDS_SECURED else False
request_id, timestamp, payload = self._get_payload(method, params, secured)
request_protocol = RoborockMessageProtocol.GENERAL_REQUEST
Expand Down Expand Up @@ -120,7 +122,7 @@ async def ping(self):

async def _send_command(
self,
method: RoborockCommand,
method: RoborockCommand | str,
params: list | dict | None = None,
):
roborock_message = self.build_roborock_message(method, params)
Expand Down