diff --git a/kasa/smart/modules/__init__.py b/kasa/smart/modules/__init__.py index 69a3c572..123435be 100644 --- a/kasa/smart/modules/__init__.py +++ b/kasa/smart/modules/__init__.py @@ -1,5 +1,6 @@ """Modules for SMART devices.""" from .childdevicemodule import ChildDeviceModule +from .cloudmodule import CloudModule from .devicemodule import DeviceModule from .energymodule import EnergyModule from .lighttransitionmodule import LightTransitionModule @@ -10,5 +11,6 @@ __all__ = [ "EnergyModule", "DeviceModule", "ChildDeviceModule", + "CloudModule", "LightTransitionModule", ] diff --git a/kasa/smart/modules/cloudmodule.py b/kasa/smart/modules/cloudmodule.py new file mode 100644 index 00000000..bf4964c3 --- /dev/null +++ b/kasa/smart/modules/cloudmodule.py @@ -0,0 +1,34 @@ +"""Implementation of cloud module.""" +from typing import TYPE_CHECKING + +from ...feature import Feature, FeatureType +from ..smartmodule import SmartModule + +if TYPE_CHECKING: + from ..smartdevice import SmartDevice + + +class CloudModule(SmartModule): + """Implementation of cloud module.""" + + QUERY_GETTER_NAME = "get_connect_cloud_state" + REQUIRED_COMPONENT = "cloud_connect" + + def __init__(self, device: "SmartDevice", module: str): + super().__init__(device, module) + + self._add_feature( + Feature( + device, + "Cloud connection", + container=self, + attribute_getter="is_connected", + icon="mdi:cloud", + type=FeatureType.BinarySensor, + ) + ) + + @property + def is_connected(self): + """Return True if device is connected to the cloud.""" + return self.data["status"] == 0 diff --git a/kasa/tests/fakeprotocol_smart.py b/kasa/tests/fakeprotocol_smart.py index 2945d167..210c63b9 100644 --- a/kasa/tests/fakeprotocol_smart.py +++ b/kasa/tests/fakeprotocol_smart.py @@ -46,6 +46,7 @@ class FakeSmartTransport(BaseTransport): FIXTURE_MISSING_MAP = { "get_wireless_scan_info": ("wireless", {"ap_list": [], "wep_supported": False}), + "get_connect_cloud_state": ("cloud_connect", {"status": 1}), "get_on_off_gradually_info": ("on_off_gradually", {"enable": True}), }