DDF for Third Reality, Inc smart button 3RSB22BZ#7897
DDF for Third Reality, Inc smart button 3RSB22BZ#7897manup merged 1 commit intodresden-elektronik:masterfrom
Conversation
I don't think that will work in Javascript since object keys must be strings. Here's an alternative approach (1): const v = [1, 1002, 2, 1004, 0, 1001, 255, 1003];
const n = v.indexOf(ZclFrame.at(3));
if (n >= 0) Item.val = v[n + 1];Or another one as one liner (2): const n = ZclFrame.at(3); if (n < 3) { Item.val = [1001, 1002, 1004][n]; } else if (n == 255) { Item.val = 1003; }Not pretty but should do the trick without string conversions :) |
|
Another one that have workied for him
Or just adding quote ? |
|
Hey, apologies for the confusion. It should be fine, JS engines internally coerces keys that are not $ node --eval "console.log({1: true})"
{ '1': true }
$ node --eval "console.log({'1': 'hello'}[1])"
'hello'A $ node --eval "console.log(new Map([[1, true]]))"
Map(1) { 1 => true }
$ node --eval "console.log(new Map([[1, 'hello'], [2, 'goodbye']]).get(1))"
helloBut it's subjectively a bit harder to read and probably a bit slower: Item.val=new Map([[1, 1002], [2, 1004], [0, 1001], [255, 1003]]).get(Number(ZclFrame.at(3)))Or you could be explicit about the conversions: Item.val={'1': 1002, '2': 1004, '0': 1001, '255': 1003}[String(Number(ZclFrame.at(3)))]The $ node --eval "console.log(Number('003'))"
3Let me know what you prefer! |
|
lol, sometime we are searching a special function, sometime we found too much of them ^^. |
Thanks I didn't know that. Could you test if this is also supported in DucktapeJS engine? |
|
Thanks Manuel.
Sure. They have a nice web REPL, and I am happy to report it works (version 20500). I have tested the device integration with deCONZ, too. All said and done, this is your codebase and the conventions are up to you, I'm happy to change to to something if it makes it more difficult for maintainers to reason about. |
|
Cool nice that it works, then I see no problem for merging. I like Web REPL, perhaps some time this should also be integrated into the UI for easier testing. |
|
This pull request is now merged. The new DDB files have been uploaded to the store. DDB FilesModified
🕧 Updated for commit 7e34c7e |
Issue: #7863