Skip to content

Commit e1dc545

Browse files
authored
fix: typing and versioning (#134)
* fix: change some typing * fix: include poetry lock * fix: linting * fix: linting
1 parent 1fc0265 commit e1dc545

File tree

8 files changed

+1301
-20
lines changed

8 files changed

+1301
-20
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ venv
33
.venv
44
.idea
55
roborock/__pycache__
6-
poetry.lock
76
*.pyc
87
.coverage
98

poetry.lock

Lines changed: 1280 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ construct = "^2.10.56"
3131

3232

3333
[build-system]
34-
requires = ["poetry-core==1.6.1"]
34+
requires = ["poetry-core==1.7.0"]
3535
build-backend = "poetry.core.masonry.api"
3636

3737
[tool.poetry.group.dev.dependencies]

roborock/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def _async_response(
348348

349349
def _get_payload(
350350
self,
351-
method: RoborockCommand,
351+
method: RoborockCommand | str,
352352
params: list | dict | None = None,
353353
secured=False,
354354
):
@@ -380,15 +380,15 @@ async def send_message(self, roborock_message: RoborockMessage):
380380

381381
async def _send_command(
382382
self,
383-
method: RoborockCommand,
383+
method: RoborockCommand | str,
384384
params: list | dict | None = None,
385385
):
386386
raise NotImplementedError
387387

388388
@final
389389
async def send_command(
390390
self,
391-
method: RoborockCommand,
391+
method: RoborockCommand | str,
392392
params: list | dict | None = None,
393393
return_type: type[RT] | None = None,
394394
) -> RT:

roborock/cloud_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ async def send_message(self, roborock_message: RoborockMessage):
198198

199199
async def _send_command(
200200
self,
201-
method: RoborockCommand,
201+
method: RoborockCommand | str,
202202
params: list | dict | None = None,
203203
):
204204
request_id, timestamp, payload = super()._get_payload(method, params, True)

roborock/command_cache.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ def get_change_commands(attr: RoborockAttribute) -> list[RoborockCommand]:
168168
return [command for command in commands if command is not None]
169169

170170

171-
cache_map_by_get_command: dict[RoborockCommand, CacheableAttribute] = {
171+
cache_map_by_get_command: dict[RoborockCommand | str, CacheableAttribute] = {
172172
attribute.get_command: cacheable_attribute for cacheable_attribute, attribute in cache_map.items()
173173
}
174174

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

197197

198-
def find_cacheable_attribute(method: RoborockCommand) -> CacheableAttributeResult | None:
198+
def find_cacheable_attribute(method: RoborockCommand | str) -> CacheableAttributeResult | None:
199199
if method is None:
200200
return None
201201

roborock/containers.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import datetime
44
import logging
55
import re
6-
from dataclasses import asdict, dataclass
6+
from dataclasses import asdict, dataclass, field
77
from datetime import timezone
88
from enum import Enum
99
from typing import Any, NamedTuple
@@ -168,10 +168,10 @@ class HomeDataProductSchema(RoborockBase):
168168

169169
@dataclass
170170
class HomeDataProduct(RoborockBase):
171-
id: str | None = None
172-
name: str | None = None
171+
id: str
172+
name: str
173+
model: str
173174
code: str | None = None
174-
model: str | None = None
175175
iconurl: str | None = None
176176
attribute: Any | None = None
177177
capability: int | None = None
@@ -216,14 +216,14 @@ class HomeDataRoom(RoborockBase):
216216

217217
@dataclass
218218
class HomeData(RoborockBase):
219-
id: int | None = None
220-
name: str | None = None
219+
id: int
220+
name: str
221+
products: list[HomeDataProduct] = field(default_factory=lambda: [])
222+
devices: list[HomeDataDevice] = field(default_factory=lambda: [])
223+
received_devices: list[HomeDataDevice] = field(default_factory=lambda: [])
221224
lon: Any | None = None
222225
lat: Any | None = None
223226
geo_name: Any | None = None
224-
products: list[HomeDataProduct] | None = None
225-
devices: list[HomeDataDevice] | None = None
226-
received_devices: list[HomeDataDevice] | None = None
227227
rooms: list[HomeDataRoom] | None = None
228228

229229
def get_all_devices(self) -> list[HomeDataDevice]:

roborock/local_api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ async def async_disconnect(self) -> None:
8282
async with self._mutex:
8383
self.sync_disconnect()
8484

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

121123
async def _send_command(
122124
self,
123-
method: RoborockCommand,
125+
method: RoborockCommand | str,
124126
params: list | dict | None = None,
125127
):
126128
roborock_message = self.build_roborock_message(method, params)

0 commit comments

Comments
 (0)