From 0c04364525a14b84a730fd8a0dfc4bdda29c3b54 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 6 Jun 2025 22:44:25 -0500 Subject: [PATCH] fix flakey tests --- .../integration/fixtures/host_mode_batch_delay.yaml | 11 ++--------- .../fixtures/host_mode_many_entities.yaml | 13 ++----------- ...ost_mode_many_entities_multiple_connections.yaml | 13 ++----------- tests/integration/test_host_mode_many_entities.py | 8 -------- 4 files changed, 6 insertions(+), 39 deletions(-) diff --git a/tests/integration/fixtures/host_mode_batch_delay.yaml b/tests/integration/fixtures/host_mode_batch_delay.yaml index 8a2553061d..8abe1da6fb 100644 --- a/tests/integration/fixtures/host_mode_batch_delay.yaml +++ b/tests/integration/fixtures/host_mode_batch_delay.yaml @@ -31,12 +31,12 @@ binary_sensor: name: "Test Binary Sensor 1" id: test_binary_sensor1 lambda: |- - return true; + return millis() % 1000 < 500; - platform: template name: "Test Binary Sensor 2" id: test_binary_sensor2 lambda: |- - return false; + return millis() % 2000 < 1000; switch: - platform: template @@ -53,10 +53,3 @@ switch: - logger.log: "Switch 2 turned on" turn_off_action: - logger.log: "Switch 2 turned off" - -# Interval to update binary sensors -interval: - - interval: 100ms - then: - - component.update: test_binary_sensor1 - - component.update: test_binary_sensor2 diff --git a/tests/integration/fixtures/host_mode_many_entities.yaml b/tests/integration/fixtures/host_mode_many_entities.yaml index 38a4eb00d7..3d1aa36196 100644 --- a/tests/integration/fixtures/host_mode_many_entities.yaml +++ b/tests/integration/fixtures/host_mode_many_entities.yaml @@ -215,12 +215,10 @@ sensor: binary_sensor: - platform: template name: "Test Binary Sensor 1" - id: test_binary_sensor_1 - lambda: return true; + lambda: return millis() % 1000 < 500; - platform: template name: "Test Binary Sensor 2" - id: test_binary_sensor_2 - lambda: return false; + lambda: return millis() % 2000 < 1000; switch: - platform: template @@ -322,10 +320,3 @@ button: name: "Test Button" on_press: - logger.log: "Button pressed" - -# Interval to update binary sensors -interval: - - interval: 100ms - then: - - component.update: test_binary_sensor_1 - - component.update: test_binary_sensor_2 diff --git a/tests/integration/fixtures/host_mode_many_entities_multiple_connections.yaml b/tests/integration/fixtures/host_mode_many_entities_multiple_connections.yaml index dbbcbd72c1..296cb2455f 100644 --- a/tests/integration/fixtures/host_mode_many_entities_multiple_connections.yaml +++ b/tests/integration/fixtures/host_mode_many_entities_multiple_connections.yaml @@ -95,12 +95,10 @@ sensor: binary_sensor: - platform: template name: "Test Binary Sensor 1" - id: test_binary_sensor_1 - lambda: return true; + lambda: return millis() % 1000 < 500; - platform: template name: "Test Binary Sensor 2" - id: test_binary_sensor_2 - lambda: return false; + lambda: return millis() % 2000 < 1000; text_sensor: - platform: template @@ -136,10 +134,3 @@ number: lambda: return 50.0; set_action: - logger.log: "Number set" - -# Interval to update binary sensors -interval: - - interval: 100ms - then: - - component.update: test_binary_sensor_1 - - component.update: test_binary_sensor_2 diff --git a/tests/integration/test_host_mode_many_entities.py b/tests/integration/test_host_mode_many_entities.py index 6481357f68..d5622e6fa4 100644 --- a/tests/integration/test_host_mode_many_entities.py +++ b/tests/integration/test_host_mode_many_entities.py @@ -51,15 +51,7 @@ async def test_host_mode_many_entities( for s in states.values() if hasattr(s, "state") and isinstance(s.state, float) ] - binary_sensor_states = [ - s - for s in states.values() - if hasattr(s, "state") and isinstance(s.state, bool) - ] assert len(sensor_states) >= 50, ( f"Expected at least 50 sensor states, got {len(sensor_states)}" ) - assert len(binary_sensor_states) >= 2, ( - f"Expected at least 2 binary sensor states, got {len(binary_sensor_states)}" - )