mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-09 20:24:02 +00:00
Use brightness module for smartbulb (#853)
Moves one more feature out from the smartbulb class
This commit is contained in:
@@ -11,6 +11,10 @@ if TYPE_CHECKING:
|
||||
from ..smartdevice import SmartDevice
|
||||
|
||||
|
||||
BRIGHTNESS_MIN = 1
|
||||
BRIGHTNESS_MAX = 100
|
||||
|
||||
|
||||
class Brightness(SmartModule):
|
||||
"""Implementation of brightness module."""
|
||||
|
||||
@@ -25,8 +29,8 @@ class Brightness(SmartModule):
|
||||
container=self,
|
||||
attribute_getter="brightness",
|
||||
attribute_setter="set_brightness",
|
||||
minimum_value=1,
|
||||
maximum_value=100,
|
||||
minimum_value=BRIGHTNESS_MIN,
|
||||
maximum_value=BRIGHTNESS_MAX,
|
||||
type=FeatureType.Number,
|
||||
)
|
||||
)
|
||||
@@ -43,4 +47,12 @@ class Brightness(SmartModule):
|
||||
|
||||
async def set_brightness(self, brightness: int):
|
||||
"""Set the brightness."""
|
||||
if not isinstance(brightness, int) or not (
|
||||
BRIGHTNESS_MIN <= brightness <= BRIGHTNESS_MAX
|
||||
):
|
||||
raise ValueError(
|
||||
f"Invalid brightness value: {brightness} "
|
||||
f"(valid range: {BRIGHTNESS_MIN}-{BRIGHTNESS_MAX}%)"
|
||||
)
|
||||
|
||||
return await self.call("set_device_info", {"brightness": brightness})
|
||||
|
Reference in New Issue
Block a user