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-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-07-11 15:21:59 +00:00
|
|
|
MINIMUM_UPDATE_INTERVAL_SECS = 60
|
2024-02-19 19:48:46 +00:00
|
|
|
|
2024-07-04 07:02:50 +00:00
|
|
|
def _post_update_hook(self):
|
|
|
|
"""Perform actions after a device update.
|
|
|
|
|
|
|
|
Overrides the default behaviour to disable a module if the query returns
|
|
|
|
an error because the logic here is to treat that as not connected.
|
|
|
|
"""
|
|
|
|
|
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-07-04 07:02:50 +00:00
|
|
|
if self._has_data_error():
|
2024-04-23 11:56:32 +00:00
|
|
|
return False
|
2024-02-19 19:48:46 +00:00
|
|
|
return self.data["status"] == 0
|