How to use the node-tradfri-client.TradfriClient function in node-tradfri-client

To help you get started, we’ve selected a few node-tradfri-client 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 thkl / Homematic-Virtual-Interface / plugins / IkeaTradfri / TradfriPlatform.js View on Github external
// this.trApiLightbulbs = {}
    // this.trApiGroups = {}
    // this.trApiScenes = {}

    if ((this.securityCode == undefined) && (this.securityID == undefined)) {
        this.log.warn('No credentials')
        return
    }

    if (this.tradfriUser == undefined) {
        this.securityCode = undefined
    }



    this.tradfri = new TradfriClient(that.bridgeIp, function(message, severity) {
        if (severity !== 'silly') {
            that.log.debug('%s - %s', severity, message)
        }
    });

    // Check if we have to authenticate
    if ((this.securityCode == undefined) || (this.tradfriUser == undefined)) {

        this.log.warn('we have to authenticate first')

        this.tradfri.authenticate(this.securityID).then((identity, psk) => {
            // work with the result
            that.log.info('Identity is %s psk is %s', identity, psk)
            that.tradfriUser = identity
            that.securityCode = psk
            that.configuration.setValueForPlugin(that.name, "tradfri_securityCode", that.securityCode);
github fvanwijk / tradfri-app / server / tradfri.js View on Github external
const { hostname, identity, psk } = require('./config.json');
const { TradfriClient } = require('node-tradfri-client');

const tradfri = new TradfriClient(hostname, {
  customLogger: (msg, severity) => {
    switch (severity) {
      case 'silly':
        break;
      case 'debug':
        console.log('\x1b[2m%s\x1b[0m', '[DEBUG]', msg);
        break;
      case 'info':
        console.info('\x1b[34m%s\x1b[0m', '[INFO]', msg);
        break;
      case 'warn':
        console.warn('\x1b[33m%s\x1b[0m', '[WARN]', msg);
        break;
      case 'error':
        console.error('\x1b[31m%s\x1b[0m', '[ERROR]', msg);
        break;