Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.on("rebooting", reason => console.log(`rebooting because ${reason}`))
.on("firmware update available", (url, priority) =>console.log(`update available (${url}) with prio ${priority}`))
;
await tradfri.observeNotifications();
// await tradfri.observeResource("15006", (resp) => {
// const notifications = JSON.parse(resp.payload.toString());
// for (const not of notifications) {
// const notification = new Notification().parse(not);
// console.log("got notification: " + JSON.stringify(notification));
// }
// });
await tradfri.rebootGateway();
await wait(20000);
tradfri.destroy();
}
main();async function main() {
const tradfri = new TradfriClient("gw-b072bf257a41");
tradfri
.on("gateway updated", (gw) => {
console.log(new Date(gw.utcNowUnixTimestamp * 1000).toISOString());
console.log(gw.utcNowISODate);
// console.log(JSON.stringify(gw, null, 4))
})
;
await tradfri.connect("tradfri_1521372596997", "7Q9wWw84A7qJSthv");
await tradfri.observeGateway();
await wait(10000);
tradfri.destroy();
}
main();const gwinfo = await discoverGateway();
console.dir(gwinfo);
process.exit(0);
const tradfri = new TradfriClient(gwinfo.addresses[0]);
tradfri
.on("gateway updated", (gw) => {
console.log(new Date(gw.utcNowUnixTimestamp * 1000).toISOString());
console.log(gw.utcNowISODate);
// console.log(JSON.stringify(gw, null, 4))
})
;
await tradfri.connect("tradfri_1525499982376", "IvcPs9WMjCwkyXpj");
await tradfri.observeGateway();
await wait(10000);
tradfri.destroy();
}
main();return __awaiter(this, void 0, void 0, function* () {
const maxAttempts = (this.watcher != null && this.watcher.options.reconnectionEnabled) ?
this.watcher.options.maximumConnectionAttempts :
1;
const interval = this.watcher && this.watcher.options.connectionInterval;
const backoffFactor = this.watcher && this.watcher.options.failedConnectionBackoffFactor;
let lastFailureReason;
for (let attempt = 0; attempt < maxAttempts; attempt++) {
if (attempt > 0) {
// If the reconnection is not enabled, we don't hit this branch,
// so interval and backoffFactor are defined
const nextTimeout = Math.round(interval * Math.pow(backoffFactor, Math.min(5, attempt - 1)));
logger_1.log(`retrying connection in ${nextTimeout} ms`, "debug");
yield async_1.wait(nextTimeout);
}
const connectionResult = yield this.tryToConnect(identity, psk);
switch (connectionResult) {
case true: {
// start connection watching
if (this.watcher != null)
this.watcher.start();
return true;
}
case "auth failed": throw new tradfri_error_1.TradfriError("The provided credentials are not valid. Please re-authenticate!", tradfri_error_1.TradfriErrorCodes.AuthenticationFailed);
case "timeout": {
// retry if allowed
this.emit("connection failed", attempt + 1, maxAttempts);
lastFailureReason = "timeout";
continue;
}