2024-02-19 19:48:46 +00:00
|
|
|
"""Implementation of cloud module."""
|
2024-04-16 18:21:20 +00:00
|
|
|
|
2024-04-17 13:39:24 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2024-02-19 19:48:46 +00:00
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
2024-04-23 11:56:32 +00:00
|
|
|
from ...exceptions import SmartErrorCode
|
2024-04-24 16:38:52 +00:00
|
|
|
from ...feature import Feature
|
2024-02-19 19:48:46 +00:00
|
|
|
from ..smartmodule import SmartModule
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from ..smartdevice import SmartDevice
|
|
|
|
|
|
|
|
|
2024-05-11 18:28:18 +00:00
|
|
|
class Cloud(SmartModule):
|
2024-02-19 19:48:46 +00:00
|
|
|
"""Implementation of cloud module."""
|
|
|
|
|
|
|
|
QUERY_GETTER_NAME = "get_connect_cloud_state"
|
|
|
|
REQUIRED_COMPONENT = "cloud_connect"
|
|
|
|
|
2024-04-17 13:39:24 +00:00
|
|
|
def __init__(self, device: SmartDevice, module: str):
|
2024-02-19 19:48:46 +00:00
|
|
|
super().__init__(device, module)
|
|
|
|
|
|
|
|
self._add_feature(
|
|
|
|
Feature(
|
|
|
|
device,
|
2024-05-07 09:13:35 +00:00
|
|
|
id="cloud_connection",
|
|
|
|
name="Cloud connection",
|
2024-02-19 19:48:46 +00:00
|
|
|
container=self,
|
|
|
|
attribute_getter="is_connected",
|
|
|
|
icon="mdi:cloud",
|
2024-04-24 16:38:52 +00:00
|
|
|
type=Feature.Type.BinarySensor,
|
2024-05-07 09:13:35 +00:00
|
|
|
category=Feature.Category.Info,
|
2024-02-19 19:48:46 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_connected(self):
|
|
|
|
"""Return True if device is connected to the cloud."""
|
2024-04-23 11:56:32 +00:00
|
|
|
if isinstance(self.data, SmartErrorCode):
|
|
|
|
return False
|
2024-02-19 19:48:46 +00:00
|
|
|
return self.data["status"] == 0
|