2021-11-07 01:41:12 +00:00
|
|
|
"""Cloud module implementation."""
|
2024-04-16 18:21:20 +00:00
|
|
|
|
2023-08-28 15:48:49 +00:00
|
|
|
try:
|
|
|
|
from pydantic.v1 import BaseModel
|
|
|
|
except ImportError:
|
|
|
|
from pydantic import BaseModel
|
2021-11-07 01:41:12 +00:00
|
|
|
|
2024-02-15 15:25:08 +00:00
|
|
|
from ...feature import Feature, FeatureType
|
2024-02-19 17:01:31 +00:00
|
|
|
from ..iotmodule import IotModule
|
2021-11-07 01:41:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CloudInfo(BaseModel):
|
|
|
|
"""Container for cloud settings."""
|
|
|
|
|
|
|
|
binded: bool
|
|
|
|
cld_connection: int
|
|
|
|
fwDlPage: str
|
|
|
|
fwNotifyType: int
|
|
|
|
illegalType: int
|
|
|
|
server: str
|
|
|
|
stopConnect: int
|
|
|
|
tcspInfo: str
|
|
|
|
tcspStatus: int
|
|
|
|
username: str
|
|
|
|
|
|
|
|
|
2024-02-04 15:20:08 +00:00
|
|
|
class Cloud(IotModule):
|
2021-11-07 01:41:12 +00:00
|
|
|
"""Module implementing support for cloud services."""
|
|
|
|
|
2024-02-15 15:25:08 +00:00
|
|
|
def __init__(self, device, module):
|
|
|
|
super().__init__(device, module)
|
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device=device,
|
|
|
|
container=self,
|
|
|
|
name="Cloud connection",
|
|
|
|
icon="mdi:cloud",
|
|
|
|
attribute_getter="is_connected",
|
|
|
|
type=FeatureType.BinarySensor,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_connected(self) -> bool:
|
|
|
|
"""Return true if device is connected to the cloud."""
|
|
|
|
return self.info.binded
|
|
|
|
|
2021-11-07 01:41:12 +00:00
|
|
|
def query(self):
|
|
|
|
"""Request cloud connectivity info."""
|
|
|
|
return self.query_for_command("get_info")
|
|
|
|
|
|
|
|
@property
|
|
|
|
def info(self) -> CloudInfo:
|
|
|
|
"""Return information about the cloud connectivity."""
|
|
|
|
return CloudInfo.parse_obj(self.data["get_info"])
|
|
|
|
|
|
|
|
def get_available_firmwares(self):
|
|
|
|
"""Return list of available firmwares."""
|
|
|
|
return self.query_for_command("get_intl_fw_list")
|
|
|
|
|
|
|
|
def set_server(self, url: str):
|
|
|
|
"""Set the update server URL."""
|
|
|
|
return self.query_for_command("set_server_url", {"server": url})
|
|
|
|
|
|
|
|
def connect(self, username: str, password: str):
|
|
|
|
"""Login to the cloud using given information."""
|
|
|
|
return self.query_for_command(
|
|
|
|
"bind", {"username": username, "password": password}
|
|
|
|
)
|
|
|
|
|
|
|
|
def disconnect(self):
|
|
|
|
"""Disconnect from the cloud."""
|
|
|
|
return self.query_for_command("unbind")
|