Enable setting brightness with color temp for smart devices (#1091)

This commit is contained in:
Steven B.
2024-07-31 15:52:27 +01:00
committed by GitHub
parent 7bba9926ed
commit cb7e904d30
5 changed files with 62 additions and 15 deletions

View File

@@ -3,16 +3,11 @@
from __future__ import annotations
import logging
from typing import TYPE_CHECKING
from ...feature import Feature
from ...interfaces.light import ColorTempRange
from ..smartmodule import SmartModule
if TYPE_CHECKING:
from ..smartdevice import SmartDevice
_LOGGER = logging.getLogger(__name__)
DEFAULT_TEMP_RANGE = [2500, 6500]
@@ -23,11 +18,11 @@ class ColorTemperature(SmartModule):
REQUIRED_COMPONENT = "color_temperature"
def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
def _initialize_features(self):
"""Initialize features."""
self._add_feature(
Feature(
device,
self._device,
"color_temperature",
"Color temperature",
container=self,
@@ -61,7 +56,7 @@ class ColorTemperature(SmartModule):
"""Return current color temperature."""
return self.data["color_temp"]
async def set_color_temp(self, temp: int):
async def set_color_temp(self, temp: int, *, brightness=None):
"""Set the color temperature."""
valid_temperature_range = self.valid_temperature_range
if temp < valid_temperature_range[0] or temp > valid_temperature_range[1]:
@@ -70,8 +65,10 @@ class ColorTemperature(SmartModule):
*valid_temperature_range, temp
)
)
return await self.call("set_device_info", {"color_temp": temp})
params = {"color_temp": temp}
if brightness:
params["brightness"] = brightness
return await self.call("set_device_info", params)
async def _check_supported(self) -> bool:
"""Check the color_temp_range has more than one value."""

View File

@@ -107,7 +107,9 @@ class Light(SmartModule, LightInterface):
"""
if not self.is_variable_color_temp:
raise KasaException("Bulb does not support colortemp.")
return await self._device.modules[Module.ColorTemperature].set_color_temp(temp)
return await self._device.modules[Module.ColorTemperature].set_color_temp(
temp, brightness=brightness
)
async def set_brightness(
self, brightness: int, *, transition: int | None = None