-
-
Notifications
You must be signed in to change notification settings - Fork 270
Refactor devices into subpackages and deprecate old names #716
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
20 commits
Select commit
Hold shift + click to select a range
70c94c6
Refactor devices into subpackages and deprecate old names
sdb9696 5f7ab52
Tweak and add tests
sdb9696 963e9f5
Fix linting
sdb9696 43cc26b
Remove duplicate implementations affecting project coverage
sdb9696 c451a8e
Merge remote-tracking branch 'upstream/master' into refactor_sub_pack…
sdb9696 a2eb7e3
Merge remote-tracking branch 'upstream/master' into refactor_sub_pack…
sdb9696 bcac3d3
Merge latest master including childdevice and test framework changes
sdb9696 435bb39
Update post review
sdb9696 e66be94
Merge remote-tracking branch 'upstream/master' into refactor_sub_pack…
sdb9696 7517d0a
Add device base class attributes and rename subclasses
sdb9696 b455c46
Rename Module to BaseModule
sdb9696 3dee032
Remove has_emeter_history
sdb9696 3743333
Merge remote-tracking branch 'upstream/master' into refactor_sub_pack…
sdb9696 887ff40
Fix missing _time in init
sdb9696 cf1e75d
Update post review
sdb9696 b44c0c8
Fix test_readmeexamples
sdb9696 b14bf70
Fix erroneously duped files
sdb9696 2845bf0
Clean up iot and smart imports
sdb9696 ccd5078
Update post latest review
sdb9696 f8d4157
Tweak Device docstring
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| """Module for Device base class.""" | ||
| from abc import ABC, abstractmethod | ||
| from typing import Dict, List, NamedTuple, Optional | ||
|
|
||
| from .device import Device | ||
|
|
||
| try: | ||
| from pydantic.v1 import BaseModel | ||
| except ImportError: | ||
| from pydantic import BaseModel | ||
|
|
||
|
|
||
| class ColorTempRange(NamedTuple): | ||
| """Color temperature range.""" | ||
|
|
||
| min: int | ||
| max: int | ||
|
|
||
|
|
||
| class HSV(NamedTuple): | ||
| """Hue-saturation-value.""" | ||
|
|
||
| hue: int | ||
| saturation: int | ||
| value: int | ||
|
|
||
|
|
||
| class BulbPreset(BaseModel): | ||
| """Bulb configuration preset.""" | ||
|
|
||
| index: int | ||
| brightness: int | ||
|
|
||
| # These are not available for effect mode presets on light strips | ||
| hue: Optional[int] | ||
| saturation: Optional[int] | ||
| color_temp: Optional[int] | ||
|
|
||
| # Variables for effect mode presets | ||
| custom: Optional[int] | ||
| id: Optional[str] | ||
| mode: Optional[int] | ||
|
|
||
|
|
||
| class Bulb(Device, ABC): | ||
| """Base class for TP-Link Bulb.""" | ||
|
|
||
| def _raise_for_invalid_brightness(self, value): | ||
| if not isinstance(value, int) or not (0 <= value <= 100): | ||
| raise ValueError(f"Invalid brightness value: {value} (valid range: 0-100%)") | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def is_color(self) -> bool: | ||
| """Whether the bulb supports color changes.""" | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def is_dimmable(self) -> bool: | ||
| """Whether the bulb supports brightness changes.""" | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def is_variable_color_temp(self) -> bool: | ||
| """Whether the bulb supports color temperature changes.""" | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def valid_temperature_range(self) -> ColorTempRange: | ||
| """Return the device-specific white temperature range (in Kelvin). | ||
|
|
||
| :return: White temperature range in Kelvin (minimum, maximum) | ||
| """ | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def has_effects(self) -> bool: | ||
| """Return True if the device supports effects.""" | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def hsv(self) -> HSV: | ||
| """Return the current HSV state of the bulb. | ||
|
|
||
| :return: hue, saturation and value (degrees, %, %) | ||
| """ | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def color_temp(self) -> int: | ||
| """Whether the bulb supports color temperature changes.""" | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def brightness(self) -> int: | ||
| """Return the current brightness in percentage.""" | ||
|
|
||
| @abstractmethod | ||
| async def set_hsv( | ||
| self, | ||
| hue: int, | ||
| saturation: int, | ||
| value: Optional[int] = None, | ||
| *, | ||
| transition: Optional[int] = None, | ||
| ) -> Dict: | ||
| """Set new HSV. | ||
|
|
||
| Note, transition is not supported and will be ignored. | ||
|
|
||
| :param int hue: hue in degrees | ||
| :param int saturation: saturation in percentage [0,100] | ||
| :param int value: value in percentage [0, 100] | ||
| :param int transition: transition in milliseconds. | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| async def set_color_temp( | ||
| self, temp: int, *, brightness=None, transition: Optional[int] = None | ||
| ) -> Dict: | ||
| """Set the color temperature of the device in kelvin. | ||
|
|
||
| Note, transition is not supported and will be ignored. | ||
|
|
||
| :param int temp: The new color temperature, in Kelvin | ||
| :param int transition: transition in milliseconds. | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| async def set_brightness( | ||
| self, brightness: int, *, transition: Optional[int] = None | ||
| ) -> Dict: | ||
| """Set the brightness in percentage. | ||
|
|
||
| Note, transition is not supported and will be ignored. | ||
|
|
||
| :param int brightness: brightness in percent | ||
| :param int transition: transition in milliseconds. | ||
| """ | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def presets(self) -> List[BulbPreset]: | ||
| """Return a list of available bulb setting presets.""" |
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.