Skip to content

Commit

Permalink
Added option to set state attributes when templating entity states
Browse files Browse the repository at this point in the history
  • Loading branch information
gadgetchnnel committed Nov 25, 2019
1 parent af4357e commit 4f62db1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion custom_card.json
@@ -1,6 +1,6 @@
{
"lovelace-card-templater": {
"version": "0.0.5",
"version": "0.0.6b1",
"remote_location": "https://raw.githubusercontent.com/gadgetchnnel/lovelace-card-templater/master/lovelace-card-templater.js",
"visit_repo": "https://github.com/gadgetchnnel/lovelace-card-templater",
"changelog": "https://github.com/gadgetchnnel/lovelace-card-templater"
Expand Down
11 changes: 7 additions & 4 deletions lovelace-card-templater.js
Expand Up @@ -26,7 +26,7 @@ customElements.whenDefined('card-tools').then(() => {
this.yaml = window.YAML;
});
}

createRenderRoot() {
return this;
}
Expand Down Expand Up @@ -81,12 +81,14 @@ customElements.whenDefined('card-tools').then(() => {
return false;
}

getMockedState(stateObj, state){
getMockedState(stateObj, state, attributes){
var newStateObj = {};
Object.assign(newStateObj, stateObj);
newStateObj.attributes = {};
Object.assign(newStateObj.attributes, stateObj.attributes);

if(attributes) {
Object.assign(newStateObj.attributes, attributes);
}
newStateObj.state = state;

return newStateObj;
Expand All @@ -99,7 +101,8 @@ customElements.whenDefined('card-tools').then(() => {
let stateObj = this._hass.states[entityConf.entity];
if(stateObj) {
let state = await this.applyTemplate(entityConf.state_template);
let mockState = this.getMockedState(stateObj, state);
let attributes = entityConf.attributes ? await this.getCardConfig(entityConf.attributes) : null;
let mockState = this.getMockedState(stateObj, state, attributes);
this._mockHass.states[entityConf.entity] = mockState;
}
}
Expand Down

0 comments on commit 4f62db1

Please sign in to comment.