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

#86 Fix #90

Merged
merged 3 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions docs/example-cfg-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ for the assigned value of `data`:
* any `key in this.entity` (e.g., `entity_id`, `state`, ...)
* otherwise a key within `this.entity.attributes` will be assumed

When accessing attributes, sometimes an attribute object will itself contain objects.
In that case, you can access the lower object using dotted notation. eg: object1.object2.field1

If the chosen `data` selector does not resolve to something useful, the
cell will be marked with an error - collection/rendering should continue w/o any
issues.
Expand Down
23 changes: 22 additions & 1 deletion flex-table-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,28 @@ class DataRow {
} else {
// no matching data found, complain:
//raw_content.push("[[ no match ]]");
raw_content.push(null);

let pos = col_key.indexOf('.');
if (pos < 0)
{
raw_content.push(null);
}
else
{
// if the col_key field contains a dotted object (eg: day.monday)
// then traverse each object to ensure that it exists
// until the final object value is found.
// if at any point in the traversal, the object is not found
// then null will be used as the value.
let objs = col_key.split('.');
let value = this.entity.attributes;
if (value) {
for (let idx = 0; value && idx < objs.length; idx++) {
value = (objs[idx] in value) ? value[objs[idx]] : null;
}
}
raw_content.push(value);
}
}

// @todo: not really nice to clean `raw_content` up here, why
Expand Down