mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 07:16:39 +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)",
|
||||
"license": "MIT",
|
||||
"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",
|
||||
"moment": "^2.10.6"
|
||||
},
|
||||
|
@ -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':
|
||||
|
@ -19,8 +19,6 @@ const PRIORITY = {
|
||||
binary_sensor: 6,
|
||||
scene: 7,
|
||||
script: 8,
|
||||
thermostat: 40,
|
||||
media_player: 50,
|
||||
};
|
||||
|
||||
function getPriority(domain) {
|
||||
|
@ -3,10 +3,10 @@ import defaultIcon from './default-icon';
|
||||
export default function domainIcon(domain, state) {
|
||||
switch (domain) {
|
||||
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':
|
||||
return state && state === 'off' ? 'mdi:radiobox-blank' : 'mdi:radiobox-marked';
|
||||
return state && state === 'off' ? 'mdi:radiobox-blank' : 'mdi:checkbox-marked-circle';
|
||||
|
||||
case 'camera':
|
||||
return 'mdi:video';
|
||||
@ -29,6 +29,9 @@ export default function domainIcon(domain, state) {
|
||||
case 'light':
|
||||
return 'mdi:lightbulb';
|
||||
|
||||
case 'lock':
|
||||
return state && state === 'unlocked' ? 'mdi:lock-open' : 'mdi:lock';
|
||||
|
||||
case 'media_player':
|
||||
let icon = 'mdi:cast';
|
||||
if (state && state !== 'off' && state !== 'idle') {
|
||||
@ -43,15 +46,6 @@ export default function domainIcon(domain, state) {
|
||||
case 'updater':
|
||||
return 'mdi:cloud-upload';
|
||||
|
||||
case 'sun':
|
||||
return 'mdi:white-balance-sunny';
|
||||
|
||||
case 'switch':
|
||||
return 'mdi:flash';
|
||||
|
||||
case 'simple_alarm':
|
||||
return 'mdi:bell';
|
||||
|
||||
case 'scene':
|
||||
return 'mdi:google-pages';
|
||||
|
||||
@ -61,6 +55,15 @@ export default function domainIcon(domain, state) {
|
||||
case 'sensor':
|
||||
return 'mdi:eye';
|
||||
|
||||
case 'simple_alarm':
|
||||
return 'mdi:bell';
|
||||
|
||||
case 'sun':
|
||||
return 'mdi:white-balance-sunny';
|
||||
|
||||
case 'switch':
|
||||
return 'mdi:flash';
|
||||
|
||||
case 'thermostat':
|
||||
return 'mdi:nest-thermostat';
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user