Skip to content
This repository has been archived by the owner on Sep 18, 2020. It is now read-only.

Commit

Permalink
default to friendly name
Browse files Browse the repository at this point in the history
  • Loading branch information
ljmerza committed Nov 5, 2019
1 parent bf9e776 commit 9fb0b33
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions dist/calendar-card.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/calendar-card.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "calendar-card",
"version": "3.98.0",
"version": "3.100.1",
"description": "A calendar card for Home Assistant Lovelace UI",
"keywords": [
"home-assistant",
Expand Down
21 changes: 9 additions & 12 deletions src/index-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ export default class CalendarCardEditor extends LitElement {

const entityOptions = entities.map(eid => {
const matchingConfigEnitity = this._config.entities.find(entity => (entity && entity.entity || entity) === eid);

const originalEntity = this.hass.states[eid];

return {
entity: eid,
name: matchingConfigEnitity ? matchingConfigEnitity.name || eid : eid,
name: (matchingConfigEnitity && matchingConfigEnitity.name) || originalEntity.attributes.friendly_name || eid,
checked: !!matchingConfigEnitity
}
});
Expand All @@ -49,9 +50,7 @@ export default class CalendarCardEditor extends LitElement {
}

render() {
if (!this.hass) {
return html``;
}
if (!this.hass) return html``;

return html`
<div class="card-config">
Expand Down Expand Up @@ -258,10 +257,8 @@ export default class CalendarCardEditor extends LitElement {
* change the calendar name of an entity
* @param {*} ev
*/
entityNameChanged(ev){
entityNameChanged({ target: { entityId }, detail: { value } }){
if (this.cantFireEvent) return;
const { target: { entityId }, detail: { value } } = ev;

let entityObjects = [...this.entities];

entityObjects = entityObjects.map(entity => {
Expand All @@ -277,14 +274,14 @@ export default class CalendarCardEditor extends LitElement {
* add or remove calendar entities from config
* @param {*} ev
*/
entityChanged(ev){
entityChanged({ target: { entityId }, detail: { value } }){
if (this.cantFireEvent) return;
const { target: { entityId }, detail: { value } } = ev;

let entityObjects = [...this.entities];

if(value){
entityObjects.push({ entity: entityId, name: entityId });
const originalEntity = this.hass.states[entityId];
entityObjects.push({ entity: entityId, name: originalEntity.attributes.friendly_name || entityId });

} else {
entityObjects = entityObjects.filter(entity => entity.entity !== entityId);
}
Expand Down

0 comments on commit 9fb0b33

Please sign in to comment.