mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-15 13:26:34 +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';
|
||||
|
||||
const OFFLINE = 'Offline';
|
||||
const UNAVAILABLE = 'Unavailable';
|
||||
|
||||
/*
|
||||
* @appliesMixin LocalizeMixin
|
||||
@ -89,7 +89,7 @@ class HuiPictureEntityCard extends LocalizeMixin(PolymerElement) {
|
||||
if (!entityId) {
|
||||
return;
|
||||
}
|
||||
if (!(entityId in hass.states) && this._oldState === OFFLINE) {
|
||||
if (!(entityId in hass.states) && this._oldState === UNAVAILABLE) {
|
||||
return;
|
||||
}
|
||||
if (!(entityId in hass.states) || hass.states[entityId].state !== this._oldState) {
|
||||
@ -98,12 +98,12 @@ class HuiPictureEntityCard extends LocalizeMixin(PolymerElement) {
|
||||
}
|
||||
|
||||
_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]));
|
||||
this.$.state.innerText = state === OFFLINE ?
|
||||
OFFLINE : this._computeState(hass.states[entityId]);
|
||||
this.$.state.innerText = state === UNAVAILABLE ?
|
||||
UNAVAILABLE : this._computeState(hass.states[entityId]);
|
||||
this._oldState = state;
|
||||
}
|
||||
|
||||
|
@ -107,16 +107,19 @@ class HuiImage extends LocalizeMixin(PolymerElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
const unavailable = !isValidObject(state, ['state']);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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({
|
||||
_imageSrc: stateImg || this.stateImage.default || this.image,
|
||||
_imageClass: ''
|
||||
_imageClass: !stateImg && (unavailable || STATES_OFF.includes(state.state)) ? 'state-off' : '',
|
||||
_imageSrc: stateImg || this.image
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user