mirror of
https://github.com/esphome/esphome.git
synced 2025-10-24 04:33:49 +01:00
Merge branch 'min_filter_ring_buffer' into integration
This commit is contained in:
@@ -30,12 +30,14 @@ class DateTimeBase : public EntityBase {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef USE_TIME
|
||||||
class DateTimeStateTrigger : public Trigger<ESPTime> {
|
class DateTimeStateTrigger : public Trigger<ESPTime> {
|
||||||
public:
|
public:
|
||||||
explicit DateTimeStateTrigger(DateTimeBase *parent) {
|
explicit DateTimeStateTrigger(DateTimeBase *parent) {
|
||||||
parent->add_on_state_callback([this, parent]() { this->trigger(parent->state_as_esptime()); });
|
parent->add_on_state_callback([this, parent]() { this->trigger(parent->state_as_esptime()); });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace datetime
|
} // namespace datetime
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|||||||
@@ -39,14 +39,6 @@ SlidingWindowFilter::SlidingWindowFilter(size_t window_size, size_t send_every,
|
|||||||
this->window_.init(window_size);
|
this->window_.init(window_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SlidingWindowFilter::set_window_size(size_t window_size) {
|
|
||||||
this->window_size_ = window_size;
|
|
||||||
// Reallocate buffer with new size
|
|
||||||
this->window_.init(window_size);
|
|
||||||
this->window_head_ = 0;
|
|
||||||
this->window_count_ = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
optional<float> SlidingWindowFilter::new_value(float value) {
|
optional<float> SlidingWindowFilter::new_value(float value) {
|
||||||
// Add value to ring buffer
|
// Add value to ring buffer
|
||||||
if (this->window_count_ < this->window_size_) {
|
if (this->window_count_ < this->window_size_) {
|
||||||
|
|||||||
@@ -53,9 +53,6 @@ class SlidingWindowFilter : public Filter {
|
|||||||
public:
|
public:
|
||||||
SlidingWindowFilter(size_t window_size, size_t send_every, size_t send_first_at);
|
SlidingWindowFilter(size_t window_size, size_t send_every, size_t send_first_at);
|
||||||
|
|
||||||
void set_send_every(size_t send_every) { this->send_every_ = send_every; }
|
|
||||||
void set_window_size(size_t window_size);
|
|
||||||
|
|
||||||
optional<float> new_value(float value) final;
|
optional<float> new_value(float value) final;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
27
tests/integration/sensor_test_utils.py
Normal file
27
tests/integration/sensor_test_utils.py
Normal file
@@ -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
|
||||||
@@ -4,34 +4,13 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from aioesphomeapi import EntityInfo, EntityState, SensorState
|
from aioesphomeapi import EntityState, SensorState
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from .sensor_test_utils import build_key_to_sensor_mapping
|
||||||
from .types import APIClientConnectedFactory, RunCompiledFunction
|
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
|
@pytest.mark.asyncio
|
||||||
async def test_sensor_filters_ring_buffer(
|
async def test_sensor_filters_ring_buffer(
|
||||||
yaml_config: str,
|
yaml_config: str,
|
||||||
|
|||||||
@@ -4,34 +4,13 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from aioesphomeapi import EntityInfo, EntityState, SensorState
|
from aioesphomeapi import EntityState, SensorState
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from .sensor_test_utils import build_key_to_sensor_mapping
|
||||||
from .types import APIClientConnectedFactory, RunCompiledFunction
|
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
|
@pytest.mark.asyncio
|
||||||
async def test_sensor_filters_sliding_window(
|
async def test_sensor_filters_sliding_window(
|
||||||
yaml_config: str,
|
yaml_config: str,
|
||||||
|
|||||||
Reference in New Issue
Block a user