From e7725d5bd18bcdafcfafa02db76dda319e950d89 Mon Sep 17 00:00:00 2001 From: Ruslan Tursunov Date: Thu, 6 Jul 2023 20:44:59 +0300 Subject: [PATCH] allow new format for local_key --- bin/cli-decode.js | 3 +-- index.js | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/bin/cli-decode.js b/bin/cli-decode.js index 0c0b267..5395a73 100644 --- a/bin/cli-decode.js +++ b/bin/cli-decode.js @@ -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; } @@ -210,4 +210,3 @@ async.auto({ }); }] }); - diff --git a/index.js b/index.js index e1892a5..8635705 100644 --- a/index.js +++ b/index.js @@ -41,7 +41,7 @@ const CLASS_DEF = { convector: ConvectorAccessory, garagedoor: GarageDoorAccessory, simpledimmer: SimpleDimmerAccessory, - simpledimmer2: SimpleDimmer2Accessory, + simpledimmer2: SimpleDimmer2Accessory, simpleblinds: SimpleBlindsAccessory, simpleblinds2: SimpleBlinds2Accessory, simpleheater: SimpleHeaterAccessory, @@ -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);