Skip to content

Commit

Permalink
[minor] Minor bug fixes, added log events
Browse files Browse the repository at this point in the history
  • Loading branch information
kikolobo committed Jun 2, 2022
1 parent 91dbb78 commit e784aa8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
12 changes: 7 additions & 5 deletions src/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class NetworkEngine {
setTimeout(() => {
this.status = ComState.Boot;
this.connect();
}, 3000);
}, 5000);
});

}
Expand Down Expand Up @@ -159,7 +159,7 @@ export class NetworkEngine {
this.log.debug('[Network][Ping] Sent...');
}
this.startPingWatchdog(); //Reschedule watchdog even if we haven't expired.
}, 30000); //N = 30 Seconds
}, 20000); //N = 20 Seconds
}

//####
Expand All @@ -168,7 +168,7 @@ export class NetworkEngine {
clearTimeout(this.pingWatchdogRef); //Clear the previous timer (Watchdog)
this.pingWatchdogRef = setTimeout(() => { //Make a new one for N seconds.
this.watchdogExpiredFlag = true;
}, 50000); //N = 50 seconds.
}, 30000); //N = 30 seconds.
}

// Callback Helpers <<<<<<<<<<<<<<<<<<<<<<<<<<<<
Expand All @@ -181,23 +181,25 @@ export class NetworkEngine {
// ####

public registerReceiveCallback(callback:DidReceiveCallback) { //Called when we receive data
this.didReceiveCallbacks.push(callback);
this.log.debug('[Network] DidReceiveCallback Registered.');
this.didReceiveCallbacks.push(callback);
}

public registerDidConnectCallback(callback:DidConnectCallback) { //Called when we connect.
this.didConnectCallbacks.push(callback);
this.log.debug('[Network] DidConnectCallback Registered.');
this.didConnectCallbacks.push(callback);
}

public fireDidReceiveCallbacks(message:string) {
for (const callback of this.didReceiveCallbacks) { //We iterate thru all registered callers.
this.log.debug('[Network] fireDidReceiveCallbacks().');
callback(this, message); //And fire.
}
}


public fireDidConnectCallbacks() {
this.log.debug('[Network] fireDidConnectCallbacks().');
for (const callback of this.didConnectCallbacks) { //We iterate thru all registered callers.
callback(this); //And fire.
}
Expand Down
11 changes: 8 additions & 3 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ export class HomeworksPlatform implements DynamicPlatformPlugin {
this.configuration.host,
this.configuration.apiPort,
this.configuration.username,
this.configuration.password,
this.configuration.password,
);

this.setupNetworkEngineCallbacks(this.engine);

this.api.on('didFinishLaunching', () => {
this.api.on('didFinishLaunching', () => {
this.log.debug('[Platform] didFinishLaunching:');
this.discoverDevices();
this.engine.connect();
});
Expand All @@ -54,11 +55,14 @@ export class HomeworksPlatform implements DynamicPlatformPlugin {
*/
private setupNetworkEngineCallbacks(engine: NetworkEngine) {


const rxCallback = (engine: NetworkEngine, message:string) : void => { //ON SOCKET TRAFFIC CALLBACK
const messagesArray = message.split('\n');


for (let singleMessage of messagesArray) {
singleMessage = singleMessage.trim();

if (singleMessage === '') {
continue;
}
Expand Down Expand Up @@ -110,7 +114,8 @@ export class HomeworksPlatform implements DynamicPlatformPlugin {
/**
* Delegate: Called when homebridge restores cached accessories from disk at startup.
*/
configureAccessory(accessory: PlatformAccessory) {
configureAccessory(accessory: PlatformAccessory) {
this.log.info('Loading accessory from cache:', accessory.displayName);
this.cachedPlatformAccessories.push(accessory);
}

Expand Down

0 comments on commit e784aa8

Please sign in to comment.