From febe075bb2b6ece497b8b3ae3d345061434bb596 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 15 Oct 2025 23:17:08 -1000 Subject: [PATCH] helper --- esphome/components/datetime/datetime_base.h | 2 ++ tests/integration/sensor_test_utils.py | 27 +++++++++++++++++++ .../test_sensor_filters_ring_buffer.py | 25 ++--------------- .../test_sensor_filters_sliding_window.py | 25 ++--------------- 4 files changed, 33 insertions(+), 46 deletions(-) create mode 100644 tests/integration/sensor_test_utils.py diff --git a/esphome/components/datetime/datetime_base.h b/esphome/components/datetime/datetime_base.h index b5f54ac96f..b7645f5539 100644 --- a/esphome/components/datetime/datetime_base.h +++ b/esphome/components/datetime/datetime_base.h @@ -30,12 +30,14 @@ class DateTimeBase : public EntityBase { #endif }; +#ifdef USE_TIME class DateTimeStateTrigger : public Trigger { public: explicit DateTimeStateTrigger(DateTimeBase *parent) { parent->add_on_state_callback([this, parent]() { this->trigger(parent->state_as_esptime()); }); } }; +#endif } // namespace datetime } // namespace esphome diff --git a/tests/integration/sensor_test_utils.py b/tests/integration/sensor_test_utils.py new file mode 100644 index 0000000000..c3843a26ab --- /dev/null +++ b/tests/integration/sensor_test_utils.py @@ -0,0 +1,27 @@ +"""Shared utilities for sensor integration tests.""" + +from __future__ import annotations + +from aioesphomeapi import EntityInfo + + +def build_key_to_sensor_mapping( + entities: list[EntityInfo], sensor_names: list[str] +) -> dict[int, str]: + """Build a mapping from entity keys to sensor names. + + Args: + entities: List of entity info objects from the API + sensor_names: List of sensor names to search for in object_ids + + Returns: + Dictionary mapping entity keys to sensor names + """ + key_to_sensor: dict[int, str] = {} + for entity in entities: + obj_id = entity.object_id.lower() + for sensor_name in sensor_names: + if sensor_name in obj_id: + key_to_sensor[entity.key] = sensor_name + break + return key_to_sensor diff --git a/tests/integration/test_sensor_filters_ring_buffer.py b/tests/integration/test_sensor_filters_ring_buffer.py index e138f93e7e..8edb1600d9 100644 --- a/tests/integration/test_sensor_filters_ring_buffer.py +++ b/tests/integration/test_sensor_filters_ring_buffer.py @@ -4,34 +4,13 @@ from __future__ import annotations import asyncio -from aioesphomeapi import EntityInfo, EntityState, SensorState +from aioesphomeapi import EntityState, SensorState import pytest +from .sensor_test_utils import build_key_to_sensor_mapping from .types import APIClientConnectedFactory, RunCompiledFunction -def build_key_to_sensor_mapping( - entities: list[EntityInfo], sensor_names: list[str] -) -> dict[int, str]: - """Build a mapping from entity keys to sensor names. - - Args: - entities: List of entity info objects from the API - sensor_names: List of sensor names to search for in object_ids - - Returns: - Dictionary mapping entity keys to sensor names - """ - key_to_sensor: dict[int, str] = {} - for entity in entities: - obj_id = entity.object_id.lower() - for sensor_name in sensor_names: - if sensor_name in obj_id: - key_to_sensor[entity.key] = sensor_name - break - return key_to_sensor - - @pytest.mark.asyncio async def test_sensor_filters_ring_buffer( yaml_config: str, diff --git a/tests/integration/test_sensor_filters_sliding_window.py b/tests/integration/test_sensor_filters_sliding_window.py index 0c7aec70aa..2183946134 100644 --- a/tests/integration/test_sensor_filters_sliding_window.py +++ b/tests/integration/test_sensor_filters_sliding_window.py @@ -4,34 +4,13 @@ from __future__ import annotations import asyncio -from aioesphomeapi import EntityInfo, EntityState, SensorState +from aioesphomeapi import EntityState, SensorState import pytest +from .sensor_test_utils import build_key_to_sensor_mapping from .types import APIClientConnectedFactory, RunCompiledFunction -def build_key_to_sensor_mapping( - entities: list[EntityInfo], sensor_names: list[str] -) -> dict[int, str]: - """Build a mapping from entity keys to sensor names. - - Args: - entities: List of entity info objects from the API - sensor_names: List of sensor names to search for in object_ids - - Returns: - Dictionary mapping entity keys to sensor names - """ - key_to_sensor: dict[int, str] = {} - for entity in entities: - obj_id = entity.object_id.lower() - for sensor_name in sensor_names: - if sensor_name in obj_id: - key_to_sensor[entity.key] = sensor_name - break - return key_to_sensor - - @pytest.mark.asyncio async def test_sensor_filters_sliding_window( yaml_config: str,