-
Notifications
You must be signed in to change notification settings - Fork 276
Add support for array-result in triggers_update #823
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
base: dev
Are you sure you want to change the base?
Conversation
Add the ability that a template could return an array of entities.
Good idea, thanks! triggers_update:
- >-
[[[
const result = [];
for(let i = 0; i<10; i++) result.push(`lights.light${i}`);
return result;
]]]
- sensor.other_entity Also update the documentation to reflect this change, please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for returning an array of entities from the triggers_update
template, allowing dynamic generation of multiple entity IDs through JavaScript templates.
- Add array handling for
triggers_update
template results - Enable templates to return multiple entities via array instead of single entity string
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
@@ -214,7 +214,11 @@ class ButtonCard extends LitElement { | |||
} else if (typeof this._config!.triggers_update === 'string') { | |||
const result = this._getTemplateOrValue(this._stateObj, this._config!.triggers_update); | |||
if (result && result !== 'all') { | |||
this._entities.push(result); | |||
if(Array.isArray(result)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after 'if' keyword. Should be 'if (Array.isArray(result))' to maintain consistent code formatting.
if(Array.isArray(result)) { | |
if (Array.isArray(result)) { |
Copilot uses AI. Check for mistakes.
@@ -214,7 +214,11 @@ class ButtonCard extends LitElement { | |||
} else if (typeof this._config!.triggers_update === 'string') { | |||
const result = this._getTemplateOrValue(this._stateObj, this._config!.triggers_update); | |||
if (result && result !== 'all') { | |||
this._entities.push(result); | |||
if(Array.isArray(result)) { | |||
result.forEach(entity => this._entities.push(entity)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing input validation for array elements. The code should validate that each entity in the array is a valid string before pushing to _entities to prevent potential runtime errors.
result.forEach(entity => this._entities.push(entity)); | |
result.forEach(entity => { | |
if (typeof entity === 'string' && entity.length > 0) { | |
this._entities.push(entity); | |
} | |
}); |
Copilot uses AI. Check for mistakes.
Add the ability that a template could return an array of entities.
Ie:
https://community.home-assistant.io/t/lovelace-button-card/65981/7129?u=psi