npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tradfri-handler

v0.5.4

Published

This module provides tradfri managements API.

Downloads

3

Readme

Overview

tradfri-handler

Install

下記コマンドでモジュールをインストールできます.

You can install the module as following command.

npm i tradfri-handler

もしかしたら下記が必要かもしれません。

npm i node-cron

Demo, example

'use strict'

const cron = require('node-cron');
const TF = require('tradfri-handler');

////////////////////////////////////////
// config
const TFkey      = '';      // GWの裏面に書いてある,初回だけ必要
let   TFidentity = ''; // GW自動生成を記録しておいて、2回目以降は設定しておくと接続早くなる
let   TFpsk      = ''; // GW自動生成を記録しておいて、2回目以降は設定しておくと接続早くなる


let dev = {};

// 受信後の処理
let TFReceived = function(rIP, device, error) {
	if( error ) {
		console.log('-- received error');
		console.error( error );
		return;
	}

	// if( device.lightList ) {
	if( device.type === TF.AccessoryTypes.lightbulb ) {
		// console.log( device );

		if( device.instanceId == 65539 ) {  // 上のlogを有効にして、ライトのIDを探して設定する
			dev = device;
		}
	}

	// console.log('-- received, IP:', rIP, ', device:', device);
};


// Tradfri.initialize
async function TFStart() {
	try{
		let co = await TF.initialize( TFkey, TFReceived, {identity: TFidentity, psk: TFpsk, debugMode:true} );

		// 2回目以降はidentityとpskを設定しておくと接続が早い
		console.log('TF connected, identity=', co.identity, ', psk=', co.psk);
	}catch(e){
		console.dir(e);
	}


	// facilitiesの定期的監視
	let oldVal = JSON.stringify( TF.objectSort(TF.facilities) );
	let c1 = cron.schedule('0 */1 * * * *', () => {  // 1分毎にautoget、変化があればログ表示
		const newVal = JSON.stringify( TF.objectSort(TF.facilities) );
		if ( oldVal == newVal ) return; // 変化した
		oldVal = newVal;
		console.log('TF changed, new TF.facilities:', newVal);
	});
	c1.start();


	// 点滅
	let on_off = 'on';
	let c2 = cron.schedule('*/10 * * * * *', async () => {
		try{
			if( on_off == 'on' ) {
				await dev.lightList[0].turnOff();
				on_off = 'off';
			}else{
				await dev.lightList[0].turnOn();
				on_off = 'on';
			}
			console.log('on_off:', on_off);
		}catch( error ) {
			console.error( error );
		}
	});
	c2.start();

};

TFStart();  // 実行

Data stracture

API

初期化と受信, 監視, initialize, receriver callback and observation

  • TF.initialize( TFkey, TFReceived, {identity: TFidentity, psk: TFpsk, debugMode:false} )
    • TFReceived(rIP, devices, error)
  • TF.setObserveFacilities( interval, function )

Authors

神奈川工科大学 創造工学部 ホームエレクトロニクス開発学科 Dept. of Home Electronics, Faculty of Creative Engineering, Kanagawa Institute of Technology

杉村 博 SUGIMURA Hiroshi

License

This library is MIT License

-- License summary --
o Commercial use
o Modification
o Distribution
o Private use
x Liability
x Warranty

Dependencies

  • MIT
    • node-tradfri-client; https://www.npmjs.com/package/node-tradfri-client

Log

  • 0.5.4 lightとblindを制御しやすく
  • 0.5.3 dependenciesなくした
  • 0.5.2 細かいバグログ関連
  • 0.5.1 autoGet、getStateバグ修正
  • 0.5.0 安定性向上、少しコントロールもできるように
  • 0.0.1 start up