mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-12 10:28:01 +00:00
Make Light and Fan a common module interface (#911)
This commit is contained in:
@@ -2,16 +2,10 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from ...feature import Feature
|
||||
from ..smartmodule import SmartModule
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..smartdevice import SmartDevice
|
||||
|
||||
|
||||
BRIGHTNESS_MIN = 1
|
||||
BRIGHTNESS_MIN = 0
|
||||
BRIGHTNESS_MAX = 100
|
||||
|
||||
|
||||
@@ -20,8 +14,11 @@ class Brightness(SmartModule):
|
||||
|
||||
REQUIRED_COMPONENT = "brightness"
|
||||
|
||||
def __init__(self, device: SmartDevice, module: str):
|
||||
super().__init__(device, module)
|
||||
def _initialize_features(self):
|
||||
"""Initialize features."""
|
||||
super()._initialize_features()
|
||||
|
||||
device = self._device
|
||||
self._add_feature(
|
||||
Feature(
|
||||
device,
|
||||
@@ -47,8 +44,11 @@ class Brightness(SmartModule):
|
||||
"""Return current brightness."""
|
||||
return self.data["brightness"]
|
||||
|
||||
async def set_brightness(self, brightness: int):
|
||||
"""Set the brightness."""
|
||||
async def set_brightness(self, brightness: int, *, transition: int | None = None):
|
||||
"""Set the brightness. A brightness value of 0 will turn off the light.
|
||||
|
||||
Note, transition is not supported and will be ignored.
|
||||
"""
|
||||
if not isinstance(brightness, int) or not (
|
||||
BRIGHTNESS_MIN <= brightness <= BRIGHTNESS_MAX
|
||||
):
|
||||
@@ -57,6 +57,8 @@ class Brightness(SmartModule):
|
||||
f"(valid range: {BRIGHTNESS_MIN}-{BRIGHTNESS_MAX}%)"
|
||||
)
|
||||
|
||||
if brightness == 0:
|
||||
return await self._device.turn_off()
|
||||
return await self.call("set_device_info", {"brightness": brightness})
|
||||
|
||||
async def _check_supported(self):
|
||||
|
Reference in New Issue
Block a user