Love: cleanup (#1362)

* Love: cleanup

* Fix
This commit is contained in:
c727 2018-06-29 05:16:01 +02:00 committed by GitHub
parent 51f169aa13
commit ee0308849e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 17 deletions

View File

@ -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);
}
}
}

View File

@ -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;