From b6f21f432e3c0ccf2c83720f81cc39ea4564064e Mon Sep 17 00:00:00 2001 From: Long Zhao Date: Fri, 9 Aug 2024 17:02:10 +1000 Subject: [PATCH] feat: Add keep-alive agent for HTTP requests --- src/CGDGarageDoor.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/CGDGarageDoor.ts b/src/CGDGarageDoor.ts index d9fb063..3bdd711 100644 --- a/src/CGDGarageDoor.ts +++ b/src/CGDGarageDoor.ts @@ -1,6 +1,9 @@ import { Logging } from 'homebridge'; +import http from 'http'; import retry from './retry'; +const httpAgent = new http.Agent({ keepAlive: true }); + interface Status { lamp: 'on' | 'off'; door: string; @@ -61,7 +64,12 @@ export class CGDGarageDoor { this.log.debug(`Running command: ${cmd}=${value}`); const { deviceHostname, deviceLocalKey } = this.config; - const response = await fetch(`http://${deviceHostname}/api?key=${deviceLocalKey}&${cmd}=${value}`); + const response = await fetch(`http://${deviceHostname}/api?key=${deviceLocalKey}&${cmd}=${value}`, { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + agent: httpAgent, + }); + const data = await response.json(); const level = response.ok ? 'debug' : 'error';