aboutsummaryrefslogtreecommitdiff
path: root/services/device-manager.js
blob: 3ed4a269af8f041cac6222a6ab422c322e9e3e91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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) {
  // TODO - get by id
  return devices[0];
}

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