From e502c41242a3557d44c3dfdbed987159de2d7059 Mon Sep 17 00:00:00 2001 From: Supereg Date: Thu, 20 Apr 2023 15:14:26 +0200 Subject: [PATCH] Remove deprecated Core and BridgeCore (see #1001) --- src/BridgedCore.ts | 50 ------------------------------------- src/Core.ts | 61 ---------------------------------------------- 2 files changed, 111 deletions(-) delete mode 100644 src/BridgedCore.ts delete mode 100644 src/Core.ts diff --git a/src/BridgedCore.ts b/src/BridgedCore.ts deleted file mode 100644 index 94f3be3c9..000000000 --- a/src/BridgedCore.ts +++ /dev/null @@ -1,50 +0,0 @@ -import path from "path"; - -import storage from "node-persist"; - -import { Accessory, AccessoryEventTypes, AccessoryLoader, Bridge, Categories, HAPLibraryVersion, uuid, VoidCallback } from "./"; - -console.log(`HAP-NodeJS v${HAPLibraryVersion()} starting...`); - -console.warn("DEPRECATION NOTICE: The use of Core and BridgeCore are deprecated and are scheduled to be remove in October 2020. " + - "For more information and some guidance on how to migrate, have a look at https://github.com/homebridge/HAP-NodeJS/wiki/Deprecation-of-Core-and-BridgeCore"); - -// Initialize our storage system -storage.initSync(); - -// Start by creating our Bridge which will host all loaded Accessories -const bridge = new Bridge("Node Bridge", uuid.generate("Node Bridge")); - -// Listen for bridge identification event -bridge.on(AccessoryEventTypes.IDENTIFY, (paired: boolean, callback: VoidCallback) => { - console.log("Node Bridge identify"); - callback(); // success -}); - -// Load up all accessories in the /accessories folder -const dir = path.join(__dirname, "accessories"); -const accessories = AccessoryLoader.loadDirectory(dir); - -// Add them all to the bridge -accessories.forEach((accessory: Accessory) => { - bridge.addBridgedAccessory(accessory); -}); - -// Publish the Bridge on the local network. -bridge.publish({ - username: "CC:22:3D:E3:CE:F6", - port: 51826, - pincode: "031-45-154", - category: Categories.BRIDGE, -}); - -const signals = { "SIGINT": 2, "SIGTERM": 15 } as Record; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -Object.keys(signals).forEach((signal: any) => { - process.on(signal, () => { - bridge.unpublish(); - setTimeout(()=> { - process.exit(128 + signals[signal]); - }, 1000); - }); -}); diff --git a/src/Core.ts b/src/Core.ts deleted file mode 100644 index b2583c81a..000000000 --- a/src/Core.ts +++ /dev/null @@ -1,61 +0,0 @@ -import path from "path"; - -import storage from "node-persist"; - -import { AccessoryLoader, HAPLibraryVersion } from "./"; - -console.log(`HAP-NodeJS v${HAPLibraryVersion()} starting...`); - -console.warn("DEPRECATION NOTICE: The use of Core and BridgeCore are deprecated and are scheduled to be remove in October 2020. " + - "For more information and some guidance on how to migrate, have a look at https://github.com/homebridge/HAP-NodeJS/wiki/Deprecation-of-Core-and-BridgeCore"); - -// Initialize our storage system -storage.initSync(); - -// Our Accessories will each have their own HAP server; we will assign ports sequentially -let targetPort = 51826; - -// Load up all accessories in the /accessories folder -const dir = path.join(__dirname, "accessories"); -const accessories = AccessoryLoader.loadDirectory(dir); - -// Publish them all separately (as opposed to BridgedCore which publishes them behind a single Bridge accessory) -accessories.forEach((accessory) => { - - // To push Accessories separately, we'll need a few extra properties - // @ts-expect-error: Core/BridgeCore API - if (!accessory.username) { - throw new Error("Username not found on accessory '" + accessory.displayName + - "'. Core.js requires all accessories to define a unique 'username' property."); - } - - // @ts-expect-error: Core/BridgeCore API - if (!accessory.pincode) { - throw new Error("Pincode not found on accessory '" + accessory.displayName + - "'. Core.js requires all accessories to define a 'pincode' property."); - } - - // publish this Accessory on the local network - accessory.publish({ - port: targetPort++, - // @ts-expect-error: Core/BridgeCore API - username: accessory.username, - // @ts-expect-error: Core/BridgeCore API - pincode: accessory.pincode, - category: accessory.category, - }); -}); - -const signals = { "SIGINT": 2, "SIGTERM": 15 } as Record; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -Object.keys(signals).forEach((signal: any) => { - process.on(signal, () => { - for (let i = 0; i < accessories.length; i++) { - accessories[i].unpublish(); - } - - setTimeout(() => { - process.exit(128 + signals[signal]); - }, 1000); - }); -});