4
0
Эх сурвалжийг харах

Light tests: add a test for recently added WHITE support

Recently support for "white" as a parameter to turn_on was added,
for the case of RGBW lights that cannot use color_temp to switch from
colour to white modes.  Add test coverage for this case to the light
entity tests.
Jason Rumney 2 жил өмнө
parent
commit
630ada43c0
1 өөрчлөгдсөн 59 нэмэгдсэн , 0 устгасан
  1. 59 0
      tests/test_light.py

+ 59 - 0
tests/test_light.py

@@ -9,6 +9,7 @@ from custom_components.tuya_local.const import (
     CONF_PROTOCOL_VERSION,
     DOMAIN,
 )
+from custom_components.tuya_local.helpers.device_config import TuyaEntityConfig
 from custom_components.tuya_local.light import async_setup_entry, TuyaLocalLight
 
 
@@ -92,3 +93,61 @@ async def test_init_entry_fails_if_config_is_missing(hass):
     except ValueError:
         pass
     m_add_entities.assert_not_called()
+
+
+@pytest.mark.asyncio
+async def test_async_turn_on_with_white_param():
+    """Test using WHITE param for async_turn_on."""
+    mock_device = AsyncMock()
+    mock_device.get_property = Mock()
+    dps = {"1": True, "2": "colour", "3": 1000, "4": "ABCDEFFF"}
+    mock_device.get_property.side_effect = lambda arg: dps[arg]
+    mock_config = Mock()
+    config = TuyaEntityConfig(
+        mock_config,
+        {
+            "entity": "light",
+            "dps": [
+                {
+                    "id": "1",
+                    "name": "switch",
+                    "type": "boolean",
+                },
+                {
+                    "id": "2",
+                    "name": "color_mode",
+                    "type": "string",
+                    "mapping": [
+                        {
+                            "dps_val": "white",
+                            "value": "white",
+                        },
+                        {
+                            "dps_val": "colour",
+                            "value": "hs",
+                        },
+                    ],
+                },
+                {
+                    "id": "3",
+                    "name": "brightness",
+                    "type": "integer",
+                    "range": {
+                        "min": 10,
+                        "max": 1000,
+                    },
+                    "mapping": [
+                        {"scale": 3.92},
+                    ],
+                },
+                {
+                    "id": "4",
+                    "name": "hs",
+                    "type": "hex",
+                },
+            ],
+        },
+    )
+    light = TuyaLocalLight(mock_device, config)
+    await light.async_turn_on(white=128)
+    mock_device.async_set_properties.assert_called_once_with({"2": "white", "3": 502})