plasticrake / tplink-smarthome-api

TP-Link Smarthome WiFi API
MIT License
1.03k stars 142 forks source link

Getting a device based on it's MAC address. #76

Closed LamboCreeper closed 4 years ago

LamboCreeper commented 5 years ago

Hi,

I was wondering if it's possible to get a device (client.getDevice()) based on it's MAC address rather than it's host (options.host) - I can only find the MAC address within the Kasa app.

I understand if you can not implement it because getting the device via a MAC address could be a limitation on TP-Links side?

Thanks.

fractalyse commented 5 years ago

Can be achive while discovering devices by creating a list of device and add them to list.

const MAC_ADDR = "XX:XX:XX:XX:XX:XX";
const { Client } = require ("tplink-smarthome-api");
const client = new Client();
const clientList = {};
client.startDiscovery().on("device-new", (device) => {
  device.getSysInfo().then((data) => {
      clientList[data.mac] = device;
  });
});

After you just have to call clientList[MAC_ADDR].function()