Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow new format for local_key #418

Merged
merged 3 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions bin/cli-decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,6 @@ const getCRC32 = buffer => {
return ~crc;
};

const checkKey = key => {
if (!key) return false;
if (!/^[0-9a-f]+$/i.test(key)) {
console.log('*** The key contains invalid characters; try again.');
return false;
}

if (!{16:1, 24:1, 32: 1}[key.length]) {
console.log('*** The key contains the wrong number of characters; try again.');
return false;
}

return true;
};

const decodeLine = (key, input, log = true) => {
const encoding = (input.substr(0, 8) === '000055aa') ? 'hex' : 'base64';

Expand Down Expand Up @@ -140,7 +125,7 @@ const decodeLine = (key, input, log = true) => {

async.auto({
Key: next => {
if (program.key && checkKey(program.key)) return next(null, program.key);
if (program.key) return next(null, program.key);

const rl = readline.createInterface({
input: process.stdin,
Expand All @@ -153,7 +138,7 @@ async.auto({

rl.on('line', line => {
const input = line.trim();
if (!checkKey(input)) return rl.prompt();
if (!input) return rl.prompt();

rl.close();
next(null, input);
Expand Down Expand Up @@ -210,4 +195,3 @@ async.auto({
});
}]
});

5 changes: 1 addition & 4 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 @@ -95,9 +95,6 @@ class TuyaLan {
device.ip = ('' + (device.ip || '')).trim();
} 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 (!{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