Просмотр исходного кода

ci(device_config): add tests for masked values with exceptions

Check that exceptions work as expected when masking is present.

For PR #5012
Jason Rumney 1 день назад
Родитель
Сommit
6985bfa557
1 измененных файлов с 36 добавлено и 0 удалено
  1. 36 0
      tests/test_device_config.py

+ 36 - 0
tests/test_device_config.py

@@ -802,6 +802,42 @@ def test_setting_masked_hex(mocker):
     assert cfg.get_values_to_set(mock_device, 0xCA) == {"1": "cabe"}
 
 
+def test_getting_masked_b64_with_special_case_mapping(mocker):
+    """Test that get_value works with masked hex encoding and a mapping that has a special case."""
+    mock_entity = mocker.MagicMock()
+    mock_config = {
+        "id": "1",
+        "name": "test",
+        "type": "base64",
+        "mask": "ffff",
+        "mapping": [
+            {"dps_val": 256, "value": "special_case"},
+        ],
+    }
+    mock_device = mocker.MagicMock()
+    mock_device.get_property.return_value = "AQA="
+    cfg = TuyaDpsConfig(mock_entity, mock_config)
+    assert cfg.get_value(mock_device) == "special_case"
+
+
+def test_setting_masked_b64_with_special_case_mapping(mocker):
+    """Test that get_values_to_set works with masked hex encoding and a mapping that has a special case."""
+    mock_entity = mocker.MagicMock()
+    mock_config = {
+        "id": "1",
+        "name": "test",
+        "type": "base64",
+        "mask": "ffff",
+        "mapping": [
+            {"dps_val": 256, "value": "special_case"},
+        ],
+    }
+    mock_device = mocker.MagicMock()
+    mock_device.get_property.return_value = "AAA="
+    cfg = TuyaDpsConfig(mock_entity, mock_config)
+    assert cfg.get_values_to_set(mock_device, "special_case") == {"1": "AQA="}
+
+
 def test_default_without_mapping(mocker):
     """Test that default returns None when there is no mapping"""
     mock_entity = mocker.MagicMock()