Localize lock dialog (#1249)

* Localize lock dialog

* Fix attribute binding

* Add ev
This commit is contained in:
c727 2018-06-03 13:37:35 +02:00 committed by Paulus Schoutsen
parent d16f4c846a
commit cb284d9718
2 changed files with 32 additions and 30 deletions

View File

@ -5,30 +5,32 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../../../components/ha-attributes.js'; import '../../../components/ha-attributes.js';
class MoreInfoLock extends PolymerElement { import LocalizeMixin from '../../../mixins/localize-mixin.js';
/*
* @appliesMixin LocalizeMixin
*/
class MoreInfoLock extends LocalizeMixin(PolymerElement) {
static get template() { static get template() {
return html` return html`
<style> <style>
paper-input { paper-input {
display: inline-block; display: inline-block;
} }
</style> </style>
<div hidden\$="[[!stateObj.attributes.code_format]]"> <template is="dom-if" if="[[stateObj.attributes.code_format]]">
<paper-input label="code" value="{{enteredCode}}" pattern="[[stateObj.attributes.code_format]]" type="password"></paper-input> <paper-input label="[[localize('ui.card.lock.code')]]" value="{{enteredCode}}" pattern="[[stateObj.attributes.code_format]]" type="password"></paper-input>
<paper-button on-click="handleUnlockTap" hidden\$="[[!isLocked]]">Unlock</paper-button> <paper-button on-click="callService" data-service="unlock" hidden$="[[!isLocked]]">[[localize('ui.card.lock.unlock')]]</paper-button>
<paper-button on-click="handleLockTap" hidden\$="[[isLocked]]">Lock</paper-button> <paper-button on-click="callService" data-service="lock" hidden$="[[isLocked]]">[[localize('ui.card.lock.lock')]]</paper-button>
</div> </template>
<ha-attributes state-obj="[[stateObj]]" extra-filters="code_format"></ha-attributes> <ha-attributes state-obj="[[stateObj]]" extra-filters="code_format"></ha-attributes>
`; `;
} }
static get properties() { static get properties() {
return { return {
hass: { hass: Object,
type: Object,
},
stateObj: { stateObj: {
type: Object, type: Object,
observer: 'stateObjChanged', observer: 'stateObjChanged',
@ -37,28 +39,23 @@ class MoreInfoLock extends PolymerElement {
type: String, type: String,
value: '', value: '',
}, },
isLocked: Boolean, isLocked: Boolean
}; };
} }
handleUnlockTap() {
this.callService('unlock', { code: this.enteredCode });
}
handleLockTap() {
this.callService('lock', { code: this.enteredCode });
}
stateObjChanged(newVal) { stateObjChanged(newVal) {
if (newVal) { if (newVal) {
this.isLocked = newVal.state === 'locked'; this.isLocked = newVal.state === 'locked';
} }
} }
callService(service, data) { callService(ev) {
var serviceData = data || {}; const service = ev.target.getAttribute('data-service');
serviceData.entity_id = this.stateObj.entity_id; const data = {
this.hass.callService('lock', service, serviceData); entity_id: this.stateObj.entity_id,
code: this.enteredCode
};
this.hass.callService('lock', service, data);
} }
} }

View File

@ -344,6 +344,11 @@
"white_value": "White value", "white_value": "White value",
"effect": "Effect" "effect": "Effect"
}, },
"lock": {
"code": "[%key:ui::card::alarm_control_panel::code%]",
"lock": "Lock",
"unlock": "Unlock"
},
"media_player": { "media_player": {
"text_to_speak": "Text to speak" "text_to_speak": "Text to speak"
}, },