8000 Add cloud module for smartdevice by rytilahti · Pull Request #767 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

Add cloud module for smartdevice #767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 19, 2024
2 changes: 2 additions & 0 deletions kasa/smart/modules/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,5 +11,6 @@
"EnergyModule",
"DeviceModule",
"ChildDeviceModule",
"CloudModule",
"LightTransitionModule",
]
34 changes: 34 additions & 0 deletions kasa/smart/modules/cloudmodule.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions kasa/tests/fakeprotocol_smart.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def credentials_hash(self):

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}),
}

Expand Down
0