Skip to content

Commit

Permalink
feat(dingz,pir): event callback override
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
johannrichard committed Dec 8, 2020
1 parent bee80d9 commit a2fc989
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions config.schema.json
Expand Up @@ -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 <em>replaced</em> 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",
Expand Down
13 changes: 12 additions & 1 deletion src/dingzAccessory.ts
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion src/myStromPIRAccessory.ts
Expand Up @@ -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({
Expand Down

0 comments on commit a2fc989

Please sign in to comment.