diff --git a/src/panels/lovelace/cards/hui-picture-entity-card.js b/src/panels/lovelace/cards/hui-picture-entity-card.js index f78bd6c06b..85488a3918 100644 --- a/src/panels/lovelace/cards/hui-picture-entity-card.js +++ b/src/panels/lovelace/cards/hui-picture-entity-card.js @@ -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); } } } diff --git a/src/panels/lovelace/common/validate-entity-config.js b/src/panels/lovelace/common/validate-entity-config.js index a211742de5..020edc7cf7 100644 --- a/src/panels/lovelace/common/validate-entity-config.js +++ b/src/panels/lovelace/common/validate-entity-config.js @@ -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;