Add smartdevice module for smooth transitions (#759)

* Add smart module for smooth transitions

* Fix tests

* Fix linting
This commit is contained in:
Teemu R 2024-02-19 20:39:20 +01:00 committed by GitHub
parent 11719991c0
commit 520b6bbae3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 51 additions and 1 deletions

View File

@ -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",
]

View 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}"

View File

@ -16,6 +16,7 @@ from .modules import ( # noqa: F401
ChildDeviceModule,
DeviceModule,
EnergyModule,
LightTransitionModule,
TimeModule,
)
from .smartmodule import SmartModule

View File

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