mirror of
https://github.com/esphome/esphome.git
synced 2025-09-14 09:12:19 +01:00
Add a simple 'skip_initial' filter (#4582)
* Add a simple 'skip' filter This filter simply skips the first `send_first_at` values, then passes everything as-is. This is quite useful when you know the first few sensor readings should be ignored. Example YAML: ```yaml sensor: - platform: sgp30 id: mysensor_sgp30 eco2: id: mysensor_sgp30_co2 name: "eCO₂" accuracy_decimals: 0 filters: - skip: send_first_at: 41 ``` * Rename the filter to `skip_initial` and simplify the schema New usage: ```yaml filters: - skip_initial: 41 ``` * Apply clang-format
This commit is contained in:
@@ -194,6 +194,7 @@ SensorPublishAction = sensor_ns.class_("SensorPublishAction", automation.Action)
|
||||
Filter = sensor_ns.class_("Filter")
|
||||
QuantileFilter = sensor_ns.class_("QuantileFilter", Filter)
|
||||
MedianFilter = sensor_ns.class_("MedianFilter", Filter)
|
||||
SkipInitialFilter = sensor_ns.class_("SkipInitialFilter", Filter)
|
||||
MinFilter = sensor_ns.class_("MinFilter", Filter)
|
||||
MaxFilter = sensor_ns.class_("MaxFilter", Filter)
|
||||
SlidingWindowMovingAverageFilter = sensor_ns.class_(
|
||||
@@ -365,6 +366,11 @@ MIN_SCHEMA = cv.All(
|
||||
)
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register("skip_initial", SkipInitialFilter, cv.positive_not_null_int)
|
||||
async def skip_initial_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(filter_id, config)
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register("min", MinFilter, MIN_SCHEMA)
|
||||
async def min_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(
|
||||
|
Reference in New Issue
Block a user