How to use alcalzone-shared - 10 common examples

To help you get started, we’ve selected a few alcalzone-shared examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AlCalzone / node-tradfri-client / test / manual / test-services.js View on Github external
.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();
github AlCalzone / node-tradfri-client / test / manual / test-gw.js View on Github external
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();
github AlCalzone / node-tradfri-client / test / manual / test-discovery.js View on Github external
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();
github AlCalzone / node-tradfri-client / test / mocks.ts View on Github external
.callsFake((path: string, method, payload) => {
					// For requests we need to store one-time promises
					requestPromises[path] = createDeferredPromise();
					// in any case, remove the reference after the promise has served its purpose
					requestPromises[path]
						.then(() => delete requestPromises[path])
						.catch(() => delete requestPromises[path])
						;
					return requestPromises[path];
				});
		} else {
github AlCalzone / node-tradfri-client / build / tradfri-client.js View on Github external
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;
                    }
github AlCalzone / node-tradfri-client / maintenance / release.ts View on Github external
}
	console.log(`bumping version ${oldVersion} to specific version ${newVersion}`);
}

if (argv.dry) {
	console.log(colors.yellow("dry run:") + " not updating package files");
} else {
	console.log(`updating package.json from ${colors.blue(pack.version)} to ${colors.green(newVersion)}`);
	pack.version = newVersion;
	fs.writeFileSync(packPath, JSON.stringify(pack, null, 2));

	console.log(`updating CHANGELOG.md`);
	const d = new Date();
	changelog = changelog.replace(
		CHANGELOG_PLACEHOLDER,
		`## ${newVersion} (${d.getFullYear()}-${padStart("" + (d.getMonth() + 1), 2, "0")}-${padStart("" + d.getDate(), 2, "0")})`,
	);
	fs.writeFileSync(changelogPath, changelog, "utf8");

	// console.log(`updating io-package.json from ${colors.blue(ioPack.common.version)} to ${colors.green(newVersion)}`);
	// ioPack.common.version = newVersion;
	// fs.writeFileSync(ioPackPath, JSON.stringify(ioPack, null, 4));
}

const gitCommands = [
	`npm install`,
	`git add -A`,
	`git commit -m "release v${newVersion} [skip ci]"`,
	`git push`,
	`git tag v${newVersion}`,
	`git push origin --tags`,
];
github AlCalzone / node-tradfri-client / src / lib / conversions.ts View on Github external
const colorTemperature_in: PropertyTransformKernel = (value) => {
	const [min, max] = colorTemperatureRange;
	// interpolate "color percentage" from the colorTemperature range of a lightbulb
	value = (value - min) / (max - min);
	value = clamp(value, 0, 1);
	return roundTo(value * 100, 1);
};
github AlCalzone / node-tradfri-client / build / lib / conversions.js View on Github external
h = 60 * (0 + (g - b) / (max - min));
    }
    else if (max === g) {
        h = 60 * (2 + (b - r) / (max - min));
    }
    else if (max === b) {
        h = 60 * (4 + (r - g) / (max - min));
    }
    h = Math.round(h); // h is defined, we checked all possibilities
    if (h < 0)
        h += 360;
    if (max === 0) {
        s = 0;
    }
    else {
        s = math_1.roundTo((max - min) / max, 3);
    }
    return { h, s, v };
}
function rgbFromHSV(h, s, v) {
github AlCalzone / node-tradfri-client / src / lib / conversions.ts View on Github external
function rgbToHSV(r: number, g: number, b: number) {
	// transform [0..255] => [0..1]
	[r, g, b] = [r, g, b].map(c => c / 255);
	const max = Math.max(r, g, b);
	const min = Math.min(r, g, b);
	let h: number;
	let s: number;
	const v: number = roundTo(max, 2);
	if (r === g && g === b) {
		h = 0;
	} else if (max === r) {
		h = 60 * (0 + (g - b) / (max - min));
	} else if (max === g) {
		h = 60 * (2 + (b - r) / (max - min));
	} else if (max === b) {
		h = 60 * (4 + (r - g) / (max - min));
	}
	h = Math.round(h!); // h is defined, we checked all possibilities
	if (h < 0) h += 360;

	if (max === 0) {
		s = 0;
	} else {
		s = roundTo((max - min) / max, 3);
github AlCalzone / node-tradfri-client / build / lib / conversions.js View on Github external
const colorTemperature_out = (value) => {
    const [min, max] = predefined_colors_1.colorTemperatureRange;
    // extrapolate 0-100% to [min..max]
    value = math_1.clamp(value, 0, 100);
    return math_1.roundTo(min + value / 100 * (max - min), 0);
};
// interpolate from [250..454] to [0..100%]

alcalzone-shared

A set of utilities shared between my projects

MIT
Latest version published 2 months ago

Package Health Score

72 / 100
Full package analysis

Similar packages