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.
This commit is contained in:
Jorge Schrauwen
2022-07-05 18:52:50 +02:00
parent 4a58dbf84c
commit 28c2697031
3 changed files with 19 additions and 8 deletions
+5 -1
View File
@@ -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) {
+8 -1
View File
@@ -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);
}
+6 -6
View File
@@ -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",