plasticrake / tplink-smarthome-api

TP-Link Smarthome WiFi API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting a device based on it's MAC address.

LamboCreeper opened this issue · comments

commented

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.

commented

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()