mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 00:06:35 +00:00
Add support for locks
This commit is contained in:
parent
33124030f6
commit
300f3582a6
@ -20,7 +20,7 @@
|
|||||||
"author": "Paulus Schoutsen <Paulus@PaulusSchoutsen.nl> (http://paulusschoutsen.nl)",
|
"author": "Paulus Schoutsen <Paulus@PaulusSchoutsen.nl> (http://paulusschoutsen.nl)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"home-assistant-js": "git+https://github.com/balloob/home-assistant-js.git#3a610931d99384bb1d666f022e8ff4ed17595f64",
|
"home-assistant-js": "git+https://github.com/balloob/home-assistant-js.git#1c29568abc9af18627cd70cab2262b32786cd63d",
|
||||||
"lodash": "^3.10.1",
|
"lodash": "^3.10.1",
|
||||||
"moment": "^2.10.6"
|
"moment": "^2.10.6"
|
||||||
},
|
},
|
||||||
|
@ -23,11 +23,12 @@ export default new Polymer({
|
|||||||
|
|
||||||
toggleChanged(ev) {
|
toggleChanged(ev) {
|
||||||
const newVal = ev.target.checked;
|
const newVal = ev.target.checked;
|
||||||
|
const curVal = this._checkToggle(this.stateObj);
|
||||||
|
|
||||||
if (newVal && this.stateObj.state === 'off') {
|
if (newVal && !curVal) {
|
||||||
this.turn_on();
|
this._call_service(true);
|
||||||
} else if (!newVal && this.stateObj.state !== 'off') {
|
} else if (!newVal && curVal) {
|
||||||
this.turn_off();
|
this._call_service(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -49,23 +50,27 @@ export default new Polymer({
|
|||||||
this.toggleChecked = newState;
|
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) {
|
_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';
|
return 'mdi:home-variant';
|
||||||
}
|
}
|
||||||
// state == 'disarmed'
|
// state == 'disarmed'
|
||||||
return 'mdi:lock-open';
|
return domainIcon(state.domain, state.state);
|
||||||
case 'binary_sensor':
|
case 'binary_sensor':
|
||||||
case 'device_tracker':
|
case 'device_tracker':
|
||||||
case 'scene':
|
case 'scene':
|
||||||
|
@ -19,8 +19,6 @@ const PRIORITY = {
|
|||||||
binary_sensor: 6,
|
binary_sensor: 6,
|
||||||
scene: 7,
|
scene: 7,
|
||||||
script: 8,
|
script: 8,
|
||||||
thermostat: 40,
|
|
||||||
media_player: 50,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function getPriority(domain) {
|
function getPriority(domain) {
|
||||||
|
@ -3,10 +3,10 @@ import defaultIcon from './default-icon';
|
|||||||
export default function domainIcon(domain, state) {
|
export default function domainIcon(domain, state) {
|
||||||
switch (domain) {
|
switch (domain) {
|
||||||
case 'alarm_control_panel':
|
case 'alarm_control_panel':
|
||||||
return state && state === 'disarmed' ? 'mdi:lock-open' : 'mdi:lock';
|
return state && state === 'disarmed' ? 'mdi:bell-outline' : 'mdi:bell';
|
||||||
|
|
||||||
case 'binary_sensor':
|
case 'binary_sensor':
|
||||||
return state && state === 'off' ? 'mdi:radiobox-blank' : 'mdi:radiobox-marked';
|
return state && state === 'off' ? 'mdi:radiobox-blank' : 'mdi:checkbox-marked-circle';
|
||||||
|
|
||||||
case 'camera':
|
case 'camera':
|
||||||
return 'mdi:video';
|
return 'mdi:video';
|
||||||
@ -29,6 +29,9 @@ export default function domainIcon(domain, state) {
|
|||||||
case 'light':
|
case 'light':
|
||||||
return 'mdi:lightbulb';
|
return 'mdi:lightbulb';
|
||||||
|
|
||||||
|
case 'lock':
|
||||||
|
return state && state === 'unlocked' ? 'mdi:lock-open' : 'mdi:lock';
|
||||||
|
|
||||||
case 'media_player':
|
case 'media_player':
|
||||||
let icon = 'mdi:cast';
|
let icon = 'mdi:cast';
|
||||||
if (state && state !== 'off' && state !== 'idle') {
|
if (state && state !== 'off' && state !== 'idle') {
|
||||||
@ -43,15 +46,6 @@ export default function domainIcon(domain, state) {
|
|||||||
case 'updater':
|
case 'updater':
|
||||||
return 'mdi:cloud-upload';
|
return 'mdi:cloud-upload';
|
||||||
|
|
||||||
case 'sun':
|
|
||||||
return 'mdi:white-balance-sunny';
|
|
||||||
|
|
||||||
case 'switch':
|
|
||||||
return 'mdi:flash';
|
|
||||||
|
|
||||||
case 'simple_alarm':
|
|
||||||
return 'mdi:bell';
|
|
||||||
|
|
||||||
case 'scene':
|
case 'scene':
|
||||||
return 'mdi:google-pages';
|
return 'mdi:google-pages';
|
||||||
|
|
||||||
@ -61,6 +55,15 @@ export default function domainIcon(domain, state) {
|
|||||||
case 'sensor':
|
case 'sensor':
|
||||||
return 'mdi:eye';
|
return 'mdi:eye';
|
||||||
|
|
||||||
|
case 'simple_alarm':
|
||||||
|
return 'mdi:bell';
|
||||||
|
|
||||||
|
case 'sun':
|
||||||
|
return 'mdi:white-balance-sunny';
|
||||||
|
|
||||||
|
case 'switch':
|
||||||
|
return 'mdi:flash';
|
||||||
|
|
||||||
case 'thermostat':
|
case 'thermostat':
|
||||||
return 'mdi:nest-thermostat';
|
return 'mdi:nest-thermostat';
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user