Converted to pure ES6 using https://lebab.io/try-it

This commit is contained in:
martind2000 2017-01-09 15:46:51 +00:00
parent 6d83d048d4
commit 65bc6987d4

View File

@ -1,7 +1,4 @@
'use strict';
const mqtt = require('mqtt');
const request = require('request');
let util = require('util');
import mqtt from 'mqtt';
const logger = require('log4js').getLogger();
// Var db = require('../server/db-connector').dbConnection;
@ -37,7 +34,7 @@ const mqttClient = function(events) {
const d = new Date();
this.lastMsg = d.getTime();
events.on('sendIFTTT', function(mode) {
events.on('sendIFTTT', mode => {
let d;
const url = ['https://maker.ifttt.com/trigger/', mode, '/with/key/cWvECkeiyAPwmiOPBkXL2D'].join('');
@ -138,24 +135,24 @@ const mqttClient = function(events) {
const options = {
keepalive: 3600,
clientId: 'a:' + orgId + ':' + Date.now(),
clientId: `a:${orgId}:${Date.now()}`,
username: userName,
password: new Buffer(appKey)
};
this.client = mqtt.connect('mqtt://' + orgId + 'silvrtree.co.uk', options);
this.client = mqtt.connect(`mqtt://${orgId}silvrtree.co.uk`, options);
this.client.on('connect', function() {
this.client.on('connect', () => {
this.connected = true;
logger.info('Connected to Silvr Broker');
this.fanTimer();
this.logTemp();
}.bind(this));
});
this.client.subscribe('livingroomTemp');
this.client.on('message', function(topic, message) {
this.client.on('message', (topic, message) => {
const json = JSON.parse(message.toString());
logger.debug(json);
@ -174,7 +171,7 @@ const mqttClient = function(events) {
const data = {id: 'temperature', data: {mode: globalMode, temp: this.livingRoom.temp}};
events.emit('sendSocket', data);
}.bind(this));
});
this.isConnected = function() {
return this.connected;
@ -182,4 +179,4 @@ const mqttClient = function(events) {
};
module.exports.mqttClient = mqttClient;
export {mqttClient};