aboutsummaryrefslogtreecommitdiff
path: root/services/device-manager.js
blob: d1d81a1587fc600f0271174eae82871b46db085e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const { Client } = require('tplink-smarthome-api');

const client = new Client();
var devices = [];

client.startDiscovery({deviceTypes: ['plug']}).on('plug-new', plug => {
  console.log('Found device: ' + plug.alias + ' [' + plug.deviceId + ']');
  devices.push(plug);
});

module.exports.getDevice = function(deviceId) {

  return devices.find(d => d.deviceId == deviceId);

}

module.exports.getAllDevices = function() {
  return devices;
}