Last active
September 24, 2023 11:26
-
-
Save anttikuuskoski/ca6e4b70bc86786ce49d22abe4fac06a to your computer and use it in GitHub Desktop.
Code to demonstrate behaviour of Object.create (not working) vs cloning through json (working) in shelly gen2 firmware 1.0.0-beta6 - 1.0.3 running in Shelly Plug Plus S
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reportConfigError(res, ec, em) { | |
console.log("Config update error", ec, em); | |
} | |
function cloneObject(something) { | |
let str = JSON.stringify(something); | |
return JSON.parse(str); | |
} | |
let bluConfig = { | |
leds: { | |
mode: "switch", | |
colors: { | |
"switch:0": { | |
on: { | |
rgb: [ 0, 0, 100], | |
brightness: 80 }, | |
off: { | |
rgb: [ 0, 50, 0 ], | |
brightness: 10 } | |
}, | |
power: { brightness: 100 } | |
}, | |
night_mode: { | |
enable: false, | |
brightness: 100, | |
active_between: [ | |
"00:00", | |
"00:00" | |
] | |
} | |
}, | |
controls: { | |
"switch:0": { | |
in_mode: "momentary" | |
} | |
} | |
}; | |
// let clone = Object.create(bluConfig); // Results in error -103 Missing or bad argument 'leds or controls'! from PLUGS_UI.SetConfig | |
let clone = cloneObject(bluConfig); // Works as expected. | |
Shelly.call( "PLUGS_UI.SetConfig", { config: clone }, reportConfigError ); |
Debug log when using Object.create
shelly_user_script.:370 Running 'script_6.js'... 17:22:05
shelly_ejs_rpc.cpp:41 Shelly.call PLUGS_UI.SetConfig {"config":{}} 17:22:05
shelly_user_script.:341 JS RAM stat: after user code: 102084 after: 99592, used: 2492 17:22:05
shelly_notification:163 Status change of script:6: {"id":6,"running":true} 17:22:05
shos_rpc_inst.c:230 PLUGS_UI.SetConfig via loopback 17:22:05
Config update error -103 17:22:05
See https://gist.github.com/anttikuuskoski/08c246aba218d74f65c752d55f836dae which demonstrates that Object.create or something in the running environment is not entirely sane.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Debug log when using cloneObject: