-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add smartdevice module for smooth transitions (#759)
* Add smart module for smooth transitions * Fix tests * Fix linting
- Loading branch information
Showing
4 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters