@caseywebb/growhaus-agent
Advanced tools
Comparing version 0.0.0-latest.20190729T211711Z.f921b60 to 0.0.0-latest.20190729T215824Z.49036fa
@@ -13,6 +13,17 @@ "use strict"; | ||
const offlineFallbackSchedule = new schedule_1.LightSchedule(); | ||
process.on('SIGINT', () => { | ||
console.log('Exiting...'); | ||
let forceQuit = false; | ||
const quit = () => { | ||
if (forceQuit) { | ||
process.exit(); | ||
} | ||
else { | ||
forceQuit = true; | ||
} | ||
console.log('Exiting... (Press ctrl+c again to force exit)'); | ||
driver.setBrightness(100); | ||
}); | ||
socket.dispose(); | ||
offlineFallbackSchedule.dispose(); | ||
process.off('SIGINT', quit); | ||
}; | ||
process.on('SIGINT', quit); | ||
socket.on(socket_1.IncomingEvent.Brightness, (m) => { | ||
@@ -19,0 +30,0 @@ // pause until 10 minutes after we should have received a new message |
export declare class LightSchedule { | ||
private paused; | ||
private pauseTimeout?; | ||
private subscriptions; | ||
private schedule; | ||
private readonly updateInterval; | ||
private readonly subscriptions; | ||
private readonly schedule; | ||
constructor(); | ||
pause(duration: number): void; | ||
subscribe(handler: (b: number) => void): void; | ||
dispose(): void; | ||
private getCurrentBrightness; | ||
@@ -10,0 +12,0 @@ private next; |
@@ -36,3 +36,3 @@ "use strict"; | ||
]; | ||
setInterval(this.next, 60 * 1000 * 60); | ||
this.updateInterval = setInterval(this.next, 60 * 1000 * 60); | ||
} | ||
@@ -54,2 +54,9 @@ pause(duration) { | ||
} | ||
dispose() { | ||
console.log('Disposing offline schedule...'); | ||
if (this.pauseTimeout) | ||
clearTimeout(this.pauseTimeout); | ||
clearInterval(this.updateInterval); | ||
console.log('Offline schedule disposed.'); | ||
} | ||
getCurrentBrightness() { | ||
@@ -56,0 +63,0 @@ return this.schedule[new Date().getHours()]; |
@@ -19,2 +19,3 @@ export declare enum IncomingEvent { | ||
on(eventType: IncomingEvent.Brightness, handler: (m: ManualBrightnessMessage) => void): void; | ||
dispose(): void; | ||
private connect; | ||
@@ -21,0 +22,0 @@ private wsHeartbeat; |
@@ -24,2 +24,10 @@ "use strict"; | ||
} | ||
dispose() { | ||
console.log('Disposing socket connection...'); | ||
if (this.heartbeatTimeout) | ||
clearTimeout(this.heartbeatTimeout); | ||
this.ws.off('close', this.wsClose); | ||
this.ws.close(); | ||
console.log('Socket connection disposed.'); | ||
} | ||
connect() { | ||
@@ -57,3 +65,8 @@ console.log(`Attempting to connect to ${this.url}...`); | ||
const handlers = this.onMessageHandlers[message.event]; | ||
await Promise.all(handlers.map((h) => h(message))); | ||
if (!handlers) { | ||
console.error('Received unknown message:', JSON.stringify(message, null, 2)); | ||
} | ||
else { | ||
await Promise.all(handlers.map((h) => h(message))); | ||
} | ||
} | ||
@@ -60,0 +73,0 @@ } |
{ | ||
"name": "@caseywebb/growhaus-agent", | ||
"version": "0.0.0-latest.20190729T211711Z.f921b60", | ||
"version": "0.0.0-latest.20190729T215824Z.49036fa", | ||
"author": "Casey Webb (https://caseyWebb.xyz)", | ||
@@ -20,3 +20,2 @@ "bin": { | ||
"dependencies": { | ||
"@caseywebb/growhaus": "^0.0.0-f921b608fb082a224d1999d91a4b7c0cf5ca54ba.20190729T211711Z.f921b60", | ||
"autobind-decorator": "^2.4.0", | ||
@@ -23,0 +22,0 @@ "dotenv": "^8.0.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11203
5
17
271
- Removed@caseywebb/growhaus@^0.0.0-f921b608fb082a224d1999d91a4b7c0cf5ca54ba.20190729T211711Z.f921b60
- Removed@caseywebb/growhaus@0.0.0-fa73133490327b4d5c48349db02bbc92955deeb4.20190731T084613Z.fa73133(transitive)
- Removednonenumerable@1.1.1(transitive)