|
9 | 9 | MODEL_DIMMER, |
10 | 10 | MODEL_DIMMER_2, |
11 | 11 | MODEL_DUO, |
| 12 | + MODEL_MULTICOLOR_BULB_G3, |
12 | 13 | MODEL_RGBW2, |
13 | 14 | MODEL_VINTAGE_V2, |
14 | 15 | ) |
@@ -962,3 +963,135 @@ async def test_rpc_cct_light_without_ct_range( |
962 | 963 | # default values from constants are 2700 and 6500 |
963 | 964 | assert state.attributes[ATTR_MIN_COLOR_TEMP_KELVIN] == 2700 |
964 | 965 | assert state.attributes[ATTR_MAX_COLOR_TEMP_KELVIN] == 6500 |
| 966 | + |
| 967 | + |
| 968 | +async def test_rpc_rgbcct_light( |
| 969 | + hass: HomeAssistant, |
| 970 | + mock_rpc_device: Mock, |
| 971 | + entity_registry: EntityRegistry, |
| 972 | + monkeypatch: pytest.MonkeyPatch, |
| 973 | +) -> None: |
| 974 | + """Test RPC RGBCCT light.""" |
| 975 | + entity_id = f"{LIGHT_DOMAIN}.test_name" |
| 976 | + |
| 977 | + config = deepcopy(mock_rpc_device.config) |
| 978 | + config["rgbcct:0"] = {"id": 0, "name": None} |
| 979 | + monkeypatch.setattr(mock_rpc_device, "config", config) |
| 980 | + |
| 981 | + status = deepcopy(mock_rpc_device.status) |
| 982 | + status["rgbcct:0"] = { |
| 983 | + "id": 0, |
| 984 | + "output": False, |
| 985 | + "brightness": 44, |
| 986 | + "ct": 3349, |
| 987 | + "rgb": [76, 140, 255], |
| 988 | + "mode": "cct", |
| 989 | + } |
| 990 | + monkeypatch.setattr(mock_rpc_device, "status", status) |
| 991 | + |
| 992 | + await init_integration(hass, 3, MODEL_MULTICOLOR_BULB_G3) |
| 993 | + |
| 994 | + assert (entry := entity_registry.async_get(entity_id)) |
| 995 | + assert entry.unique_id == "123456789ABC-rgbcct:0" |
| 996 | + |
| 997 | + # Turn off |
| 998 | + await hass.services.async_call( |
| 999 | + LIGHT_DOMAIN, |
| 1000 | + SERVICE_TURN_OFF, |
| 1001 | + {ATTR_ENTITY_ID: entity_id}, |
| 1002 | + blocking=True, |
| 1003 | + ) |
| 1004 | + |
| 1005 | + mock_rpc_device.call_rpc.assert_called_once_with( |
| 1006 | + "RGBCCT.Set", {"id": 0, "on": False} |
| 1007 | + ) |
| 1008 | + |
| 1009 | + assert (state := hass.states.get(entity_id)) |
| 1010 | + assert state.state == STATE_OFF |
| 1011 | + |
| 1012 | + # Turn on |
| 1013 | + mock_rpc_device.call_rpc.reset_mock() |
| 1014 | + mutate_rpc_device_status(monkeypatch, mock_rpc_device, "rgbcct:0", "output", True) |
| 1015 | + await hass.services.async_call( |
| 1016 | + LIGHT_DOMAIN, |
| 1017 | + SERVICE_TURN_ON, |
| 1018 | + {ATTR_ENTITY_ID: entity_id}, |
| 1019 | + blocking=True, |
| 1020 | + ) |
| 1021 | + |
| 1022 | + mock_rpc_device.call_rpc.assert_called_once_with( |
| 1023 | + "RGBCCT.Set", {"id": 0, "on": True} |
| 1024 | + ) |
| 1025 | + mock_rpc_device.mock_update() |
| 1026 | + |
| 1027 | + assert (state := hass.states.get(entity_id)) |
| 1028 | + assert state.state == STATE_ON |
| 1029 | + assert state.attributes[ATTR_COLOR_MODE] == ColorMode.COLOR_TEMP |
| 1030 | + assert state.attributes[ATTR_BRIGHTNESS] == 112 |
| 1031 | + assert state.attributes[ATTR_COLOR_TEMP_KELVIN] == 3349 |
| 1032 | + assert state.attributes[ATTR_MIN_COLOR_TEMP_KELVIN] == 2700 |
| 1033 | + assert state.attributes[ATTR_MAX_COLOR_TEMP_KELVIN] == 6500 |
| 1034 | + |
| 1035 | + # Turn on, brightness = 88 |
| 1036 | + mock_rpc_device.call_rpc.reset_mock() |
| 1037 | + await hass.services.async_call( |
| 1038 | + LIGHT_DOMAIN, |
| 1039 | + SERVICE_TURN_ON, |
| 1040 | + {ATTR_ENTITY_ID: entity_id, ATTR_BRIGHTNESS_PCT: 88}, |
| 1041 | + blocking=True, |
| 1042 | + ) |
| 1043 | + |
| 1044 | + mutate_rpc_device_status(monkeypatch, mock_rpc_device, "rgbcct:0", "brightness", 88) |
| 1045 | + mock_rpc_device.mock_update() |
| 1046 | + |
| 1047 | + mock_rpc_device.call_rpc.assert_called_once_with( |
| 1048 | + "RGBCCT.Set", {"id": 0, "on": True, "brightness": 88} |
| 1049 | + ) |
| 1050 | + |
| 1051 | + assert (state := hass.states.get(entity_id)) |
| 1052 | + assert state.state == STATE_ON |
| 1053 | + assert state.attributes[ATTR_BRIGHTNESS] == 224 # 88% of 255 |
| 1054 | + |
| 1055 | + # Turn on, color temp = 4444 K |
| 1056 | + mock_rpc_device.call_rpc.reset_mock() |
| 1057 | + await hass.services.async_call( |
| 1058 | + LIGHT_DOMAIN, |
| 1059 | + SERVICE_TURN_ON, |
| 1060 | + {ATTR_ENTITY_ID: entity_id, ATTR_COLOR_TEMP_KELVIN: 4444}, |
| 1061 | + blocking=True, |
| 1062 | + ) |
| 1063 | + |
| 1064 | + mutate_rpc_device_status(monkeypatch, mock_rpc_device, "rgbcct:0", "ct", 4444) |
| 1065 | + mock_rpc_device.mock_update() |
| 1066 | + |
| 1067 | + mock_rpc_device.call_rpc.assert_called_once_with( |
| 1068 | + "RGBCCT.Set", {"id": 0, "on": True, "ct": 4444, "mode": "cct"} |
| 1069 | + ) |
| 1070 | + |
| 1071 | + assert (state := hass.states.get(entity_id)) |
| 1072 | + assert state.state == STATE_ON |
| 1073 | + assert state.attributes[ATTR_COLOR_TEMP_KELVIN] == 4444 |
| 1074 | + |
| 1075 | + # Turn on, color 100, 150, 200 |
| 1076 | + mock_rpc_device.call_rpc.reset_mock() |
| 1077 | + await hass.services.async_call( |
| 1078 | + LIGHT_DOMAIN, |
| 1079 | + SERVICE_TURN_ON, |
| 1080 | + {ATTR_ENTITY_ID: entity_id, ATTR_RGB_COLOR: [100, 150, 200]}, |
| 1081 | + blocking=True, |
| 1082 | + ) |
| 1083 | + |
| 1084 | + mutate_rpc_device_status( |
| 1085 | + monkeypatch, mock_rpc_device, "rgbcct:0", "rgb", [100, 150, 200] |
| 1086 | + ) |
| 1087 | + mutate_rpc_device_status(monkeypatch, mock_rpc_device, "rgbcct:0", "mode", "rgb") |
| 1088 | + mock_rpc_device.mock_update() |
| 1089 | + |
| 1090 | + mock_rpc_device.call_rpc.assert_called_once_with( |
| 1091 | + "RGBCCT.Set", {"id": 0, "on": True, "rgb": [100, 150, 200], "mode": "rgb"} |
| 1092 | + ) |
| 1093 | + |
| 1094 | + assert (state := hass.states.get(entity_id)) |
| 1095 | + assert state.state == STATE_ON |
| 1096 | + assert state.attributes[ATTR_COLOR_MODE] == ColorMode.RGB |
| 1097 | + assert state.attributes[ATTR_RGB_COLOR] == (100, 150, 200) |
0 commit comments