8000 Migrate iot cloud module to mashumaro (#1282) · python-kasa/python-kasa@5eca487 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5eca487

Browse files
authored
Migrate iot cloud module to mashumaro (#1282)
Breaking change as the CloudInfo interface is changing to snake case for consistency with the rest of the library.
1 parent df48c21 commit 5eca487

File tree

3 files changed

+31
-12
lines 8000 changed

3 files changed

+31
-12
lines changed

kasa/iot/modules/cloud.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
"""Cloud module implementation."""
22

3-
from pydantic.v1 import BaseModel
3+
from dataclasses import dataclass
4+
from typing import Annotated
5+
6+
from mashumaro import DataClassDictMixin
7+
from mashumaro.types import Alias
48

59
from ...feature import Feature
610
from ..iotmodule import IotModule
711

812

9-
class CloudInfo(BaseModel):
13+
@dataclass
14+
class CloudInfo(DataClassDictMixin):
1015
"""Container for cloud settings."""
1116

12-
binded: bool
13-
cld_connection: int
14-
fwDlPage: str
15-
fwNotifyType: int
16-
illegalType: int
17+
provisioned: Annotated[int, Alias("binded")]
18+
cloud_connected: Annotated[int, Alias("cld_connection")]
19+
firmware_download_page: Annotated[str, Alias("fwDlPage")]
20+
firmware_notify_type: Annotated[int, Alias("fwNotifyType")]
21+
illegal_type: Annotated[int, Alias("illegalType")]
1722
server: str
18-
stopConnect: int
19-
tcspInfo: str
20-
tcspStatus: int
23+
stop_connect: Annotated[int, Alias("stopConnect")]
24+
tcsp_info: Annotated[str, Alias("tcspInfo")]
25+
tcsp_status: Annotated[int, Alias("tcspStatus")]
2126
username: str
2227

2328

@@ -42,7 +47,7 @@ def _initialize_features(self) -> None:
4247
@property
4348
def is_connected(self) -> bool:
4449
"""Return true if device is connected to the cloud."""
45-
return self.info.binded
50+
return bool(self.info.cloud_connected)
4651

4752
def query(self) -> dict:
4853
"""Request cloud connectivity info."""
@@ -51,7 +56,7 @@ def query(self) -> dict:
5156
@property
5257
def info(self) -> CloudInfo:
5358
"""Return information about the cloud connectivity."""
54-
return CloudInfo.parse_obj(self.data["get_info"])
59+
return CloudInfo.from_dict(self.data["get_info"])
5560

5661
def get_available_firmwares(self) -> dict:
5762
"""Return list of available firmwares."""

tests/fakeprotocol_iot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def success(res):
125125
"username": "",
126126
"server": "devs.tplinkcloud.com",
127127
"binded": 0,
128+
"err_code": 0,
128129
"cld_connection": 0,
129130
"illegalType": -1,
130131
"stopConnect": -1,

tests/iot/modules/test_cloud.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from kasa import Device, Module
2+
3+
from ...device_fixtures import device_iot
4+
5+
6+
@device_iot
7+
def test_cloud(dev: Device):
8+
cloud = dev.modules.get(Module.IotCloud)
9+
assert cloud
10+
info = cloud.info
11+
assert info
12+
assert isinstance(info.provisioned, int)
13+
assert cloud.is_connected == bool(info.cloud_connected)

0 commit comments

Comments
 (0)
0