Skip to content

Commit 7b2dd01

Browse files
committed
Call correct service when toggling lock or cover entity (#32)
1 parent 2fe0e72 commit 7b2dd01

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

multiple-entity-row.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@
316316
break;
317317
}
318318
case 'toggle': {
319-
this._hass.callService('homeassistant', 'toggle', {entity_id: entityId});
319+
this.toggleEntity(entityId);
320320
this.forwardHaptic('light');
321321
break;
322322
}
@@ -337,6 +337,25 @@
337337
}
338338
}
339339

340+
toggleEntity(entityId) {
341+
const turnOn = ["closed", "locked", "off"].includes(this._hass.states[entityId].state);
342+
const stateDomain = entityId.split('.')[0];
343+
const serviceDomain = stateDomain === "group" ? "homeassistant" : stateDomain;
344+
345+
let service;
346+
switch (stateDomain) {
347+
case "lock":
348+
service = turnOn ? "unlock" : "lock";
349+
break;
350+
case "cover":
351+
service = turnOn ? "open_cover" : "close_cover";
352+
break;
353+
default:
354+
service = turnOn ? "turn_on" : "turn_off";
355+
}
356+
this._hass.callService(serviceDomain, service, {entity_id: entityId});
357+
}
358+
340359
fireEvent(node, type, detail = {}, options = {}) {
341360
const event = new Event(type, {
342361
bubbles: options.bubbles || true,

0 commit comments

Comments
 (0)