Add support for locks

This commit is contained in:
Paulus Schoutsen
2015-11-29 22:48:55 -08:00
parent 33124030f6
commit 300f3582a6
5 changed files with 42 additions and 36 deletions

View File

@@ -23,11 +23,12 @@ export default new Polymer({
toggleChanged(ev) {
const newVal = ev.target.checked;
const curVal = this._checkToggle(this.stateObj);
if (newVal && this.stateObj.state === 'off') {
this.turn_on();
} else if (!newVal && this.stateObj.state !== 'off') {
this.turn_off();
if (newVal && !curVal) {
this._call_service(true);
} else if (!newVal && curVal) {
this._call_service(false);
}
},
@@ -49,23 +50,27 @@ export default new Polymer({
this.toggleChecked = newState;
},
turn_on() {
// We call updateToggle after a successful call to re-sync the toggle
// with the state. It will be out of sync if our service call did not
// result in the entity to be turned on. Since the state is not changing,
// the resync is not called automatic.
serviceActions.callTurnOn(this.stateObj.entityId).then(() => this.forceStateChange());
},
turn_off() {
// We call updateToggle after a successful call to re-sync the toggle
// with the state. It will be out of sync if our service call did not
// result in the entity to be turned on. Since the state is not changing,
// the resync is not called automatic.
serviceActions.callTurnOff(this.stateObj.entityId).then(() => this.forceStateChange());
},
_checkToggle(stateObj) {
return stateObj && stateObj.state !== 'off';
return stateObj && stateObj.state !== 'off' && stateObj.state !== 'unlocked';
},
// We call updateToggle after a successful call to re-sync the toggle
// with the state. It will be out of sync if our service call did not
// result in the entity to be turned on. Since the state is not changing,
// the resync is not called automatic.
_call_service(turnOn) {
let domain;
let service;
if (this.stateObj.domain === 'lock') {
domain = 'lock';
service = turnOn ? 'lock' : 'unlock';
} else {
domain = 'homeassistant';
service = turnOn ? 'turn_on' : 'turn_off';
}
serviceActions.callService(domain, service, {entity_id: this.stateObj.entityId})
.then(() => this.forceStateChange());
},
});

View File

@@ -79,7 +79,7 @@ export default new Polymer({
return 'mdi:home-variant';
}
// state == 'disarmed'
return 'mdi:lock-open';
return domainIcon(state.domain, state.state);
case 'binary_sensor':
case 'device_tracker':
case 'scene':