mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	[light] Add compile test for addressable lights
This commit is contained in:
		| @@ -17,6 +17,20 @@ esphome: | ||||
|           relative_brightness: 5% | ||||
|           brightness_limits: | ||||
|             max_brightness: 90% | ||||
|       - light.turn_on: | ||||
|           id: test_addressable_transition | ||||
|           brightness: 50% | ||||
|           red: 100% | ||||
|           green: 0% | ||||
|           blue: 0% | ||||
|           transition_length: 500ms | ||||
|       - light.turn_on: | ||||
|           id: test_addressable_transition | ||||
|           brightness: 100% | ||||
|           red: 0% | ||||
|           green: 100% | ||||
|           blue: 0% | ||||
|           transition_length: 1s | ||||
|  | ||||
| light: | ||||
|   - platform: binary | ||||
| @@ -163,3 +177,9 @@ light: | ||||
|               blue: 0% | ||||
|               duration: 1s | ||||
|               transition_length: 500ms | ||||
|   - platform: partition | ||||
|     id: test_addressable_transition | ||||
|     name: Addressable Transition Test | ||||
|     default_transition_length: 1s | ||||
|     segments: | ||||
|       - single_light_id: test_rgb_light | ||||
|   | ||||
| @@ -49,42 +49,3 @@ async def test_noise_encryption_key_protection( | ||||
|         with pytest.raises(InvalidEncryptionKeyAPIError): | ||||
|             async with api_client_connected(noise_psk=wrong_key) as client: | ||||
|                 await client.device_info() | ||||
|  | ||||
|  | ||||
| @pytest.mark.asyncio | ||||
| async def test_noise_encryption_key_clear_protection( | ||||
|     yaml_config: str, | ||||
|     run_compiled: RunCompiledFunction, | ||||
|     api_client_connected: APIClientConnectedFactory, | ||||
| ) -> None: | ||||
|     """Test that noise encryption key set in YAML cannot be changed via API.""" | ||||
|     # The key that's set in the YAML fixture | ||||
|     noise_psk = "zX9/JHxMKwpP0jUGsF0iESCm1wRvNgR6NkKVOhn7kSs=" | ||||
|  | ||||
|     # Keep ESPHome process running throughout all tests | ||||
|     async with run_compiled(yaml_config): | ||||
|         # First connection - test key change attempt | ||||
|         async with api_client_connected(noise_psk=noise_psk) as client: | ||||
|             # Verify connection is established | ||||
|             device_info = await client.device_info() | ||||
|             assert device_info is not None | ||||
|  | ||||
|             # Try to set a new encryption key via API | ||||
|             new_key = b""  # Empty key to attempt to clear | ||||
|  | ||||
|             # This should fail since key was set in YAML | ||||
|             success = await client.noise_encryption_set_key(new_key) | ||||
|             assert success is False | ||||
|  | ||||
|         # Reconnect with the original key to verify it still works | ||||
|         async with api_client_connected(noise_psk=noise_psk) as client: | ||||
|             # Verify connection is still successful with original key | ||||
|             device_info = await client.device_info() | ||||
|             assert device_info is not None | ||||
|             assert device_info.name == "noise-key-test" | ||||
|  | ||||
|         # Verify that connecting with a wrong key fails | ||||
|         wrong_key = base64.b64encode(b"y" * 32).decode()  # Different key | ||||
|         with pytest.raises(InvalidEncryptionKeyAPIError): | ||||
|             async with api_client_connected(noise_psk=wrong_key) as client: | ||||
|                 await client.device_info() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user