mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
Add smartdevice module for smooth transitions (#759)
* Add smart module for smooth transitions * Fix tests * Fix linting
This commit is contained in:
parent
11719991c0
commit
520b6bbae3
@ -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
kasa/smart/modules/lighttransitionmodule.py
Normal file
41
kasa/smart/modules/lighttransitionmodule.py
Normal file
@ -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}"
|
@ -16,6 +16,7 @@ from .modules import ( # noqa: F401
|
||||
ChildDeviceModule,
|
||||
DeviceModule,
|
||||
EnergyModule,
|
||||
LightTransitionModule,
|
||||
TimeModule,
|
||||
)
|
||||
from .smartmodule import SmartModule
|
||||
|
@ -46,6 +46,7 @@ class FakeSmartTransport(BaseTransport):
|
||||
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user