Skip to content

Commit 3f3a7a3

Browse files
fix ceiling light color mode (#391)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 2f4e050 commit 3f3a7a3

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

switchbot/devices/ceiling_light.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def color_modes(self) -> set[ColorMode]:
3737
@property
3838
def color_mode(self) -> ColorMode:
3939
"""Return the current color mode."""
40-
device_mode = CeilingLightColorMode(self._get_adv_value("color_mode") or 10)
40+
device_mode = CeilingLightColorMode(
41+
value if (value := self._get_adv_value("color_mode")) is not None else 10
42+
)
4143
return _CEILING_LIGHT_COLOR_MODE_MAP.get(device_mode, ColorMode.OFF)
4244

4345
@update_after_operation

tests/test_ceiling_light.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from unittest.mock import AsyncMock, MagicMock
1+
from unittest.mock import AsyncMock, MagicMock, patch
22

33
import pytest
44
from bleak.backends.device import BLEDevice
@@ -183,3 +183,22 @@ async def test_set_brightness():
183183
device._send_command.assert_called_with(
184184
device._set_brightness_command.format("4B0FA1")
185185
)
186+
187+
188+
@pytest.mark.asyncio
189+
@pytest.mark.parametrize(
190+
("adv_value", "expected_color_mode"),
191+
[
192+
(0, ColorMode.COLOR_TEMP),
193+
(1, ColorMode.COLOR_TEMP),
194+
(4, ColorMode.EFFECT),
195+
(10, ColorMode.OFF),
196+
(None, ColorMode.OFF),
197+
],
198+
)
199+
async def test_get_color_mode(adv_value, expected_color_mode):
200+
"""Test getting color mode."""
201+
device = create_device_for_command_testing()
202+
203+
with patch.object(device, "_get_adv_value", return_value=adv_value):
204+
assert device.color_mode == expected_color_mode

0 commit comments

Comments
 (0)