mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 15:26:36 +00:00
Love: Update hui-image to use entity instead of state. (#1386)
* Update hui-image to use entity instead of state. * Removed old function.
This commit is contained in:
parent
66803cd4eb
commit
918c2ce29e
@ -52,7 +52,7 @@ class HuiPictureEntityCard extends LocalizeMixin(PolymerElement) {
|
|||||||
image="[[_config.image]]"
|
image="[[_config.image]]"
|
||||||
state-image="[[_config.state_image]]"
|
state-image="[[_config.state_image]]"
|
||||||
camera-image="[[_config.camera_image]]"
|
camera-image="[[_config.camera_image]]"
|
||||||
state="[[_getStateObj(_oldState)]]"
|
entity="[[_config.entity]]"
|
||||||
></hui-image>
|
></hui-image>
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div id="title"></div>
|
<div id="title"></div>
|
||||||
@ -77,7 +77,8 @@ class HuiPictureEntityCard extends LocalizeMixin(PolymerElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setConfig(config) {
|
setConfig(config) {
|
||||||
if (!config || !config.entity || (!config.image && !config.state_image)) {
|
if (!config || !config.entity ||
|
||||||
|
(!config.image && !config.state_image && !config.camera_image)) {
|
||||||
throw new Error('Error in card configuration.');
|
throw new Error('Error in card configuration.');
|
||||||
}
|
}
|
||||||
this._config = config;
|
this._config = config;
|
||||||
@ -134,10 +135,6 @@ class HuiPictureEntityCard extends LocalizeMixin(PolymerElement) {
|
|||||||
toggleEntity(this.hass, entityId);
|
toggleEntity(this.hass, entityId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_getStateObj() {
|
|
||||||
return this.hass && this.hass.states[this._config.entity];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define('hui-picture-entity-card', HuiPictureEntityCard);
|
customElements.define('hui-picture-entity-card', HuiPictureEntityCard);
|
||||||
|
@ -60,7 +60,9 @@ class HuiPictureGlanceCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
|||||||
<hui-image
|
<hui-image
|
||||||
hass="[[hass]]"
|
hass="[[hass]]"
|
||||||
image="[[_config.image]]"
|
image="[[_config.image]]"
|
||||||
|
state-image="[[_config.state_image]]"
|
||||||
camera-image="[[_config.camera_image]]"
|
camera-image="[[_config.camera_image]]"
|
||||||
|
entity="[[_config.entity]]"
|
||||||
></hui-image>
|
></hui-image>
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="title">[[_config.title]]</div>
|
<div class="title">[[_config.title]]</div>
|
||||||
@ -115,7 +117,8 @@ class HuiPictureGlanceCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
|||||||
|
|
||||||
setConfig(config) {
|
setConfig(config) {
|
||||||
if (!config || !config.entities || !Array.isArray(config.entities) ||
|
if (!config || !config.entities || !Array.isArray(config.entities) ||
|
||||||
!(config.image || config.camera_image)) {
|
!(config.image || config.camera_image || config.state_image) ||
|
||||||
|
(config.state_image && !config.entity)) {
|
||||||
throw new Error('Invalid card configuration');
|
throw new Error('Invalid card configuration');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,12 +49,11 @@ class HuiImage extends LocalizeMixin(PolymerElement) {
|
|||||||
|
|
||||||
static get properties() {
|
static get properties() {
|
||||||
return {
|
return {
|
||||||
hass: Object,
|
hass: {
|
||||||
state: {
|
|
||||||
type: Object,
|
type: Object,
|
||||||
value: null,
|
observer: '_hassChanged'
|
||||||
observer: '_stateChanged'
|
|
||||||
},
|
},
|
||||||
|
entity: String,
|
||||||
image: String,
|
image: String,
|
||||||
stateImage: Object,
|
stateImage: Object,
|
||||||
cameraImage: String,
|
cameraImage: String,
|
||||||
@ -102,11 +101,12 @@ class HuiImage extends LocalizeMixin(PolymerElement) {
|
|||||||
this._error = false;
|
this._error = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_stateChanged(state) {
|
_hassChanged(hass) {
|
||||||
if (this.cameraImage) {
|
if (this.cameraImage || !this.entity) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const state = hass.states[this.entity];
|
||||||
const unavailable = !isValidObject(state, ['state']);
|
const unavailable = !isValidObject(state, ['state']);
|
||||||
|
|
||||||
if (!this.stateImage) {
|
if (!this.stateImage) {
|
||||||
@ -114,8 +114,7 @@ class HuiImage extends LocalizeMixin(PolymerElement) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const stateImg = !unavailable ?
|
const stateImg = !unavailable ? this.stateImage[state.state] : this.stateImage.unavailable;
|
||||||
(this.stateImage[state.state] || this.stateImage.default) : this.stateImage.unavailable;
|
|
||||||
|
|
||||||
this.setProperties({
|
this.setProperties({
|
||||||
_imageClass: !stateImg && (unavailable || STATES_OFF.includes(state.state)) ? 'state-off' : '',
|
_imageClass: !stateImg && (unavailable || STATES_OFF.includes(state.state)) ? 'state-off' : '',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user