From a2fc989ee4848a0fe16b0004dfee692359a67399 Mon Sep 17 00:00:00 2001 From: Johann Richard <189003+johannrichard@users.noreply.github.com> Date: Tue, 8 Dec 2020 13:51:06 +0100 Subject: [PATCH] feat(dingz,pir): event callback override - new setting which will override action URLs - can be used to reset your devices to *one* callback setting - will also override any other (generic) action URL - useful if your server IP/address changes, and - useful if you have multiple servers (incl. dev) and want to reset your setup - settings is applied on each restart of the homebridge server --- config.schema.json | 5 +++++ src/dingzAccessory.ts | 13 ++++++++++++- src/myStromPIRAccessory.ts | 12 +++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/config.schema.json b/config.schema.json index e35ff79..95691f7 100644 --- a/config.schema.json +++ b/config.schema.json @@ -48,6 +48,11 @@ "type": "number", "description": "In order to implement button actions, the dingz plugin exposes a webserver for callbacks. By default, it listens on port 18081. Add this setting if you want to change this." }, + "callbackOverride": { + "title": "Override generic callbacks", + "type": "boolean", + "description": "If set, actions will be overriden, that is, existing action URLs (for the 'generic' endpoint) will be replaced by an action to this server only. Useful for testing and/or resetting your devices if you homebridge server's address changes." + }, "devices": { "title": "dingz Devices", "type": "array", diff --git a/src/dingzAccessory.ts b/src/dingzAccessory.ts index fb7540f..57cd0a4 100644 --- a/src/dingzAccessory.ts +++ b/src/dingzAccessory.ts @@ -253,7 +253,18 @@ export class DingzAccessory extends DingzDaBaseAccessory { this.getButtonCallbackUrl() .then((callBackUrl) => { - if (!callBackUrl?.url.includes(this.platform.getCallbackUrl())) { + if (this.platform.config.callbackOverride) { + this.log.warn('Override callback URL ->', callBackUrl); + // Set the callback URL (Override!) + const endpoints = this.dingzDeviceInfo.has_pir + ? ['generic', 'pir/single'] + : ['generic']; + this.platform.setButtonCallbackUrl({ + baseUrl: this.baseUrl, + token: this.device.token, + endpoints: endpoints, + }); + } else if (!callBackUrl?.url.includes(this.platform.getCallbackUrl())) { this.log.warn('Update existing callback URL ->', callBackUrl); // Set the callback URL (Override!) const endpoints = this.dingzDeviceInfo.has_pir diff --git a/src/myStromPIRAccessory.ts b/src/myStromPIRAccessory.ts index 36c83cc..81473b1 100644 --- a/src/myStromPIRAccessory.ts +++ b/src/myStromPIRAccessory.ts @@ -152,7 +152,17 @@ export class MyStromPIRAccessory extends DingzDaBaseAccessory { retrySlow.execute(() => { this.getButtonCallbackUrl() .then((callBackUrl) => { - if (!callBackUrl?.url.includes(this.platform.getCallbackUrl())) { + if (this.platform.config.callbackOverride) { + this.log.warn('Override callback URL ->', callBackUrl); + // Set the callback URL (Override!) + this.platform.setButtonCallbackUrl({ + baseUrl: this.baseUrl, + token: this.device.token, + endpoints: ['pir/generic'], + }); + } else if ( + !callBackUrl?.url.includes(this.platform.getCallbackUrl()) + ) { this.log.warn('Update existing callback URL ->', callBackUrl); // Set the callback URL (Override!) this.platform.setButtonCallbackUrl({