Apply AiDot color when brightness is sent along with it (#180391)

This commit is contained in:
Franck Nijhof
2026-08-28 18:13:19 +02:00
committed by GitHub
parent f985fafbf5
commit 456582ed2d
2 changed files with 51 additions and 3 deletions
+7 -3
View File
@@ -92,13 +92,16 @@ class AidotLight(CoordinatorEntity[AidotDeviceUpdateCoordinator], LightEntity):
@override
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the light on, applying brightness, color temperature, RGBW, or plain on."""
"""Turn the light on, applying any requested brightness and color."""
# Brightness is independent of color: a scene sends both at once, and
# the color must not be dropped just because brightness came with it.
if ATTR_BRIGHTNESS in kwargs:
brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
await self.coordinator.device_client.async_set_brightness(brightness)
self.coordinator.data.dimming = brightness
self._attr_brightness = brightness
elif ATTR_COLOR_TEMP_KELVIN in kwargs:
if ATTR_COLOR_TEMP_KELVIN in kwargs:
color_temp_kelvin = kwargs.get(ATTR_COLOR_TEMP_KELVIN)
await self.coordinator.device_client.async_set_cct(color_temp_kelvin)
self.coordinator.data.cct = color_temp_kelvin
@@ -110,7 +113,8 @@ class AidotLight(CoordinatorEntity[AidotDeviceUpdateCoordinator], LightEntity):
self.coordinator.data.rgbw = rgbw_color
self._attr_rgbw_color = rgbw_color
self._attr_color_mode = ColorMode.RGBW
else:
elif ATTR_BRIGHTNESS not in kwargs:
# Nothing was requested to apply, so just switch it on.
await self.coordinator.device_client.async_turn_on()
self.coordinator.data.on = True
+44
View File
@@ -1,11 +1,13 @@
"""Test the aidot device."""
from typing import Any
from unittest.mock import AsyncMock, MagicMock, Mock
from aidot.const import CONF_DEVICE_LIST
from aidot.device_client import DeviceStatusData
from aidot.exceptions import AidotAuthFailed
from freezegun.api import FrozenDateTimeFactory
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.aidot.coordinator import UPDATE_DEVICE_LIST_INTERVAL
@@ -136,6 +138,48 @@ async def test_turn_on_with_rgbw(
mocked_device_client.async_set_rgbw.assert_called_once()
@pytest.mark.parametrize(
("color_data", "applied_call", "ignored_call"),
[
pytest.param(
{ATTR_RGBW_COLOR: (0, 0, 255, 0)},
"async_set_rgbw",
"async_set_cct",
id="rgbw",
),
pytest.param(
{ATTR_COLOR_TEMP_KELVIN: 3000},
"async_set_cct",
"async_set_rgbw",
id="color_temp",
),
],
)
async def test_turn_on_with_brightness_and_color(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mocked_device_client: MagicMock,
color_data: dict[str, Any],
applied_call: str,
ignored_call: str,
) -> None:
"""Test brightness and color are both applied when sent together."""
await async_init_integration(hass, mock_config_entry)
# Scenes send brightness and color in a single call.
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: ENTITY_LIGHT, ATTR_BRIGHTNESS: 100, **color_data},
blocking=True,
)
mocked_device_client.async_set_brightness.assert_called_once_with(100)
getattr(mocked_device_client, applied_call).assert_called_once()
getattr(mocked_device_client, ignored_call).assert_not_called()
mocked_device_client.async_turn_on.assert_not_called()
async def test_light_unavailable(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,