const em = require('events').EventEmitter; const util = require('util'); const logger = require('log4js').getLogger('Aida'); const _ = require('lodash'); const Lights = require('./light-controller'); const Wemo = require('./wemo-controller'); const HS100 = require('./hs100-controller'); const Hive = require('./hive-controller'); const MqttController = require('./mqtt-controller'); const { BedroomRecipe, BedroomLightMorning } = require('./recipes'); logger.level = 'debug'; const devices = { 'sensors': {}, 'lights': new Map(), 'wemo': {}, 'heating': {} }; const Aida = function() { logger.debug('Aida!!'); const self = this; this.on('newListener', function(listener) { logger.debug(`Event Listener: ${ listener}`); }); this.init(); }; util.inherits(Aida, em); Aida.prototype.init = function() { this.lights = new Lights(); this.wemo = new Wemo(); this.hs100 = new HS100(); // this.hive = new Hive(); this.mqtt = new MqttController(); this.lights.on('found', (d) => { if (devices.lights.get(d.id) === undefined) { logger.debug('Adding to light list'); devices.lights.set(d.id, d); } }); this.wemo.on('found', (d) => { logger.debug('Found Wemo switch:', d.macAddress); }); this.hs100.on('found', (d) => { logger.debug('Found hs100 switch:', d.deviceId); }); /* this.hive.on('update', (d) => { logger.debug('Heating updated'); devices.heating = d; });*/ this.mqtt.on('found', () => { logger.debug('MQTT found device'); }); // this.hive.update(); this.BedroomRecipe = new BedroomRecipe({ 'mqtt':this.mqtt, 'wemo':this.wemo }); this.BedroomLightMorning = new BedroomLightMorning({ 'lights': this.lights }); }; module.exports = Aida;