mirror of
https://github.com/esphome/esphome.git
synced 2025-10-22 19:53:46 +01:00
tests
This commit is contained in:
@@ -68,45 +68,47 @@ async def test_sensor_filters_sliding_window(
|
|||||||
|
|
||||||
# Get the sensor name from the key mapping
|
# Get the sensor name from the key mapping
|
||||||
sensor_name = key_to_sensor.get(state.key)
|
sensor_name = key_to_sensor.get(state.key)
|
||||||
if sensor_name and sensor_name in sensor_states:
|
if not sensor_name or sensor_name not in sensor_states:
|
||||||
sensor_states[sensor_name].append(state.state)
|
return
|
||||||
|
|
||||||
# Check if we received the expected final value
|
sensor_states[sensor_name].append(state.state)
|
||||||
# After publishing 10 values [1.0, 2.0, ..., 10.0], the window has the last 5: [2, 3, 4, 5, 6]
|
|
||||||
# Filters send at position 1 and position 6 (send_every=5 means every 5th value after first)
|
# Check if we received the expected final value
|
||||||
if (
|
# After publishing 10 values [1.0, 2.0, ..., 10.0], the window has the last 5: [2, 3, 4, 5, 6]
|
||||||
sensor_name == "min_sensor"
|
# Filters send at position 1 and position 6 (send_every=5 means every 5th value after first)
|
||||||
and abs(state.state - 2.0) < 0.01
|
if (
|
||||||
and not min_received.done()
|
sensor_name == "min_sensor"
|
||||||
):
|
and abs(state.state - 2.0) < 0.01
|
||||||
min_received.set_result(True)
|
and not min_received.done()
|
||||||
elif (
|
):
|
||||||
sensor_name == "max_sensor"
|
min_received.set_result(True)
|
||||||
and abs(state.state - 6.0) < 0.01
|
elif (
|
||||||
and not max_received.done()
|
sensor_name == "max_sensor"
|
||||||
):
|
and abs(state.state - 6.0) < 0.01
|
||||||
max_received.set_result(True)
|
and not max_received.done()
|
||||||
elif (
|
):
|
||||||
sensor_name == "median_sensor"
|
max_received.set_result(True)
|
||||||
and abs(state.state - 4.0) < 0.01
|
elif (
|
||||||
and not median_received.done()
|
sensor_name == "median_sensor"
|
||||||
):
|
and abs(state.state - 4.0) < 0.01
|
||||||
# Median of [2, 3, 4, 5, 6] = 4
|
and not median_received.done()
|
||||||
median_received.set_result(True)
|
):
|
||||||
elif (
|
# Median of [2, 3, 4, 5, 6] = 4
|
||||||
sensor_name == "quantile_sensor"
|
median_received.set_result(True)
|
||||||
and abs(state.state - 6.0) < 0.01
|
elif (
|
||||||
and not quantile_received.done()
|
sensor_name == "quantile_sensor"
|
||||||
):
|
and abs(state.state - 6.0) < 0.01
|
||||||
# 90th percentile of [2, 3, 4, 5, 6] = 6
|
and not quantile_received.done()
|
||||||
quantile_received.set_result(True)
|
):
|
||||||
elif (
|
# 90th percentile of [2, 3, 4, 5, 6] = 6
|
||||||
sensor_name == "moving_avg_sensor"
|
quantile_received.set_result(True)
|
||||||
and abs(state.state - 4.0) < 0.01
|
elif (
|
||||||
and not moving_avg_received.done()
|
sensor_name == "moving_avg_sensor"
|
||||||
):
|
and abs(state.state - 4.0) < 0.01
|
||||||
# Average of [2, 3, 4, 5, 6] = 4
|
and not moving_avg_received.done()
|
||||||
moving_avg_received.set_result(True)
|
):
|
||||||
|
# Average of [2, 3, 4, 5, 6] = 4
|
||||||
|
moving_avg_received.set_result(True)
|
||||||
|
|
||||||
async with (
|
async with (
|
||||||
run_compiled(yaml_config),
|
run_compiled(yaml_config),
|
||||||
|
Reference in New Issue
Block a user