Skip to content

Commit 8ef9f25

Browse files
committed
rename map to fn, as it is not a mapping but an arbitrary function
1 parent e0a082e commit 8ef9f25

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ entities:
417417
# The filters below receive all datapoints as they come from home assistant. Y values are strings or null (unless previously mapped to numbers or any other type)
418418
- map_y: y === "heat" ? 1 : 0 # map the y values of each datapoint. Variables `i` (index), `x`, `state`, `statistic` and `meta` and `vars` are also in scope.
419419
- map_x: new Date(+x + 1000) # map the x coordinate (javascript date object) of each datapoint. Same variables as map_y are in scope
420-
- map: |- # arbitrary function.
420+
- fn: |- # arbitrary function.
421421
({xs, ys, meta, states, statistics}) => {
422422
# either statistics or states will be available, depending on if "statistics" are fetched or not
423423
# attributes will be available inside states only if an attribute is picked in the trace
@@ -484,7 +484,7 @@ or alternatively,
484484
or alternatively,
485485
486486
```yaml
487-
- map: |-
487+
- fn: |-
488488
({ys, states}) => ({
489489
ys: states.map((state, i) => state?.state === "heat" ? state.attributes?.current_temperature : 0),
490490
}),
@@ -502,7 +502,7 @@ or alternatively,
502502
- entity: sensor.temperature_in_celsius
503503
statistics: mean
504504
filters:
505-
- map: |-
505+
- fn: |-
506506
(params) => {
507507
console.log(params);
508508
const ys = [];

src/filters/filters.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ const filters = {
214214
(var_name: string) =>
215215
({ vars, ...rest }) => ({ vars: { ...vars, [var_name]: rest } }),
216216
/*
217-
example: map("({xs, ys, states, statistics }) => ({xs: ys})")
217+
example: fn("({xs, ys, states, statistics }) => ({xs: ys})")
218218
*/
219-
map: (fnStr: string) => myEval(fnStr),
219+
fn: (fnStr: string) => myEval(fnStr),
220220
filter: (fnStr: string) => {
221221
const fn = myEval(`(i, x, y, state, statistic, vars) => ${fnStr}`);
222222
return ({ xs, ys, states, statistics, vars }) => {

0 commit comments

Comments
 (0)