mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-08 09:56: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 computeStateName from '../../../common/entity/compute_state_name.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';
|
||||
|
||||
@ -144,20 +145,7 @@ class HuiPictureEntityCard extends LocalizeMixin(PolymerElement) {
|
||||
if (stateDomain === 'weblink') {
|
||||
window.open(this.hass.states[entityId].state);
|
||||
} else {
|
||||
const turnOn = STATES_OFF.includes(this.hass.states[entityId].state);
|
||||
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 });
|
||||
toggleEntity(this.hass, entityId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,16 @@
|
||||
// check for valid value of config.entity with optinal entity dommain check
|
||||
import computeDomain from '../../../common/entity/compute_domain.js';
|
||||
import validEntityId from '../../../common/entity/valid_entity_id';
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (domain) {
|
||||
return computeDomain(entity) === domain;
|
||||
return computeDomain(entityId) === domain;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user