From 80947e3330445370db03872810c18cf193fce82f Mon Sep 17 00:00:00 2001 From: LordTocs Date: Mon, 21 Aug 2023 17:10:09 -0400 Subject: [PATCH] Add setting for tp-link to specify the udp broadcast address --- packages/castmate/src/main/plugins/tplink.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/castmate/src/main/plugins/tplink.js b/packages/castmate/src/main/plugins/tplink.js index b3130a15..423f5f65 100644 --- a/packages/castmate/src/main/plugins/tplink.js +++ b/packages/castmate/src/main/plugins/tplink.js @@ -133,6 +133,7 @@ class TPLinkIoTProvider extends IoTProvider { error: (...args) => console.log(...args), },*/ }) + this.client.on("plug-new", async (plug) => { this._addNewPlug(new TPLinkPlug(plug, await plug.getPowerState())) }) @@ -149,9 +150,20 @@ class TPLinkIoTProvider extends IoTProvider { } async initServices() { - console.log("Starting TP-Link Discovery...") + const broadcast = + this.pluginObj.settings.broadcastMask ?? "255.255.255.255" + console.log("Starting TP-Link Discovery", broadcast) this.client.startDiscovery({ breakoutChildren: true, + broadcast, + }) + } + + async setBroadcastMask(newMask) { + this.client.stopDiscovery() + console.log("Starting TP-Link Discovery", newMask) + this.client.startDiscovery({ + broadcast: newMask, }) } @@ -172,4 +184,10 @@ export default { async init() { this.iotProvider = new TPLinkIoTProvider(this) }, + settings: { + broadcastMask: { type: String, name: "Broadcast Mask" }, + }, + async onSettingsReload() { + this.iotProvider.setBroadcastMask(this.settings.broadcastMask) + }, }