mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-09 10:59:50 +00:00
Add support for locks
This commit is contained in:
@@ -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());
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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':
|
||||
|
||||
Reference in New Issue
Block a user