Browse Source

Benutze getComponentStatus um eine RPC-Verschachtelung weniger zu haben

master
Philipp 3 years ago
parent
commit
6b5341e41f
  1. 19
      switch.js

19
switch.js

@ -1,15 +1,3 @@
function initialize() {
Shelly.call("Switch.GetStatus",
{ id: CONFIG.switchId },
function (res, error_code, error_msg, ud) {
print("Initializing... current switch state is:", res.output)
switchIsOpen = res.output;
runLoop();
},
null
);
}
function runLoop() {
let alertTimer = Timer.set(
CONFIG.pollingInterval,
@ -19,7 +7,7 @@ function runLoop() {
{ method: "POST", url: CONFIG.pollingUrl, body: '{"801":{"170":null}}', timeout: 10 },
function (res, error_code, error_msg, ud) {
print("errors-http-post:", error_code, error_msg);
if (error_code === 0) { // do this so that during timeout no crash
if (error_code === 0) {
let parsedBody = JSON.parse(res.body);
let production = parsedBody["801"]["170"]["101"];
let consumption = parsedBody["801"]["170"]["110"];
@ -69,6 +57,7 @@ let CONFIG = {
chargingConsumption: 2100,
};
let switchIsOpen;
let switchIsOpen = Shelly.getComponentStatus("switch:0").output;
print("Initialized switchIsOpen with:", switchIsOpen);
initialize();
runLoop();

Loading…
Cancel
Save