Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion kasa/smart/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
from .childdevicemodule import ChildDeviceModule
from .devicemodule import DeviceModule
from .energymodule import EnergyModule
from .lighttransitionmodule import LightTransitionModule
from .timemodule import TimeModule

__all__ = ["TimeModule", "EnergyModule", "DeviceModule", "ChildDeviceModule"]
__all__ = [
"TimeModule",
"EnergyModule",
"DeviceModule",
"ChildDeviceModule",
"LightTransitionModule",
]
41 changes: 41 additions & 0 deletions kasa/smart/modules/lighttransitionmodule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Module for smooth light transitions."""
from typing import TYPE_CHECKING

from ...feature import Feature, FeatureType
from ..smartmodule import SmartModule

if TYPE_CHECKING:
from ..smartdevice import SmartDevice


class LightTransitionModule(SmartModule):
"""Implementation of gradual on/off."""

REQUIRED_COMPONENT = "on_off_gradually"
QUERY_GETTER_NAME = "get_on_off_gradually_info"

def __init__(self, device: "SmartDevice", module: str):
super().__init__(device, module)
self._add_feature(
Feature(
device=device,
container=self,
name="Smooth transitions",
icon="mdi:transition",
attribute_getter="enabled",
attribute_setter="set_enabled",
type=FeatureType.Switch,
)
)

def set_enabled(self, enable: bool):
"""Enable gradual on/off."""
return self.call("set_on_off_gradually_info", {"enable": enable})

@property
def enabled(self) -> bool:
"""Return True if gradual on/off is enabled."""
return bool(self.data["enable"])

def __cli_output__(self):
return f"Gradual on/off enabled: {self.enabled}"
1 change: 1 addition & 0 deletions kasa/smart/smartdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
ChildDeviceModule,
DeviceModule,
EnergyModule,
LightTransitionModule,
TimeModule,
)
from .smartmodule import SmartModule
Expand Down
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_on_off_gradually_info": ("on_off_gradually", {"enable": True}),
}

async def send(self, request: str):
Expand Down