mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-15 13:26:34 +00:00
Replace camera-preview card with picture-entity card. (#1393)
This commit is contained in:
parent
dc034038c0
commit
c0ae7d50ad
@ -1,15 +0,0 @@
|
|||||||
import '../../../cards/ha-camera-card.js';
|
|
||||||
|
|
||||||
import LegacyWrapperCard from './hui-legacy-wrapper-card.js';
|
|
||||||
|
|
||||||
class HuiCameraPreviewCard extends LegacyWrapperCard {
|
|
||||||
constructor() {
|
|
||||||
super('ha-camera-card', 'camera');
|
|
||||||
}
|
|
||||||
|
|
||||||
getCardSize() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
customElements.define('hui-camera-preview-card', HuiCameraPreviewCard);
|
|
@ -6,7 +6,6 @@ import '../components/hui-image.js';
|
|||||||
|
|
||||||
import computeDomain from '../../../common/entity/compute_domain.js';
|
import computeDomain from '../../../common/entity/compute_domain.js';
|
||||||
import computeStateDisplay from '../../../common/entity/compute_state_display.js';
|
import computeStateDisplay from '../../../common/entity/compute_state_display.js';
|
||||||
import computeStateDomain from '../../../common/entity/compute_state_domain.js';
|
|
||||||
import computeStateName from '../../../common/entity/compute_state_name.js';
|
import computeStateName from '../../../common/entity/compute_state_name.js';
|
||||||
import toggleEntity from '../common/entity/toggle-entity.js';
|
import toggleEntity from '../common/entity/toggle-entity.js';
|
||||||
|
|
||||||
@ -58,7 +57,7 @@ class HuiPictureEntityCard extends EventsMixin(LocalizeMixin(PolymerElement)) {
|
|||||||
hass="[[hass]]"
|
hass="[[hass]]"
|
||||||
image="[[_config.image]]"
|
image="[[_config.image]]"
|
||||||
state-image="[[_config.state_image]]"
|
state-image="[[_config.state_image]]"
|
||||||
camera-image="[[_config.camera_image]]"
|
camera-image="[[_getCameraImage(_config)]]"
|
||||||
entity="[[_config.entity]]"
|
entity="[[_config.entity]]"
|
||||||
></hui-image>
|
></hui-image>
|
||||||
<div class="info" hidden$='[[_computeHideInfo(_config)]]'>
|
<div class="info" hidden$='[[_computeHideInfo(_config)]]'>
|
||||||
@ -84,10 +83,16 @@ class HuiPictureEntityCard extends EventsMixin(LocalizeMixin(PolymerElement)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setConfig(config) {
|
setConfig(config) {
|
||||||
if (!config || !config.entity ||
|
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._entityDomain = computeDomain(config.entity);
|
||||||
|
if (this._entityDomain !== 'camera' &&
|
||||||
|
(!config.image && !config.state_image && !config.camera_image)) {
|
||||||
|
throw new Error('No image source configured.');
|
||||||
|
}
|
||||||
|
|
||||||
this._config = config;
|
this._config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,8 +130,7 @@ class HuiPictureEntityCard extends EventsMixin(LocalizeMixin(PolymerElement)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_computeStateLabel(stateObj) {
|
_computeStateLabel(stateObj) {
|
||||||
const domain = computeStateDomain(stateObj);
|
switch (this._entityDomain) {
|
||||||
switch (domain) {
|
|
||||||
case 'scene':
|
case 'scene':
|
||||||
return this.localize('ui.card.scene.activate');
|
return this.localize('ui.card.scene.activate');
|
||||||
case 'script':
|
case 'script':
|
||||||
@ -145,22 +149,24 @@ class HuiPictureEntityCard extends EventsMixin(LocalizeMixin(PolymerElement)) {
|
|||||||
|
|
||||||
_cardClicked() {
|
_cardClicked() {
|
||||||
const entityId = this._config && this._config.entity;
|
const entityId = this._config && this._config.entity;
|
||||||
const stateObj = this.hass.states[entityId];
|
|
||||||
|
|
||||||
if (!entityId || !stateObj) return;
|
if (!entityId || !(entityId in this.hass.states)) return;
|
||||||
|
|
||||||
if (this._config.tap_action !== 'toggle') {
|
if (this._config.tap_action !== 'toggle') {
|
||||||
this.fire('hass-more-info', { entityId });
|
this.fire('hass-more-info', { entityId });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const domain = computeDomain(entityId);
|
if (this._entityDomain === 'weblink') {
|
||||||
if (domain === 'weblink') {
|
|
||||||
window.open(this.hass.states[entityId].state);
|
window.open(this.hass.states[entityId].state);
|
||||||
} else {
|
} else {
|
||||||
toggleEntity(this.hass, entityId);
|
toggleEntity(this.hass, entityId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_getCameraImage(config) {
|
||||||
|
return this._entityDomain === 'camera' ? config.entity : config.camera_image;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define('hui-picture-entity-card', HuiPictureEntityCard);
|
customElements.define('hui-picture-entity-card', HuiPictureEntityCard);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import fireEvent from '../../../common/dom/fire_event.js';
|
import fireEvent from '../../../common/dom/fire_event.js';
|
||||||
|
|
||||||
import '../cards/hui-camera-preview-card.js';
|
|
||||||
import '../cards/hui-entities-card.js';
|
import '../cards/hui-entities-card.js';
|
||||||
import '../cards/hui-entity-filter-card.js';
|
import '../cards/hui-entity-filter-card.js';
|
||||||
import '../cards/hui-error-card.js';
|
import '../cards/hui-error-card.js';
|
||||||
@ -21,7 +20,6 @@ import '../cards/hui-weather-forecast-card';
|
|||||||
import createErrorCardConfig from './create-error-card-config.js';
|
import createErrorCardConfig from './create-error-card-config.js';
|
||||||
|
|
||||||
const CARD_TYPES = [
|
const CARD_TYPES = [
|
||||||
'camera-preview',
|
|
||||||
'entities',
|
'entities',
|
||||||
'entity-filter',
|
'entity-filter',
|
||||||
'error',
|
'error',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user