-
-
Notifications
You must be signed in to change notification settings - Fork 238
Create common interfaces for remaining device types #895
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
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6e0d0d6
Create interfaces for remaining device types
sdb9696 46a4a27
Simplify interfaces
sdb9696 036f413
Merge remote-tracking branch 'upstream/master' into feat/add_interfaces
sdb9696 3ec9096
Fix non python 3.8 compatible set_led
sdb9696 7bf8753
Add common module interfaces
sdb9696 bbaf51e
Merge remote-tracking branch 'upstream/master' into feat/add_interfaces
sdb9696 ed56937
Add LightEffect feature tests
sdb9696 4100655
Cleanup a few leftovers
sdb9696 7f6eac2
Make modules dictionary support typed get and get_item (#908)
sdb9696 f2557f4
Merge remote-tracking branch 'upstream/master' into feat/add_interfaces
sdb9696 532458a
Move contribution instructions into docs (#901)
rytilahti c67a5be
Improve smartdevice update module (#791)
rytilahti ccdd38e
Fix test_firmware test
sdb9696 e386370
Merge remote-tracking branch 'upstream/feat/add_interfaces' into feat…
sdb9696 5dc6a70
Rename interfaces to remove interface suffix
sdb9696 8ed6c7a
Rename interface files
sdb9696 76bc0f0
Fix python 3.8 subscriptable type in cast
sdb9696 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,38 @@ | ||
| """Module for base light effect module.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from abc import ABC, abstractmethod | ||
|
|
||
| from ..feature import Feature | ||
| from ..module import Module | ||
|
|
||
|
|
||
| class Led(Module, ABC): | ||
| """Base interface to represent a LED module.""" | ||
|
|
||
| def _initialize_features(self): | ||
| """Initialize features.""" | ||
| device = self._device | ||
| self._add_feature( | ||
| Feature( | ||
| device=device, | ||
| container=self, | ||
| name="LED", | ||
| id="led", | ||
| icon="mdi:led", | ||
| attribute_getter="led", | ||
| attribute_setter="set_led", | ||
| type=Feature.Type.Switch, | ||
| category=Feature.Category.Config, | ||
| ) | ||
| ) | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def led(self) -> bool: | ||
| """Return current led status.""" | ||
|
|
||
| @abstractmethod | ||
| async def set_led(self, enable: bool) -> None: | ||
| """Set led.""" |
This file contains hidden or 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,80 @@ | ||
| """Module for base light effect module.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from abc import ABC, abstractmethod | ||
|
|
||
| from ..feature import Feature | ||
| from ..module import Module | ||
|
|
||
|
|
||
| class LightEffect(Module, ABC): | ||
| """Interface to represent a light effect module.""" | ||
|
|
||
| LIGHT_EFFECTS_OFF = "Off" | ||
|
|
||
| def _initialize_features(self): | ||
| """Initialize features.""" | ||
| device = self._device | ||
| self._add_feature( | ||
| Feature( | ||
| device, | ||
| id="light_effect", | ||
| name="Light effect", | ||
| container=self, | ||
| attribute_getter="effect", | ||
| attribute_setter="set_effect", | ||
| category=Feature.Category.Primary, | ||
| type=Feature.Type.Choice, | ||
| choices_getter="effect_list", | ||
| ) | ||
| ) | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def has_custom_effects(self) -> bool: | ||
| """Return True if the device supports setting custom effects.""" | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def effect(self) -> str: | ||
| """Return effect state or name.""" | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def effect_list(self) -> list[str]: | ||
| """Return built-in effects list. | ||
|
|
||
| Example: | ||
| ['Aurora', 'Bubbling Cauldron', ...] | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| async def set_effect( | ||
| self, | ||
| effect: str, | ||
| *, | ||
| brightness: int | None = None, | ||
| transition: int | None = None, | ||
| ) -> None: | ||
| """Set an effect on the device. | ||
|
|
||
| If brightness or transition is defined, | ||
| its value will be used instead of the effect-specific default. | ||
|
|
||
| See :meth:`effect_list` for available effects, | ||
| or use :meth:`set_custom_effect` for custom effects. | ||
|
|
||
| :param str effect: The effect to set | ||
| :param int brightness: The wanted brightness | ||
| :param int transition: The wanted transition time | ||
| """ | ||
|
|
||
| async def set_custom_effect( | ||
| self, | ||
| effect_dict: dict, | ||
| ) -> None: | ||
| """Set a custom effect on the device. | ||
|
|
||
| :param str effect_dict: The custom effect dict to set | ||
| """ |
File renamed without changes.
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.