Add cloud module for smartdevice (#767)

Add initial support for the cloud module.

Adds a new binary sensor: `Cloud connection (cloud_connection): False`
This commit is contained in:
Teemu R 2024-02-19 20:48:46 +01:00 committed by GitHub
parent 520b6bbae3
commit f5175c5632
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 0 deletions

View File

@ -1,5 +1,6 @@
"""Modules for SMART devices.""" """Modules for SMART devices."""
from .childdevicemodule import ChildDeviceModule from .childdevicemodule import ChildDeviceModule
from .cloudmodule import CloudModule
from .devicemodule import DeviceModule from .devicemodule import DeviceModule
from .energymodule import EnergyModule from .energymodule import EnergyModule
from .lighttransitionmodule import LightTransitionModule from .lighttransitionmodule import LightTransitionModule
@ -10,5 +11,6 @@ __all__ = [
"EnergyModule", "EnergyModule",
"DeviceModule", "DeviceModule",
"ChildDeviceModule", "ChildDeviceModule",
"CloudModule",
"LightTransitionModule", "LightTransitionModule",
] ]

View File

@ -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

View File

@ -46,6 +46,7 @@ class FakeSmartTransport(BaseTransport):
FIXTURE_MISSING_MAP = { FIXTURE_MISSING_MAP = {
"get_wireless_scan_info": ("wireless", {"ap_list": [], "wep_supported": False}), "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}), "get_on_off_gradually_info": ("on_off_gradually", {"enable": True}),
} }