Hide name or state in picture entity (#1511)

* Hide name or state in picture entity

* Lint
This commit is contained in:
c727 2018-07-24 13:54:54 +02:00 committed by Paulus Schoutsen
parent 5e91fbc54f
commit 201959841c
2 changed files with 63 additions and 33 deletions

View File

@ -36,12 +36,31 @@ const CONFIGS = [
` `
}, },
{ {
heading: 'Hidden info', heading: 'Hidden name',
config: ` config: `
- type: picture-entity - type: picture-entity
image: /images/kitchen.png image: /images/kitchen.png
entity: light.kitchen_lights entity: light.kitchen_lights
show_info: false show_name: false
`
},
{
heading: 'Hidden state',
config: `
- type: picture-entity
image: /images/kitchen.png
entity: light.kitchen_lights
show_state: false
`
},
{
heading: 'Both hidden',
config: `
- type: picture-entity
image: /images/kitchen.png
entity: light.kitchen_lights
show_name: false
show_state: false
` `
}, },
]; ];

View File

@ -30,7 +30,7 @@ class HuiPictureEntityCard extends EventsMixin(LocalizeMixin(PolymerElement)) {
ha-card.canInteract { ha-card.canInteract {
cursor: pointer; cursor: pointer;
} }
.info { .footer {
@apply --paper-font-common-nowrap; @apply --paper-font-common-nowrap;
position: absolute; position: absolute;
left: 0; left: 0;
@ -41,14 +41,13 @@ class HuiPictureEntityCard extends EventsMixin(LocalizeMixin(PolymerElement)) {
font-size: 16px; font-size: 16px;
line-height: 16px; line-height: 16px;
color: white; color: white;
}
.both {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
} }
#title { .state {
font-weight: 500; text-align: right;
}
[hidden] {
display: none;
} }
</style> </style>
@ -60,10 +59,22 @@ class HuiPictureEntityCard extends EventsMixin(LocalizeMixin(PolymerElement)) {
camera-image="[[_getCameraImage(_config)]]" camera-image="[[_getCameraImage(_config)]]"
entity="[[_config.entity]]" entity="[[_config.entity]]"
></hui-image> ></hui-image>
<div class="info" hidden$='[[_computeHideInfo(_config)]]'> <template is="dom-if" if="[[_showNameAndState(_config)]]">
<div id="name"></div> <div class="footer both">
<div id="state"></div> <div>[[_name]]</div>
<div>[[_state]]</div>
</div> </div>
</template>
<template is="dom-if" if="[[_showName(_config)]]">
<div class="footer">
[[_name]]
</div>
</template>
<template is="dom-if" if="[[_showState(_config)]]">
<div class="footer state">
[[_state]]
</div>
</template>
</ha-card> </ha-card>
`; `;
} }
@ -75,6 +86,8 @@ class HuiPictureEntityCard extends EventsMixin(LocalizeMixin(PolymerElement)) {
observer: '_hassChanged' observer: '_hassChanged'
}, },
_config: Object, _config: Object,
_name: String,
_state: String
}; };
} }
@ -110,41 +123,39 @@ class HuiPictureEntityCard extends EventsMixin(LocalizeMixin(PolymerElement)) {
let name; let name;
let state; let state;
let stateLabel; let stateLabel;
let canInteract = true; let available;
if (stateObj) { if (stateObj) {
name = config.name || computeStateName(stateObj); name = config.name || computeStateName(stateObj);
state = stateObj.state; state = stateObj.state;
stateLabel = this._computeStateLabel(stateObj); stateLabel = computeStateDisplay(this.localize, stateObj);
available = true;
} else { } else {
name = config.name || entityId; name = config.name || entityId;
state = UNAVAILABLE; state = UNAVAILABLE;
stateLabel = UNAVAILABLE; stateLabel = this.localize('state.default.unavailable');
canInteract = false; available = false;
} }
this.$.name.innerText = name; this.setProperties({
this.$.state.innerText = stateLabel; _name: name,
this._oldState = state; _state: stateLabel,
this.$.card.classList.toggle('canInteract', canInteract); _oldState: state
});
this.$.card.classList.toggle('canInteract', available);
} }
_computeStateLabel(stateObj) { _showNameAndState(config) {
switch (this._entityDomain) { return config.show_name !== false && config.show_state !== false;
case 'scene':
return this.localize('ui.card.scene.activate');
case 'script':
return this.localize('ui.card.script.execute');
case 'weblink':
return 'Open';
default:
return computeStateDisplay(this.localize, stateObj);
}
} }
_computeHideInfo(config) { _showName(config) {
// By default we will show it, so === undefined should be true. return config.show_name !== false && config.show_state === false;
return config.show_info === false; }
_showState(config) {
return config.show_name === false && config.show_state !== false;
} }
_cardClicked() { _cardClicked() {