| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| """Implementation of brightness module.""" | ||
| from typing import TYPE_CHECKING, Dict | ||
|
|
||
| from ...feature import Feature, FeatureType | ||
| from ..smartmodule import SmartModule | ||
|
|
||
| if TYPE_CHECKING: | ||
| from ..smartdevice import SmartDevice | ||
|
|
||
|
|
||
| class Brightness(SmartModule): | ||
| """Implementation of brightness module.""" | ||
|
|
||
| REQUIRED_COMPONENT = "brightness" | ||
|
|
||
| def __init__(self, device: "SmartDevice", module: str): | ||
| super().__init__(device, module) | ||
| self._add_feature( | ||
| Feature( | ||
| device, | ||
| "Brightness", | ||
| container=self, | ||
| attribute_getter="brightness", | ||
| attribute_setter="set_brightness", | ||
| minimum_value=1, | ||
| maximum_value=100, | ||
| type=FeatureType.Number, | ||
| ) | ||
| ) | ||
|
|
||
| def query(self) -> Dict: | ||
| """Query to execute during the update cycle.""" | ||
| # Brightness is contained in the main device info response. | ||
| return {} | ||
|
|
||
| @property | ||
| def brightness(self): | ||
| """Return current brightness.""" | ||
| return self.data["brightness"] | ||
|
|
||
| async def set_brightness(self, brightness: int): | ||
| """Set the brightness.""" | ||
| return await self.call("set_device_info", {"brightness": brightness}) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,28 @@ | ||
| import pytest | ||
|
|
||
| from kasa.smart import SmartDevice | ||
| from kasa.tests.conftest import parametrize | ||
|
|
||
| from .conftest import ( | ||
| brightness, | ||
| ) | ||
| brightness = parametrize("brightness smart", component_filter="brightness") | ||
|
|
||
|
|
||
| @brightness | ||
| async def test_brightness_component(dev: SmartDevice): | ||
| """Placeholder to test framwework component filter.""" | ||
| """Test brightness feature.""" | ||
| assert isinstance(dev, SmartDevice) | ||
| assert "brightness" in dev._components | ||
|
|
||
| # Test getting the value | ||
| feature = dev.features["brightness"] | ||
| assert isinstance(feature.value, int) | ||
| assert feature.value > 0 and feature.value <= 100 | ||
|
|
||
| # Test setting the value | ||
| await feature.set_value(10) | ||
| assert feature.value == 10 | ||
|
|
||
| with pytest.raises(ValueError): | ||
| await feature.set_value(feature.minimum_value - 10) | ||
|
|
||
| with pytest.raises(ValueError): | ||
| await feature.set_value(feature.maximum_value + 10) |
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIf a module reports its query as non-true, it means that the information is stored in the main get_device_info responses.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.