Skip to content

Commit

Permalink
Added Native API heartbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleBoyer committed Aug 7, 2024
1 parent 36c2847 commit ffbe13d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
}
}
},
"enableNativeAPIHeartbeat": {
"title": "Prevent random restarts by performing a heartbeat on the Native API",
"type": "boolean",
"default": true
},
"garageDoorType": {
"title": "Enable publishing a separate \"occupancy\" obstruction sensor for the garage",
"type": "string",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": false,
"displayName": "Konnected BlaQ",
"name": "homebridge-blaq",
"version": "0.2.30",
"version": "0.2.31",
"description": "Control and view your garage door(s) remotely with real-time updates using Konnected's BlaQ hardware",
"license": "Apache-2.0",
"type": "module",
Expand Down
20 changes: 20 additions & 0 deletions src/hub.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AutoReconnectingEventSource, LogMessageEvent, PingMessageEvent, StateUpdateMessageEvent } from './utils/eventsource.js';
import { Logger, PlatformAccessory, PlatformConfig } from 'homebridge';
import stripAnsi from 'strip-ansi';
import { createConnection } from 'net';
import { BlaQTextSensorEvent, ConfigDevice } from './types.js';
import { BaseBlaQAccessoryInterface } from './accessory/base.js';
import { BlaQHomebridgePluginPlatform } from './platform.js';
Expand Down Expand Up @@ -64,6 +65,11 @@ export class BlaQHub {
this.initAccessoryCallback = initAccessoryCallback;
this.logger = logger;
this.reinitializeEventSource();
if(pluginConfig.enableNativeAPIHeartbeat){
setInterval(() => {
this.performNativeAPIHeartbeat();
}, 5 * 60 * 1000);
}
logger.debug('Initialized BlaQHub!');
}

Expand Down Expand Up @@ -96,6 +102,20 @@ export class BlaQHub {
}
}

public performNativeAPIHeartbeat() {
const socket = createConnection(
{host: this.host, port: 6053},
(
() => setTimeout(
() => {
socket.destroy();
},
5 * 1000,
)
),
);
}

private possiblyFinalizeInit(){
if(!this.initialized && this.friendlyName && this.deviceMac){
this.logger.info(`[${this.configDevice.displayName}] [init] Publishing accessories with device model:`, this.friendlyName);
Expand Down

0 comments on commit ffbe13d

Please sign in to comment.