mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-08 18:06:36 +00:00
parent
51f169aa13
commit
ee0308849e
@ -10,6 +10,7 @@ import computeStateDisplay from '../../../common/entity/compute_state_display.js
|
|||||||
import computeStateDomain from '../../../common/entity/compute_state_domain.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 createErrorCardConfig from '../common/create-error-card-config.js';
|
import createErrorCardConfig from '../common/create-error-card-config.js';
|
||||||
|
import toggleEntity from '../common/entity/toggle-entity.js';
|
||||||
|
|
||||||
import LocalizeMixin from '../../../mixins/localize-mixin.js';
|
import LocalizeMixin from '../../../mixins/localize-mixin.js';
|
||||||
|
|
||||||
@ -144,20 +145,7 @@ class HuiPictureEntityCard extends LocalizeMixin(PolymerElement) {
|
|||||||
if (stateDomain === 'weblink') {
|
if (stateDomain === 'weblink') {
|
||||||
window.open(this.hass.states[entityId].state);
|
window.open(this.hass.states[entityId].state);
|
||||||
} else {
|
} else {
|
||||||
const turnOn = STATES_OFF.includes(this.hass.states[entityId].state);
|
toggleEntity(this.hass, entityId);
|
||||||
let service;
|
|
||||||
switch (stateDomain) {
|
|
||||||
case 'lock':
|
|
||||||
service = turnOn ? 'unlock' : 'lock';
|
|
||||||
break;
|
|
||||||
case 'cover':
|
|
||||||
service = turnOn ? 'open_cover' : 'close_cover';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
service = turnOn ? 'turn_on' : 'turn_off';
|
|
||||||
}
|
|
||||||
const serviceDomain = stateDomain === 'group' ? 'homeassistant' : stateDomain;
|
|
||||||
this.hass.callService(serviceDomain, service, { entity_id: entityId });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
// check for valid value of config.entity with optinal entity dommain check
|
// check for valid value of config.entity with optinal entity dommain check
|
||||||
import computeDomain from '../../../common/entity/compute_domain.js';
|
import computeDomain from '../../../common/entity/compute_domain.js';
|
||||||
|
import validEntityId from '../../../common/entity/valid_entity_id';
|
||||||
|
|
||||||
export default function validateEntityConfig(config, domain = null) {
|
export default function validateEntityConfig(config, domain = null) {
|
||||||
const entity = config && config.entity;
|
const entityId = config && config.entity;
|
||||||
|
|
||||||
if (!entity || typeof entity !== 'string') {
|
if (!entityId || typeof entityId !== 'string' || !validEntityId(entityId)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (domain) {
|
if (domain) {
|
||||||
return computeDomain(entity) === domain;
|
return computeDomain(entityId) === domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user