Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure filtered_attributes and filtered_optimistic are also regex #13047

Merged
merged 3 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Ensure filtered_attributes and filtered_optimistic are also regex
Bring filtered_attributes and filtered_optimistic in line with the newer filtered_cache.
All three of them are now regex matches instead of absolute matches.
  • Loading branch information
sjorge committed Jul 5, 2022
commit 28c2697031c732fcbcd6b35facc7cc829ef672c9
6 changes: 5 additions & 1 deletion lib/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,11 @@ class Controller {

// Filter mqtt message attributes
if (entity.options.filtered_attributes) {
entity.options.filtered_attributes.forEach((a) => delete message[a]);
for (const property of Object.keys(message)) {
if (entity.options.filtered_attributes.find((p) => property.match(p))) {
delete message[property];
}
}
}

if (Object.entries(message).length) {
Expand Down
9 changes: 8 additions & 1 deletion lib/extension/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,14 @@ export default class Publish extends Extension {
}

// filter out attribute listed in filtered_optimistic
entitySettings.filtered_optimistic?.forEach((a) => delete msg[a]);
if (entitySettings.filtered_optimistic) {
for (const property of Object.keys(msg)) {
if (entitySettings.filtered_optimistic.find((p) => property.match(p))) {
delete msg[property];
}
}
}

addToToPublish(re, msg);
}

Expand Down
12 changes: 6 additions & 6 deletions lib/util/settings.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -817,27 +817,27 @@
"items": {
"type": "string"
},
"examples": ["temperature", "battery", "action"],
"examples": ["^temperature$", "^battery$", "^action$"],
"title": "Filtered publish attributes",
"description": "Filter attributes from publish payload."
"description": "Filter attributes with regex from published payload."
},
"filtered_cache": {
"type": "array",
"items": {
"type": "string"
},
"examples": ["action", "input_actions"],
"examples": ["^input_actions$"],
"title": "Filtered attributes from cache",
"description": "Filter attributes from being added to the cache, this prevents the attribute from being in the published payload when the value didn't change."
"description": "Filter attributes with regex from being added to the cache, this prevents the attribute from being in the published payload when the value didn't change."
},
"filtered_optimistic": {
"type": "array",
"items": {
"type": "string"
},
"examples": ["color_mode", "color_temp", "color"],
"examples": ["^color_(mode|temp)$", "color"],
"title": "Filtered optimistic attributes",
"description": "Filter attributes from optimistic publish payload when calling /set. (This has no effect if optimistic is set to false)."
"description": "Filter attributes with regex from optimistic publish payload when calling /set. (This has no effect if optimistic is set to false)."
},
"icon": {
"type": "string",
Expand Down