From a3fb8cb08e91f9f26787be912c29b7dc887fbd6e Mon Sep 17 00:00:00 2001 From: Donavan Becker Date: Sun, 29 Sep 2024 21:19:54 -0500 Subject: [PATCH] Update platform.ts --- src/platform.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/platform.ts b/src/platform.ts index ce89d70e..09f89659 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -2,19 +2,14 @@ * * platform.ts: @switchbot/homebridge-switchbot platform class. */ -import type { IncomingMessage, Server, ServerResponse } from 'node:http' -import type { UrlObject } from 'node:url' +import type { Server } from 'node:http' import type { API, DynamicPlatformPlugin, Logging, PlatformAccessory } from 'homebridge' import type { MqttClient } from 'mqtt' -import type { Dispatcher } from 'undici' import type { devicesConfig, irDevicesConfig, options, SwitchBotPlatformConfig } from './settings.js' -import { Buffer } from 'node:buffer' -import crypto, { randomUUID } from 'node:crypto' import { readFileSync, writeFileSync } from 'node:fs' -import { createServer } from 'node:http' import process from 'node:process' import asyncmqtt from 'async-mqtt' @@ -56,7 +51,7 @@ import { Others } from './irdevice/other.js' import { TV } from './irdevice/tv.js' import { VacuumCleaner } from './irdevice/vacuumcleaner.js' import { WaterHeater } from './irdevice/waterheater.js' -import { deleteWebhook, Devices, PLATFORM_NAME, PLUGIN_NAME, queryWebhook, setupWebhook, updateWebhook } from './settings.js' +import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js' import { formatDeviceIdAsMac, isBlindTiltDevice, isCurtainDevice, sleep } from './utils.js' /** @@ -91,7 +86,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { // Event Handlers public readonly webhookEventHandler: { [x: string]: (context: any) => void } = {} public readonly bleEventHandler: { [x: string]: (context: any) => void } = {} - switchBotAPI: SwitchBotOpenAPI + switchBotAPI!: SwitchBotOpenAPI constructor( log: Logging, @@ -100,9 +95,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { ) { this.api = api this.log = log - this.switchBotAPI = new SwitchBotOpenAPI(this.config.credentials?.token, this.config.credentials?.secret) - // Set the log level - this.switchBotAPI.setLogLevel(LogLevel.DEBUG) // only load if configured if (!config) { @@ -135,6 +127,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { return } + // SwitchBot OpenAPI + this.switchBotAPI = new SwitchBotOpenAPI(this.config.credentials?.token, this.config.credentials?.secret) + // Set the log level + this.switchBotAPI.setLogLevel(LogLevel.DEBUG) // import fakegato-history module and EVE characteristics this.fakegatoAPI = fakegato(api) this.eve = new EveHomeKitTypes(api)