Use brightness module for smartbulb (#853)

Moves one more feature out from the smartbulb class
This commit is contained in:
Teemu R
2024-04-20 20:29:07 +02:00
committed by GitHub
parent 29b28966e0
commit 651ad96144
2 changed files with 17 additions and 13 deletions

View File

@@ -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})