Skip to content

Commit

Permalink
allow new format for local_key
Browse files Browse the repository at this point in the history
  • Loading branch information
justerror committed Jul 6, 2023
1 parent 8f44944 commit e7725d5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions bin/cli-decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const getCRC32 = buffer => {

const checkKey = key => {
if (!key) return false;
if (!/^[0-9a-f]+$/i.test(key)) {
if (!/^[a-zA-Z0-9!@#$%\^&*)(+=._-]+$/i.test(key)) {
console.log('*** The key contains invalid characters; try again.');
return false;
}
Expand Down Expand Up @@ -210,4 +210,3 @@ async.auto({
});
}]
});

4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const CLASS_DEF = {
convector: ConvectorAccessory,
garagedoor: GarageDoorAccessory,
simpledimmer: SimpleDimmerAccessory,
simpledimmer2: SimpleDimmer2Accessory,
simpledimmer2: SimpleDimmer2Accessory,
simpleblinds: SimpleBlindsAccessory,
simpleblinds2: SimpleBlinds2Accessory,
simpleheater: SimpleHeaterAccessory,
Expand Down Expand Up @@ -96,7 +96,7 @@ class TuyaLan {
} catch(ex) {}

//if (!/^[0-9a-f]+$/i.test(device.id)) return this.log.error('%s, id for %s, is not a valid id.', device.id, device.name || 'unnamed device');
if (!/^[0-9a-f]+$/i.test(device.key)) return this.log.error('%s, key for %s (%s), is not a valid key.', device.key.replace(/.{4}$/, '****'), device.name || 'unnamed device', device.id);
if (!/^[a-zA-Z0-9!@#$%\^&*)(+=._-]+$/i.test(device.key)) return this.log.error('%s, key for %s (%s), is not a valid key.', device.key.replace(/.{4}$/, '****'), device.name || 'unnamed device', device.id);
if (!{16:1, 24:1, 32: 1}[device.key.length]) return this.log.error('%s, key for %s (%s), doesn\'t have the expected length.', device.key.replace(/.{4}$/, '****'), device.name || 'unnamed device', device.id);
if (!device.type) return this.log.error('%s (%s) doesn\'t have a type defined.', device.name || 'Unnamed device', device.id);
if (!CLASS_DEF[device.type.toLowerCase()]) return this.log.error('%s (%s) doesn\'t have a valid type defined.', device.name || 'Unnamed device', device.id);
Expand Down

0 comments on commit e7725d5

Please sign in to comment.