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