mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
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.
This commit is contained in:
parent
df48c21900
commit
5eca487bcb
@ -1,23 +1,28 @@
|
|||||||
"""Cloud module implementation."""
|
"""Cloud module implementation."""
|
||||||
|
|
||||||
from pydantic.v1 import BaseModel
|
from dataclasses import dataclass
|
||||||
|
from typing import Annotated
|
||||||
|
|
||||||
|
from mashumaro import DataClassDictMixin
|
||||||
|
from mashumaro.types import Alias
|
||||||
|
|
||||||
from ...feature import Feature
|
from ...feature import Feature
|
||||||
from ..iotmodule import IotModule
|
from ..iotmodule import IotModule
|
||||||
|
|
||||||
|
|
||||||
class CloudInfo(BaseModel):
|
@dataclass
|
||||||
|
class CloudInfo(DataClassDictMixin):
|
||||||
"""Container for cloud settings."""
|
"""Container for cloud settings."""
|
||||||
|
|
||||||
binded: bool
|
provisioned: Annotated[int, Alias("binded")]
|
||||||
cld_connection: int
|
cloud_connected: Annotated[int, Alias("cld_connection")]
|
||||||
fwDlPage: str
|
firmware_download_page: Annotated[str, Alias("fwDlPage")]
|
||||||
fwNotifyType: int
|
firmware_notify_type: Annotated[int, Alias("fwNotifyType")]
|
||||||
illegalType: int
|
illegal_type: Annotated[int, Alias("illegalType")]
|
||||||
server: str
|
server: str
|
||||||
stopConnect: int
|
stop_connect: Annotated[int, Alias("stopConnect")]
|
||||||
tcspInfo: str
|
tcsp_info: Annotated[str, Alias("tcspInfo")]
|
||||||
tcspStatus: int
|
tcsp_status: Annotated[int, Alias("tcspStatus")]
|
||||||
username: str
|
username: str
|
||||||
|
|
||||||
|
|
||||||
@ -42,7 +47,7 @@ class Cloud(IotModule):
|
|||||||
@property
|
@property
|
||||||
def is_connected(self) -> bool:
|
def is_connected(self) -> bool:
|
||||||
"""Return true if device is connected to the cloud."""
|
"""Return true if device is connected to the cloud."""
|
||||||
return self.info.binded
|
return bool(self.info.cloud_connected)
|
||||||
|
|
||||||
def query(self) -> dict:
|
def query(self) -> dict:
|
||||||
"""Request cloud connectivity info."""
|
"""Request cloud connectivity info."""
|
||||||
@ -51,7 +56,7 @@ class Cloud(IotModule):
|
|||||||
@property
|
@property
|
||||||
def info(self) -> CloudInfo:
|
def info(self) -> CloudInfo:
|
||||||
"""Return information about the cloud connectivity."""
|
"""Return information about the cloud connectivity."""
|
||||||
return CloudInfo.parse_obj(self.data["get_info"])
|
return CloudInfo.from_dict(self.data["get_info"])
|
||||||
|
|
||||||
def get_available_firmwares(self) -> dict:
|
def get_available_firmwares(self) -> dict:
|
||||||
"""Return list of available firmwares."""
|
"""Return list of available firmwares."""
|
||||||
|
@ -125,6 +125,7 @@ CLOUD_MODULE = {
|
|||||||
"username": "",
|
"username": "",
|
||||||
"server": "devs.tplinkcloud.com",
|
"server": "devs.tplinkcloud.com",
|
||||||
"binded": 0,
|
"binded": 0,
|
||||||
|
"err_code": 0,
|
||||||
"cld_connection": 0,
|
"cld_connection": 0,
|
||||||
"illegalType": -1,
|
"illegalType": -1,
|
||||||
"stopConnect": -1,
|
"stopConnect": -1,
|
||||||
|
13
tests/iot/modules/test_cloud.py
Normal file
13
tests/iot/modules/test_cloud.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
from kasa import Device, Module
|
||||||
|
|
||||||
|
from ...device_fixtures import device_iot
|
||||||
|
|
||||||
|
|
||||||
|
@device_iot
|
||||||
|
def test_cloud(dev: Device):
|
||||||
|
cloud = dev.modules.get(Module.IotCloud)
|
||||||
|
assert cloud
|
||||||
|
info = cloud.info
|
||||||
|
assert info
|
||||||
|
assert isinstance(info.provisioned, int)
|
||||||
|
assert cloud.is_connected == bool(info.cloud_connected)
|
Loading…
Reference in New Issue
Block a user