const Hs100Api = require('tplink-smarthome-api'); const client = new Hs100Api.Client(); const em = require('events').EventEmitter; const util = require('util'); const logger = require('log4js').getLogger('hs100'); logger.level = 'debug'; const Hs100Controller = function() { const _this = this; client.startDiscovery().on('device-new', (device) => { device.getSysInfo(). catch((err) => { logger.error(err); }).then((deviceInfo) => { logger.debug(deviceInfo); _this.emit('found', deviceInfo); }); device.setPowerState(true); device.startPolling(10000); device.on('power-on', (d) => { logger.debug('Power on', d); }); device.on('power-off', (d) => { logger.debug('Power off', d); }); }); // this.on('newListener', listener => { logger.info(`Event Listener: ${ listener}`); }); return this; }; util.inherits(Hs100Controller, em); module.exports = Hs100Controller;