mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-06 10:44:04 +00:00
Add colortemp module (#814)
Allow controlling the color temperature via features interface: ``` $ kasa --host 192.168.xx.xx feature color_temperature Color temperature (color_temperature): 0 $ kasa --host 192.168.xx.xx feature color_temperature 2000 Setting color_temperature to 2000 Raised error: Temperature should be between 2500 and 6500, was 2000 Run with --debug enabled to see stacktrace $ kasa --host 192.168.xx.xx feature color_temperature 3000 Setting color_temperature to 3000 $ kasa --host 192.168.xx.xx feature color_temperature Color temperature (color_temperature): 3000 ```
This commit is contained in:
@@ -5,6 +5,7 @@ from .battery import BatterySensor
|
||||
from .brightness import Brightness
|
||||
from .childdevicemodule import ChildDeviceModule
|
||||
from .cloudmodule import CloudModule
|
||||
from .colortemp import ColorTemperatureModule
|
||||
from .devicemodule import DeviceModule
|
||||
from .energymodule import EnergyModule
|
||||
from .firmware import Firmware
|
||||
@@ -31,4 +32,5 @@ __all__ = [
|
||||
"Firmware",
|
||||
"CloudModule",
|
||||
"LightTransitionModule",
|
||||
"ColorTemperatureModule",
|
||||
]
|
||||
|
55
kasa/smart/modules/colortemp.py
Normal file
55
kasa/smart/modules/colortemp.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""Implementation of color temp module."""
|
||||
from typing import TYPE_CHECKING, Dict
|
||||
|
||||
from ...bulb import ColorTempRange
|
||||
from ...feature import Feature
|
||||
from ..smartmodule import SmartModule
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..smartdevice import SmartDevice
|
||||
|
||||
|
||||
class ColorTemperatureModule(SmartModule):
|
||||
"""Implementation of color temp module."""
|
||||
|
||||
REQUIRED_COMPONENT = "color_temperature"
|
||||
|
||||
def __init__(self, device: "SmartDevice", module: str):
|
||||
super().__init__(device, module)
|
||||
self._add_feature(
|
||||
Feature(
|
||||
device,
|
||||
"Color temperature",
|
||||
container=self,
|
||||
attribute_getter="color_temp",
|
||||
attribute_setter="set_color_temp",
|
||||
range_getter="valid_temperature_range",
|
||||
)
|
||||
)
|
||||
|
||||
def query(self) -> Dict:
|
||||
"""Query to execute during the update cycle."""
|
||||
# Color temp is contained in the main device info response.
|
||||
return {}
|
||||
|
||||
@property
|
||||
def valid_temperature_range(self) -> ColorTempRange:
|
||||
"""Return valid color-temp range."""
|
||||
return ColorTempRange(*self.data.get("color_temp_range"))
|
||||
|
||||
@property
|
||||
def color_temp(self):
|
||||
"""Return current color temperature."""
|
||||
return self.data["color_temp"]
|
||||
|
||||
async def set_color_temp(self, temp: int):
|
||||
"""Set the color temperature."""
|
||||
valid_temperature_range = self.valid_temperature_range
|
||||
if temp < valid_temperature_range[0] or temp > valid_temperature_range[1]:
|
||||
raise ValueError(
|
||||
"Temperature should be between {} and {}, was {}".format(
|
||||
*valid_temperature_range, temp
|
||||
)
|
||||
)
|
||||
|
||||
return await self.call("set_device_info", {"color_temp": temp})
|
Reference in New Issue
Block a user