mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 15:26:36 +00:00
* Bugfix for #10754 * Adjustments * Fix sloppiness
This commit is contained in:
parent
80a11206af
commit
5f5a62d094
@ -46,11 +46,13 @@
|
|||||||
<div class='card-actions'>
|
<div class='card-actions'>
|
||||||
<paper-input
|
<paper-input
|
||||||
label='User code'
|
label='User code'
|
||||||
type=number
|
type='text'
|
||||||
value='{{selectedUserCodeValue}}'
|
allowed-pattern='[0-9,a-f,x,\\]'
|
||||||
maxlength='{{userCodeMaxLen}}'
|
maxlength='{{userCodeMaxLen}}'
|
||||||
min='0'>
|
minlength='16'
|
||||||
|
value='{{selectedUserCodeValue}}'>
|
||||||
</paper-input>
|
</paper-input>
|
||||||
|
<pre>Ascii: [[[computedCodeOutput]]]</pre>
|
||||||
</div>
|
</div>
|
||||||
<div class='card-actions'>
|
<div class='card-actions'>
|
||||||
<ha-call-service-button
|
<ha-call-service-button
|
||||||
@ -106,8 +108,12 @@ class ZwaveUsercodes extends Polymer.Element {
|
|||||||
},
|
},
|
||||||
|
|
||||||
selectedUserCodeValue: {
|
selectedUserCodeValue: {
|
||||||
type: Number,
|
type: String,
|
||||||
value: -1
|
},
|
||||||
|
|
||||||
|
computedCodeOutput: {
|
||||||
|
type: String,
|
||||||
|
value: ''
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -137,10 +143,10 @@ class ZwaveUsercodes extends Polymer.Element {
|
|||||||
|
|
||||||
selectedUserCodeChanged(selectedUserCode) {
|
selectedUserCodeChanged(selectedUserCode) {
|
||||||
if (this.selectedUserCode === -1 || selectedUserCode === -1) return;
|
if (this.selectedUserCode === -1 || selectedUserCode === -1) return;
|
||||||
var value = (parseInt((this.userCodes[selectedUserCode].value.code).trim()));
|
var value = this.userCodes[selectedUserCode].value.code;
|
||||||
this.userCodeMaxLen = (this.userCodes[selectedUserCode].value.length);
|
this.userCodeMaxLen = (this.userCodes[selectedUserCode].value.length * 4);
|
||||||
if (isNaN(value)) this.selectedUserCodeValue = '';
|
this.selectedUserCodeValue = this.a2hex(value);
|
||||||
else this.selectedUserCodeValue = value;
|
this.computedCodeOutput = this.hex2a(this.selectedUserCodeValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
computeUserCodeServiceData(selectedUserCodeValue, type) {
|
computeUserCodeServiceData(selectedUserCodeValue, type) {
|
||||||
@ -148,7 +154,8 @@ class ZwaveUsercodes extends Polymer.Element {
|
|||||||
var serviceData = null;
|
var serviceData = null;
|
||||||
var valueData = null;
|
var valueData = null;
|
||||||
if (type === 'Add') {
|
if (type === 'Add') {
|
||||||
valueData = selectedUserCodeValue;
|
valueData = this.hex2a(selectedUserCodeValue);
|
||||||
|
this.computedCodeOutput = valueData;
|
||||||
serviceData = {
|
serviceData = {
|
||||||
node_id: this.nodes[this.selectedNode].attributes.node_id,
|
node_id: this.nodes[this.selectedNode].attributes.node_id,
|
||||||
code_slot: this.selectedUserCode,
|
code_slot: this.selectedUserCode,
|
||||||
@ -178,6 +185,31 @@ class ZwaveUsercodes extends Polymer.Element {
|
|||||||
this.selectedUserCodeChanged(this.selectedUserCode);
|
this.selectedUserCodeChanged(this.selectedUserCode);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a2hex(str) {
|
||||||
|
var arr = [];
|
||||||
|
var output = '';
|
||||||
|
for (var i = 0, l = str.length; i < l; i++) {
|
||||||
|
var hex = Number(str.charCodeAt(i)).toString(16);
|
||||||
|
if (hex === '0') {
|
||||||
|
output = '00';
|
||||||
|
} else {
|
||||||
|
output = hex;
|
||||||
|
}
|
||||||
|
arr.push('\\x' + output);
|
||||||
|
}
|
||||||
|
return arr.join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
hex2a(hexx) {
|
||||||
|
var hex = hexx.toString();
|
||||||
|
var hexMod = hex.replace(/\\x/g, '');
|
||||||
|
var str = '';
|
||||||
|
for (var i = 0; i < hexMod.length; i += 2) {
|
||||||
|
str += String.fromCharCode(parseInt(hexMod.substr(i, 2), 16));
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define(ZwaveUsercodes.is, ZwaveUsercodes);
|
customElements.define(ZwaveUsercodes.is, ZwaveUsercodes);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user