mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-17 06:16:33 +00:00
Fix image filtering when no off state is defined (#1379)
* Fix image filtering when no off state is defined * Change Offline to Unavailable.
This commit is contained in:
parent
22ee205807
commit
06cf03bff0
@ -12,7 +12,7 @@ import toggleEntity from '../common/entity/toggle-entity.js';
|
|||||||
|
|
||||||
import LocalizeMixin from '../../../mixins/localize-mixin.js';
|
import LocalizeMixin from '../../../mixins/localize-mixin.js';
|
||||||
|
|
||||||
const OFFLINE = 'Offline';
|
const UNAVAILABLE = 'Unavailable';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @appliesMixin LocalizeMixin
|
* @appliesMixin LocalizeMixin
|
||||||
@ -89,7 +89,7 @@ class HuiPictureEntityCard extends LocalizeMixin(PolymerElement) {
|
|||||||
if (!entityId) {
|
if (!entityId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!(entityId in hass.states) && this._oldState === OFFLINE) {
|
if (!(entityId in hass.states) && this._oldState === UNAVAILABLE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!(entityId in hass.states) || hass.states[entityId].state !== this._oldState) {
|
if (!(entityId in hass.states) || hass.states[entityId].state !== this._oldState) {
|
||||||
@ -98,12 +98,12 @@ class HuiPictureEntityCard extends LocalizeMixin(PolymerElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_updateState(hass, entityId, config) {
|
_updateState(hass, entityId, config) {
|
||||||
const state = entityId in hass.states ? hass.states[entityId].state : OFFLINE;
|
const state = entityId in hass.states ? hass.states[entityId].state : UNAVAILABLE;
|
||||||
|
|
||||||
this.$.title.innerText = config.title || (state === OFFLINE ?
|
this.$.title.innerText = config.title || (state === UNAVAILABLE ?
|
||||||
entityId : computeStateName(hass.states[entityId]));
|
entityId : computeStateName(hass.states[entityId]));
|
||||||
this.$.state.innerText = state === OFFLINE ?
|
this.$.state.innerText = state === UNAVAILABLE ?
|
||||||
OFFLINE : this._computeState(hass.states[entityId]);
|
UNAVAILABLE : this._computeState(hass.states[entityId]);
|
||||||
this._oldState = state;
|
this._oldState = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,16 +107,19 @@ class HuiImage extends LocalizeMixin(PolymerElement) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const unavailable = !isValidObject(state, ['state']);
|
||||||
|
|
||||||
if (!this.stateImage) {
|
if (!this.stateImage) {
|
||||||
this._imageClass = (!isValidObject(state, ['state']) || STATES_OFF.includes(state.state)) ? 'state-off' : '';
|
this._imageClass = unavailable || STATES_OFF.includes(state.state) ? 'state-off' : '';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const stateImg = isValidObject(state, ['state']) ? this.stateImage[state.state] : this.stateImage.offline;
|
const stateImg = !unavailable ?
|
||||||
|
(this.stateImage[state.state] || this.stateImage.default) : this.stateImage.unavailable;
|
||||||
|
|
||||||
this.setProperties({
|
this.setProperties({
|
||||||
_imageSrc: stateImg || this.stateImage.default || this.image,
|
_imageClass: !stateImg && (unavailable || STATES_OFF.includes(state.state)) ? 'state-off' : '',
|
||||||
_imageClass: ''
|
_imageSrc: stateImg || this.image
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user