homebridge 2.0.0-alpha.4 → 2.0.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/bin/homebridge +1 -1
  2. package/dist/api.d.ts +193 -0
  3. package/dist/api.d.ts.map +1 -0
  4. package/dist/api.js +129 -0
  5. package/dist/api.js.map +1 -0
  6. package/dist/bridgeService.d.ts +106 -0
  7. package/dist/bridgeService.d.ts.map +1 -0
  8. package/dist/bridgeService.js +390 -0
  9. package/dist/bridgeService.js.map +1 -0
  10. package/dist/childBridgeFork.d.ts +38 -0
  11. package/dist/childBridgeFork.d.ts.map +1 -0
  12. package/dist/childBridgeFork.js +241 -2
  13. package/dist/childBridgeFork.js.map +1 -7
  14. package/dist/childBridgeService.d.ts +200 -0
  15. package/dist/childBridgeService.d.ts.map +1 -0
  16. package/dist/childBridgeService.js +427 -0
  17. package/dist/childBridgeService.js.map +1 -0
  18. package/dist/cli.d.ts +3 -0
  19. package/dist/cli.d.ts.map +1 -0
  20. package/dist/cli.js +89 -2
  21. package/dist/cli.js.map +1 -7
  22. package/dist/externalPortService.d.ts +33 -0
  23. package/dist/externalPortService.d.ts.map +1 -0
  24. package/dist/externalPortService.js +59 -0
  25. package/dist/externalPortService.js.map +1 -0
  26. package/dist/index.d.ts +76 -1099
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +19 -2
  29. package/dist/index.js.map +1 -7
  30. package/dist/ipcService.d.ts +30 -0
  31. package/dist/ipcService.d.ts.map +1 -0
  32. package/dist/ipcService.js +49 -0
  33. package/dist/ipcService.js.map +1 -0
  34. package/dist/logger.d.ts +78 -0
  35. package/dist/logger.d.ts.map +1 -0
  36. package/dist/logger.js +138 -0
  37. package/dist/logger.js.map +1 -0
  38. package/dist/platformAccessory.d.ts +55 -0
  39. package/dist/platformAccessory.d.ts.map +1 -0
  40. package/dist/platformAccessory.js +98 -0
  41. package/dist/platformAccessory.js.map +1 -0
  42. package/dist/plugin.d.ts +31 -0
  43. package/dist/plugin.d.ts.map +1 -0
  44. package/dist/plugin.js +185 -0
  45. package/dist/plugin.js.map +1 -0
  46. package/dist/pluginManager.d.ts +77 -0
  47. package/dist/pluginManager.d.ts.map +1 -0
  48. package/dist/pluginManager.js +374 -0
  49. package/dist/pluginManager.js.map +1 -0
  50. package/dist/server.d.ts +58 -0
  51. package/dist/server.d.ts.map +1 -0
  52. package/dist/server.js +430 -0
  53. package/dist/server.js.map +1 -0
  54. package/dist/storageService.d.ts +13 -0
  55. package/dist/storageService.d.ts.map +1 -0
  56. package/dist/storageService.js +41 -0
  57. package/dist/storageService.js.map +1 -0
  58. package/dist/user.d.ts +13 -0
  59. package/dist/user.d.ts.map +1 -0
  60. package/dist/user.js +29 -0
  61. package/dist/user.js.map +1 -0
  62. package/dist/util/mac.d.ts +5 -0
  63. package/dist/util/mac.d.ts.map +1 -0
  64. package/dist/util/mac.js +14 -0
  65. package/dist/util/mac.js.map +1 -0
  66. package/dist/version.d.ts +3 -0
  67. package/dist/version.d.ts.map +1 -0
  68. package/dist/version.js +16 -0
  69. package/dist/version.js.map +1 -0
  70. package/package.json +7 -10
package/dist/cli.js.map CHANGED
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/cli.ts", "../src/logger.ts", "../src/server.ts", "../src/api.ts", "../src/platformAccessory.ts", "../src/pluginManager.ts", "../src/plugin.ts", "../src/version.ts", "../src/user.ts", "../src/bridgeService.ts", "../src/storageService.ts", "../src/util/mac.ts", "../src/childBridgeService.ts", "../src/ipcService.ts", "../src/externalPortService.ts"],
4
- "sourcesContent": ["/* global NodeJS */\n\nimport type { HomebridgeOptions } from './server.js'\n\nimport process from 'node:process'\n\nimport { Command } from 'commander'\nimport { HAPStorage } from 'hap-nodejs'\nimport { satisfies } from 'semver'\n\nimport { Logger } from './logger.js'\nimport { Server } from './server.js'\nimport { User } from './user.js'\nimport getVersion, { getRequiredNodeVersion } from './version.js'\n\nimport Signals = NodeJS.Signals\n\nconst log = Logger.internal\n\nconst requiredNodeVersion = getRequiredNodeVersion()\nif (requiredNodeVersion && !satisfies(process.version, requiredNodeVersion)) {\n log.warn(`Homebridge requires Node.js version of ${requiredNodeVersion} which does \\\nnot satisfy the current Node.js version of ${process.version}. You may need to upgrade your installation of Node.js - see https://homebridge.io/w/JTKEF`)\n}\n\nexport default function cli(): void {\n let insecureAccess = false\n let hideQRCode = false\n let keepOrphans = false\n let customPluginPath: string | undefined\n let strictPluginResolution = false\n let noLogTimestamps = false\n let debugModeEnabled = false\n let forceColourLogging = false\n let customStoragePath: string | undefined\n\n let shuttingDown = false\n\n const program = new Command()\n program\n .version(getVersion())\n .option('-C, --color', 'force color in logging', () => forceColourLogging = true)\n .option('-D, --debug', 'turn on debug level logging', () => debugModeEnabled = true)\n .option('-I, --insecure', 'allow unauthenticated requests (for easier hacking)', () => insecureAccess = true)\n .option('-P, --plugin-path [path]', 'look for plugins installed at [path] as well as the default locations ([path] can also point to a single plugin)', path => customPluginPath = path)\n .option('-Q, --no-qrcode', 'do not issue QRcode in logging', () => hideQRCode = true)\n .option('-K, --keep-orphans', 'keep cached accessories for which the associated plugin is not loaded', () => keepOrphans = true)\n .option('-T, --no-timestamp', 'do not issue timestamps in logging', () => noLogTimestamps = true)\n .option('-U, --user-storage-path [path]', 'look for homebridge user files at [path] instead of the default location (~/.homebridge)', path => customStoragePath = path)\n .option('--strict-plugin-resolution', 'only load plugins from the --plugin-path if set, otherwise from the primary global node_modules', () => strictPluginResolution = true)\n .parse(process.argv)\n\n if (noLogTimestamps) {\n Logger.setTimestampEnabled(false)\n }\n\n if (debugModeEnabled) {\n Logger.setDebugEnabled(true)\n }\n\n if (forceColourLogging) {\n Logger.forceColor()\n }\n\n if (customStoragePath) {\n User.setStoragePath(customStoragePath)\n }\n\n // Initialize HAP-NodeJS with a custom persist directory\n HAPStorage.setCustomStoragePath(User.persistPath())\n\n const options: HomebridgeOptions = {\n keepOrphanedCachedAccessories: keepOrphans,\n insecureAccess,\n hideQRCode,\n customPluginPath,\n noLogTimestamps,\n debugModeEnabled,\n forceColourLogging,\n customStoragePath,\n strictPluginResolution,\n }\n\n const server = new Server(options)\n\n const signalHandler = (signal: Signals, signalNum: number): void => {\n if (shuttingDown) {\n return\n }\n shuttingDown = true\n\n log.info('Got %s, shutting down Homebridge...', signal)\n setTimeout(() => process.exit(128 + signalNum), 5000)\n\n server.teardown()\n }\n process.on('SIGINT', signalHandler.bind(undefined, 'SIGINT', 2))\n process.on('SIGTERM', signalHandler.bind(undefined, 'SIGTERM', 15))\n\n const errorHandler = (error: Error): void => {\n if (error.stack) {\n log.error(error.stack)\n }\n\n if (!shuttingDown) {\n process.kill(process.pid, 'SIGTERM')\n }\n }\n process.on('uncaughtException', errorHandler)\n server.start().catch(errorHandler)\n}\n", "import util from 'node:util'\n\nimport chalk from 'chalk'\n\n/**\n * Log levels to indicate importance of the logged message.\n * Every level corresponds to a certain color.\n *\n * - INFO: no color\n * - SUCCESS: green\n * - WARN: yellow\n * - ERROR: red\n * - DEBUG: gray\n *\n * Messages with DEBUG level are only displayed if explicitly enabled.\n */\n// eslint-disable-next-line no-restricted-syntax\nexport const enum LogLevel {\n INFO = 'info',\n SUCCESS = 'success',\n WARN = 'warn',\n ERROR = 'error',\n DEBUG = 'debug',\n}\n\n/**\n * Represents a logging device which can be used directly as a function (for INFO logging)\n * but also has dedicated logging functions for respective logging levels.\n */\nexport interface Logging {\n\n prefix: string\n\n (message: string, ...parameters: any[]): void\n\n info: (message: string, ...parameters: any[]) => void\n success: (message: string, ...parameters: any[]) => void\n warn: (message: string, ...parameters: any[]) => void\n error: (message: string, ...parameters: any[]) => void\n debug: (message: string, ...parameters: any[]) => void\n log: (level: LogLevel, message: string, ...parameters: any[]) => void\n\n}\n\ninterface IntermediateLogging { // some auxiliary interface used to correctly type stuff happening in \"withPrefix\"\n\n prefix?: string\n\n (message: string, ...parameters: any[]): void\n\n info?: (message: string, ...parameters: any[]) => void\n success?: (message: string, ...parameters: any[]) => void\n warn?: (message: string, ...parameters: any[]) => void\n error?: (message: string, ...parameters: any[]) => void\n debug?: (message: string, ...parameters: any[]) => void\n log?: (level: LogLevel, message: string, ...parameters: any[]) => void\n\n}\n\n/**\n * Logger class\n */\nexport class Logger {\n public static readonly internal = new Logger()\n\n private static readonly loggerCache = new Map<string, Logging>() // global cache of logger instances by plugin name\n private static debugEnabled = false\n private static timestampEnabled = true\n\n readonly prefix?: string\n\n constructor(prefix?: string) {\n this.prefix = prefix\n }\n\n /**\n * Creates a new Logging device with a specified prefix.\n *\n * @param prefix {string} - the prefix of the logger\n */\n static withPrefix(prefix: string): Logging {\n const loggerStuff = Logger.loggerCache.get(prefix)\n\n if (loggerStuff) {\n return loggerStuff\n } else {\n const logger = new Logger(prefix)\n\n const log: IntermediateLogging = logger.info.bind(logger)\n log.info = logger.info\n log.success = logger.success\n log.warn = logger.warn\n log.error = logger.error\n log.debug = logger.debug\n log.log = logger.log\n\n log.prefix = logger.prefix\n\n // @ts-expect-error: I aimed to not use ts-ignore in this project, but this evil \"thing\" above is hell\n const logging: Logging = log\n Logger.loggerCache.set(prefix, logging)\n return logging\n }\n }\n\n /**\n * Turns on debug level logging. Off by default.\n *\n * @param enabled {boolean}\n */\n public static setDebugEnabled(enabled: boolean = true): void {\n Logger.debugEnabled = enabled\n }\n\n /**\n * Turns on inclusion of timestamps in log messages. On by default.\n *\n * @param enabled {boolean}\n */\n public static setTimestampEnabled(enabled: boolean = true): void {\n Logger.timestampEnabled = enabled\n }\n\n /**\n * Forces color in logging output, even if it seems like color is unsupported.\n */\n public static forceColor(): void {\n chalk.level = 1 // `1` - Basic 16 colors support.\n }\n\n public info(message: string, ...parameters: any[]): void {\n this.log(LogLevel.INFO, message, ...parameters)\n }\n\n public success(message: string, ...parameters: any[]): void {\n this.log(LogLevel.SUCCESS, message, ...parameters)\n }\n\n public warn(message: string, ...parameters: any[]): void {\n this.log(LogLevel.WARN, message, ...parameters)\n }\n\n public error(message: string, ...parameters: any[]): void {\n this.log(LogLevel.ERROR, message, ...parameters)\n }\n\n public debug(message: string, ...parameters: any[]): void {\n this.log(LogLevel.DEBUG, message, ...parameters)\n }\n\n public log(level: LogLevel, message: string, ...parameters: any[]): void {\n if (level === LogLevel.DEBUG && !Logger.debugEnabled) {\n return\n }\n\n message = util.format(message, ...parameters)\n\n let loggingFunction = console.log // eslint-disable-line no-console\n switch (level) {\n case LogLevel.SUCCESS:\n message = chalk.green(message)\n break\n case LogLevel.WARN:\n message = chalk.yellow(message)\n loggingFunction = console.error\n break\n case LogLevel.ERROR:\n message = chalk.red(message)\n loggingFunction = console.error\n break\n case LogLevel.DEBUG:\n message = chalk.gray(message)\n break\n }\n\n if (this.prefix) {\n message = `${getLogPrefix(this.prefix)} ${message}`\n }\n\n if (Logger.timestampEnabled) {\n const date = new Date()\n message = chalk.white(`[${date.toLocaleString()}] `) + message\n }\n\n loggingFunction(message)\n }\n}\n\n/**\n * Gets the prefix\n * @param prefix\n */\nexport function getLogPrefix(prefix: string): string {\n return chalk.cyan(`[${prefix}]`)\n}\n", "import type { MacAddress } from 'hap-nodejs'\n\nimport type {\n AccessoryIdentifier,\n AccessoryName,\n AccessoryPlugin,\n AccessoryPluginConstructor,\n PlatformIdentifier,\n PlatformName,\n PlatformPlugin,\n PlatformPluginConstructor,\n} from './api.js'\nimport type { BridgeConfiguration, BridgeOptions, HomebridgeConfig } from './bridgeService.js'\nimport type { Plugin } from './plugin.js'\nimport type { PluginManagerOptions } from './pluginManager.js'\n\nimport fs from 'node:fs'\nimport process from 'node:process'\n\nimport chalk from 'chalk'\nimport { AccessoryEventTypes, MDNSAdvertiser } from 'hap-nodejs'\nimport qrcode from 'qrcode-terminal'\n\nimport { HomebridgeAPI, PluginType } from './api.js'\nimport { BridgeService } from './bridgeService.js'\nimport { ChildBridgeService } from './childBridgeService.js'\nimport { ExternalPortService } from './externalPortService.js'\nimport { IpcIncomingEvent, IpcOutgoingEvent, IpcService } from './ipcService.js'\nimport { Logger } from './logger.js'\nimport { PluginManager } from './pluginManager.js'\nimport { User } from './user.js'\nimport { validMacAddress } from './util/mac.js'\n\nconst log = Logger.internal\n\nexport interface HomebridgeOptions {\n keepOrphanedCachedAccessories?: boolean\n hideQRCode?: boolean\n insecureAccess?: boolean\n customPluginPath?: string\n noLogTimestamps?: boolean\n debugModeEnabled?: boolean\n forceColourLogging?: boolean\n customStoragePath?: string\n strictPluginResolution?: boolean\n}\n\n// eslint-disable-next-line no-restricted-syntax\nexport const enum ServerStatus {\n /**\n * When the server is starting up\n */\n PENDING = 'pending',\n\n /**\n * When the server is online and has published the main bridge\n */\n OK = 'ok',\n\n /**\n * When the server is shutting down\n */\n DOWN = 'down',\n}\n\nexport class Server {\n private readonly api: HomebridgeAPI\n private readonly pluginManager: PluginManager\n private readonly bridgeService: BridgeService\n private readonly ipcService: IpcService\n private readonly externalPortService: ExternalPortService\n\n private readonly config: HomebridgeConfig\n\n // used to keep track of child bridges\n private readonly childBridges: Map<MacAddress, ChildBridgeService> = new Map()\n\n // current server status\n private serverStatus: ServerStatus = ServerStatus.PENDING\n\n constructor(\n private options: HomebridgeOptions = {},\n ) {\n this.config = Server.loadConfig()\n\n // object we feed to Plugins and BridgeService\n this.api = new HomebridgeAPI()\n this.ipcService = new IpcService()\n this.externalPortService = new ExternalPortService(this.config.ports)\n\n // set status to pending\n this.setServerStatus(ServerStatus.PENDING)\n\n // create new plugin manager\n const pluginManagerOptions: PluginManagerOptions = {\n activePlugins: this.config.plugins,\n disabledPlugins: this.config.disabledPlugins,\n customPluginPath: options.customPluginPath,\n strictPluginResolution: options.strictPluginResolution,\n }\n this.pluginManager = new PluginManager(this.api, pluginManagerOptions)\n\n // create new bridge service\n const bridgeConfig: BridgeOptions = {\n cachedAccessoriesDir: User.cachedAccessoryPath(),\n cachedAccessoriesItemName: 'cachedAccessories',\n }\n\n // shallow copy the homebridge options to the bridge options object\n Object.assign(bridgeConfig, this.options)\n\n this.bridgeService = new BridgeService(\n this.api,\n this.pluginManager,\n this.externalPortService,\n bridgeConfig,\n this.config.bridge,\n this.config,\n )\n\n // watch bridge events to check when server is online\n this.bridgeService.bridge.on(AccessoryEventTypes.ADVERTISED, () => {\n this.setServerStatus(ServerStatus.OK)\n })\n\n // watch for the paired event to update the server status\n this.bridgeService.bridge.on(AccessoryEventTypes.PAIRED, () => {\n this.setServerStatus(this.serverStatus)\n })\n\n // watch for the unpaired event to update the server status\n this.bridgeService.bridge.on(AccessoryEventTypes.UNPAIRED, () => {\n this.setServerStatus(this.serverStatus)\n })\n }\n\n /**\n * Set the current server status and update parent via IPC\n * @param status\n */\n private setServerStatus(status: ServerStatus) {\n this.serverStatus = status\n this.ipcService.sendMessage(IpcOutgoingEvent.SERVER_STATUS_UPDATE, {\n status: this.serverStatus,\n paired: this.bridgeService?.bridge?._accessoryInfo?.paired() ?? null,\n setupUri: this.bridgeService?.bridge?.setupURI() ?? null,\n name: this.bridgeService?.bridge?.displayName || this.config.bridge.name,\n username: this.config.bridge.username,\n pin: this.config.bridge.pin,\n })\n }\n\n public async start(): Promise<void> {\n if (this.config.bridge.disableIpc !== true) {\n this.initializeIpcEventHandlers()\n }\n\n const promises: Promise<void>[] = []\n\n // load the cached accessories\n await this.bridgeService.loadCachedPlatformAccessoriesFromDisk()\n\n // initialize plugins\n await this.pluginManager.initializeInstalledPlugins()\n\n if (this.config.platforms.length > 0) {\n promises.push(...this.loadPlatforms())\n }\n if (this.config.accessories.length > 0) {\n this.loadAccessories()\n }\n\n // start child bridges\n for (const childBridge of this.childBridges.values()) {\n childBridge.start()\n }\n\n // restore cached accessories\n this.bridgeService.restoreCachedPlatformAccessories()\n\n this.api.signalFinished()\n\n // wait for all platforms to publish their accessories before we publish the bridge\n await Promise.all(promises)\n .then(() => this.publishBridge())\n }\n\n public teardown(): void {\n this.bridgeService.teardown()\n this.setServerStatus(ServerStatus.DOWN)\n }\n\n private publishBridge(): void {\n this.bridgeService.publishBridge()\n this.printSetupInfo(this.config.bridge.pin)\n }\n\n private static loadConfig(): HomebridgeConfig {\n // Look for the configuration file\n const configPath = User.configPath()\n\n const defaultBridge: BridgeConfiguration = {\n name: 'Homebridge',\n username: 'CC:22:3D:E3:CE:30',\n pin: '031-45-154',\n }\n\n if (!fs.existsSync(configPath)) {\n log.warn('config.json (%s) not found.', configPath)\n return { // return a default configuration\n bridge: defaultBridge,\n accessories: [],\n platforms: [],\n }\n }\n\n let config: Partial<HomebridgeConfig>\n try {\n config = JSON.parse(fs.readFileSync(configPath, { encoding: 'utf8' }))\n } catch (error: any) {\n log.error('There was a problem reading your config.json file.')\n log.error('Please try pasting your config.json file here to validate it: https://jsonlint.com')\n log.error('')\n throw error\n }\n\n if (config.ports !== undefined) {\n if (config.ports.start && config.ports.end) {\n if (config.ports.start > config.ports.end) {\n log.error('Invalid port pool configuration. End should be greater than or equal to start.')\n config.ports = undefined\n }\n } else {\n log.error('Invalid configuration for \\'ports\\'. Missing \\'start\\' and \\'end\\' properties! Ignoring it!')\n config.ports = undefined\n }\n }\n\n const bridge: BridgeConfiguration = config.bridge || defaultBridge\n bridge.name = bridge.name || defaultBridge.name\n bridge.username = bridge.username || defaultBridge.username\n bridge.pin = bridge.pin || defaultBridge.pin\n config.bridge = bridge\n\n const username = config.bridge.username\n if (!validMacAddress(username)) {\n throw new Error(`Not a valid username: ${username}. Must be 6 pairs of colon-separated hexadecimal chars (A-F 0-9), like a MAC address.`)\n }\n\n config.accessories = config.accessories || []\n config.platforms = config.platforms || []\n\n if (!Array.isArray(config.accessories)) {\n log.error('Value provided for accessories must be an array[]')\n config.accessories = []\n }\n\n if (!Array.isArray(config.platforms)) {\n log.error('Value provided for platforms must be an array[]')\n config.platforms = []\n }\n\n log.info('Loaded config.json with %s accessories and %s platforms.', config.accessories.length, config.platforms.length)\n\n if (config.bridge.advertiser) {\n if (![\n MDNSAdvertiser.BONJOUR,\n MDNSAdvertiser.CIAO,\n MDNSAdvertiser.AVAHI,\n MDNSAdvertiser.RESOLVED,\n ].includes(config.bridge.advertiser)) {\n config.bridge.advertiser = undefined\n log.error('Value provided in bridge.advertiser is not valid, reverting to platform default.')\n }\n } else {\n config.bridge.advertiser = undefined\n }\n\n return config as HomebridgeConfig\n }\n\n private loadAccessories(): void {\n log.info(`Loading ${this.config.accessories.length} accessories...`)\n\n this.config.accessories.forEach((accessoryConfig, index) => {\n if (!accessoryConfig.accessory) {\n log.warn('Your config.json contains an illegal accessory configuration object at position %d. '\n + 'Missing property \\'accessory\\'. Skipping entry...', index + 1) // we rather count from 1 for the normal people?\n return\n }\n\n const accessoryIdentifier: AccessoryName | AccessoryIdentifier = accessoryConfig.accessory\n const displayName = accessoryConfig.name\n if (!displayName) {\n log.warn('Could not load accessory %s at position %d as it is missing the required \\'name\\' property!', accessoryIdentifier, index + 1)\n return\n }\n\n let plugin: Plugin\n let constructor: AccessoryPluginConstructor\n\n try {\n plugin = this.pluginManager.getPluginForAccessory(accessoryIdentifier)\n } catch (error: any) {\n log.error(error.message)\n return\n }\n\n // check the plugin is not disabled\n if (plugin.disabled) {\n log.warn(`Ignoring config for the accessory \"${accessoryIdentifier}\" in your config.json as the plugin \"${plugin.getPluginIdentifier()}\" has been disabled.`)\n return\n }\n\n try {\n constructor = plugin.getAccessoryConstructor(accessoryIdentifier)\n } catch (error: any) {\n log.error(`Error loading the accessory \"${accessoryIdentifier}\" requested in your config.json at position ${index + 1} - this is likely an issue with the \"${plugin.getPluginIdentifier()}\" plugin.`)\n log.error(error) // error message contains more information and full stack trace\n return\n }\n\n const logger = Logger.withPrefix(displayName)\n logger('Initializing %s accessory...', accessoryIdentifier)\n\n if (accessoryConfig._bridge) {\n // ensure the username is always uppercase\n accessoryConfig._bridge.username = accessoryConfig._bridge.username.toUpperCase()\n\n try {\n this.validateChildBridgeConfig(PluginType.ACCESSORY, accessoryIdentifier, accessoryConfig._bridge)\n } catch (error: any) {\n log.error(error.message)\n return\n }\n\n let childBridge: ChildBridgeService\n\n if (this.childBridges.has(accessoryConfig._bridge.username)) {\n childBridge = this.childBridges.get(accessoryConfig._bridge.username)!\n logger(`Adding to existing child bridge ${accessoryConfig._bridge.username}`)\n } else {\n logger(`Initializing child bridge ${accessoryConfig._bridge.username}`)\n childBridge = new ChildBridgeService(\n PluginType.ACCESSORY,\n accessoryIdentifier,\n plugin,\n accessoryConfig._bridge,\n this.config,\n this.options,\n this.api,\n this.ipcService,\n this.externalPortService,\n )\n\n this.childBridges.set(accessoryConfig._bridge.username, childBridge)\n }\n\n // add config to child bridge service\n childBridge.addConfig(accessoryConfig)\n\n return\n }\n\n const accessoryInstance: AccessoryPlugin = new constructor(logger, accessoryConfig, this.api)\n\n // pass accessoryIdentifier for UUID generation, and optional parameter uuid_base which can be used instead of displayName for UUID generation\n const accessory = this.bridgeService.createHAPAccessory(plugin, accessoryInstance, displayName, accessoryIdentifier, accessoryConfig.uuid_base)\n\n if (accessory) {\n try {\n this.bridgeService.bridge.addBridgedAccessory(accessory)\n } catch (error: any) {\n logger.error(`Error loading the accessory \"${accessoryIdentifier}\" from \"${plugin.getPluginIdentifier()}\" requested in your config.json:`, error.message)\n }\n } else {\n logger.info('Accessory %s returned empty set of services; not adding it to the bridge.', accessoryIdentifier)\n }\n })\n }\n\n private loadPlatforms(): Promise<void>[] {\n log.info(`Loading ${this.config.platforms.length} platforms...`)\n\n const promises: Promise<void>[] = []\n this.config.platforms.forEach((platformConfig, index) => {\n if (!platformConfig.platform) {\n log.warn('Your config.json contains an illegal platform configuration object at position %d. '\n + 'Missing property \\'platform\\'. Skipping entry...', index + 1) // we rather count from 1 for the normal people?\n return\n }\n\n const platformIdentifier: PlatformName | PlatformIdentifier = platformConfig.platform\n const displayName = platformConfig.name || platformIdentifier\n\n let plugin: Plugin\n let constructor: PlatformPluginConstructor\n\n // do not load homebridge-config-ui-x when running in service mode\n if (platformIdentifier === 'config' && process.env.UIX_SERVICE_MODE === '1') {\n return\n }\n\n try {\n plugin = this.pluginManager.getPluginForPlatform(platformIdentifier)\n } catch (error: any) {\n log.error(error.message)\n return\n }\n\n // check the plugin is not disabled\n if (plugin.disabled) {\n log.warn(`Ignoring config for the platform \"${platformIdentifier}\" in your config.json as the plugin \"${plugin.getPluginIdentifier()}\" has been disabled.`)\n return\n }\n\n try {\n constructor = plugin.getPlatformConstructor(platformIdentifier)\n } catch (error: any) {\n log.error(`Error loading the platform \"${platformIdentifier}\" requested in your config.json at position ${index + 1} - this is likely an issue with the \"${plugin.getPluginIdentifier()}\" plugin.`)\n log.error(error) // error message contains more information and full stack trace\n return\n }\n\n const logger = Logger.withPrefix(displayName)\n logger('Initializing %s platform...', platformIdentifier)\n\n if (platformConfig._bridge) {\n // ensure the username is always uppercase\n platformConfig._bridge.username = platformConfig._bridge.username.toUpperCase()\n\n try {\n this.validateChildBridgeConfig(PluginType.PLATFORM, platformIdentifier, platformConfig._bridge)\n } catch (error: any) {\n log.error(error.message)\n return\n }\n\n logger(`Initializing child bridge ${platformConfig._bridge.username}`)\n const childBridge = new ChildBridgeService(\n PluginType.PLATFORM,\n platformIdentifier,\n plugin,\n platformConfig._bridge,\n this.config,\n this.options,\n this.api,\n this.ipcService,\n this.externalPortService,\n )\n\n this.childBridges.set(platformConfig._bridge.username, childBridge)\n\n // add config to child bridge service\n childBridge.addConfig(platformConfig)\n return\n }\n\n const platform: PlatformPlugin = new constructor(logger, platformConfig, this.api)\n\n if (HomebridgeAPI.isDynamicPlatformPlugin(platform)) {\n plugin.assignDynamicPlatform(platformIdentifier, platform)\n } else if (HomebridgeAPI.isStaticPlatformPlugin(platform)) { // Plugin 1.0, load accessories\n promises.push(this.bridgeService.loadPlatformAccessories(plugin, platform, platformIdentifier, logger))\n } else {\n // otherwise it's a IndependentPlatformPlugin which doesn't expose any methods at all.\n // We just call the constructor and let it be enabled.\n }\n })\n\n return promises\n }\n\n /**\n * Validate an external bridge config\n */\n private validateChildBridgeConfig(type: PluginType, identifier: string, bridgeConfig: BridgeConfiguration): void {\n if (!validMacAddress(bridgeConfig.username)) {\n throw new Error(\n `Error loading the ${type} \"${identifier}\" requested in your config.json - `\n + `not a valid username in _bridge.username: \"${bridgeConfig.username}\". Must be 6 pairs of colon-separated hexadecimal chars (A-F 0-9), like a MAC address.`,\n )\n }\n\n if (this.childBridges.has(bridgeConfig.username)) {\n const childBridge = this.childBridges.get(bridgeConfig.username)\n if (type === PluginType.PLATFORM) {\n // only a single platform can exist on one child bridge\n throw new Error(\n `Error loading the ${type} \"${identifier}\" requested in your config.json - `\n + `Duplicate username found in _bridge.username: \"${bridgeConfig.username}\". Each platform child bridge must have it's own unique username.`,\n )\n } else if (childBridge?.identifier !== identifier) {\n // only accessories of the same type can be added to the same child bridge\n throw new Error(\n `Error loading the ${type} \"${identifier}\" requested in your config.json - `\n + `Duplicate username found in _bridge.username: \"${bridgeConfig.username}\". You can only group accessories of the same type in a child bridge.`,\n )\n }\n }\n\n if (bridgeConfig.username === this.config.bridge.username.toUpperCase()) {\n throw new Error(\n `Error loading the ${type} \"${identifier}\" requested in your config.json - `\n + `Username found in _bridge.username: \"${bridgeConfig.username}\" is the same as the main bridge. Each child bridge platform/accessory must have it's own unique username.`,\n )\n }\n }\n\n /**\n * Takes care of the IPC Events sent to Homebridge\n */\n private initializeIpcEventHandlers() {\n // start ipc service\n this.ipcService.start()\n\n // handle restart child bridge event\n this.ipcService.on(IpcIncomingEvent.RESTART_CHILD_BRIDGE, (username) => {\n if (typeof username === 'string') {\n const childBridge = this.childBridges.get(username.toUpperCase())\n childBridge?.restartChildBridge()\n }\n })\n\n // handle stop child bridge event\n this.ipcService.on(IpcIncomingEvent.STOP_CHILD_BRIDGE, (username) => {\n if (typeof username === 'string') {\n const childBridge = this.childBridges.get(username.toUpperCase())\n childBridge?.stopChildBridge()\n }\n })\n\n // handle start child bridge event\n this.ipcService.on(IpcIncomingEvent.START_CHILD_BRIDGE, (username) => {\n if (typeof username === 'string') {\n const childBridge = this.childBridges.get(username.toUpperCase())\n childBridge?.startChildBridge()\n }\n })\n\n this.ipcService.on(IpcIncomingEvent.CHILD_BRIDGE_METADATA_REQUEST, () => {\n this.ipcService.sendMessage(\n IpcOutgoingEvent.CHILD_BRIDGE_METADATA_RESPONSE,\n Array.from(this.childBridges.values()).map(x => x.getMetadata()),\n )\n })\n }\n\n private printSetupInfo(pin: string): void {\n /* eslint-disable no-console */\n console.log('Setup Payload:')\n console.log(this.bridgeService.bridge.setupURI())\n\n if (!this.options.hideQRCode) {\n console.log('Scan this code with your HomeKit app on your iOS device to pair with Homebridge:')\n qrcode.setErrorLevel('M') // HAP specifies level M or higher for ECC\n qrcode.generate(this.bridgeService.bridge.setupURI())\n console.log('Or enter this code with your HomeKit app on your iOS device to pair with Homebridge:')\n } else {\n console.log('Enter this code with your HomeKit app on your iOS device to pair with Homebridge:')\n }\n\n console.log(chalk.black.bgWhite(' '))\n console.log(chalk.black.bgWhite(' \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 '))\n console.log(chalk.black.bgWhite(` \u2502 ${pin} \u2502 `))\n console.log(chalk.black.bgWhite(' \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 '))\n console.log(chalk.black.bgWhite(' '))\n /* eslint-enable no-console */\n }\n}\n", "import type { Controller, Service } from 'hap-nodejs'\n\nimport type { AccessoryConfig, PlatformConfig } from './bridgeService.js'\nimport type { Logging } from './logger.js'\n\nimport { EventEmitter } from 'node:events'\n\nimport hapNodeJs from 'hap-nodejs'\nimport semver from 'semver'\n\nimport { Logger } from './logger.js'\nimport { PlatformAccessory } from './platformAccessory.js'\nimport { PluginManager } from './pluginManager.js'\nimport { User } from './user.js'\nimport getVersion from './version.js'\n\nconst log = Logger.internal\n\nexport type HAP = typeof hapNodeJs\nexport type HAPLegacyTypes = typeof hapNodeJs.LegacyTypes\n\nexport type PluginIdentifier = PluginName | ScopedPluginName\nexport type PluginName = string // plugin name like \"homebridge-dummy\"\nexport type ScopedPluginName = string // plugin name like \"@scope/homebridge-dummy\"\nexport type AccessoryName = string\nexport type PlatformName = string\n\nexport type AccessoryIdentifier = string // format: \"PluginIdentifier.AccessoryName\"\nexport type PlatformIdentifier = string // format: \"PluginIdentifier.PlatformName\"\n\n// eslint-disable-next-line no-restricted-syntax\nexport const enum PluginType {\n ACCESSORY = 'accessory',\n PLATFORM = 'platform',\n}\n\n/**\n * The {PluginInitializer} is a method which must be the default export for every homebridge plugin.\n * It is called once the plugin is loaded from disk.\n */\nexport interface PluginInitializer {\n\n /**\n * When the initializer is called the plugin must use the provided api instance and call the appropriate\n * register methods - {@link API.registerAccessory} or {@link API.registerPlatform} - in order to\n * correctly register for the following startup sequence.\n *\n * @param {API} api\n */\n (api: API): void | Promise<void>\n\n}\n\nexport interface AccessoryPluginConstructor {\n new(logger: Logging, config: AccessoryConfig, api: API): AccessoryPlugin\n}\n\nexport interface AccessoryPlugin {\n\n /**\n * Optional method which will be called if an 'identify' of an Accessory is requested by HomeKit.\n */\n identify?: () => void\n\n /**\n * This method will be called once on startup, to query all services to be exposed by the Accessory.\n * All event handlers for characteristics should be set up before the array is returned.\n *\n * @returns {Service[]} services - returned services will be added to the Accessory\n */\n getServices: () => Service[]\n\n /**\n * This method will be called once on startup, to query all controllers to be exposed by the Accessory.\n * It is optional to implement.\n *\n * This includes controllers like the RemoteController or the CameraController.\n * Any necessary controller specific setup should have been done when returning the array.\n * In most cases the plugin will only return an array of the size 1.\n *\n * In the case that the Plugin does not add any additional services (returned by {@link getServices}) the\n * method {@link getServices} must be defined in any way and should just return an empty array.\n *\n * @returns {Controller[]} controllers - returned controllers will be configured for the Accessory\n */\n getControllers?: () => Controller[]\n\n}\n\nexport interface PlatformPluginConstructor<Config extends PlatformConfig = PlatformConfig> {\n new(logger: Logging, config: Config, api: API): DynamicPlatformPlugin | StaticPlatformPlugin | IndependentPlatformPlugin\n}\n\nexport interface PlatformPlugin {} // not exported to the public in index.ts\n\n/**\n * Platform that is able to dynamically add or remove accessories.\n * All configured accessories are stored to disk and recreated on startup.\n * Accessories can be added or removed by using {@link API.registerPlatformAccessories} or {@link API.unregisterPlatformAccessories}.\n */\nexport interface DynamicPlatformPlugin extends PlatformPlugin {\n\n /**\n * This method is called for every PlatformAccessory, which is recreated from disk on startup.\n * It should be used to properly initialize the Accessory and setup all event handlers for\n * all services and their characteristics.\n *\n * @param {PlatformAccessory} accessory which needs to be configured\n */\n configureAccessory: (accessory: PlatformAccessory) => void\n\n}\n\n/**\n * Platform that exposes all available characteristics at the start of the plugin.\n * The set of accessories can not change at runtime.\n * The bridge waits for all callbacks to return before it is published and accessible by HomeKit controllers.\n */\nexport interface StaticPlatformPlugin extends PlatformPlugin {\n\n /**\n * This method is called once at startup. The Platform should pass all accessories which need to be created\n * to the callback in form of a {@link AccessoryPlugin}.\n * The Platform must respond in a timely manner as otherwise the startup of the bridge would be unnecessarily delayed.\n *\n * @param {(foundAccessories: AccessoryPlugin[]) => void} callback\n */\n accessories: (callback: (foundAccessories: AccessoryPlugin[]) => void) => void\n\n}\n\n/**\n * Platform that does not aim to add any accessories to the main bridge accessory.\n * This platform should be used if for example a plugin aims to only expose external accessories.\n * It should also be used when the platform doesn't intend to expose any accessories at all, like plugins\n * providing a UI for homebridge.\n */\nexport interface IndependentPlatformPlugin extends PlatformPlugin {\n // does not expose any methods\n}\n\n// eslint-disable-next-line no-restricted-syntax\nexport const enum APIEvent {\n /**\n * Event is fired once homebridge has finished with booting up and initializing all components and plugins.\n * When this event is fired it is possible that the Bridge accessory isn't published yet, if homebridge still needs\n * to wait for some {@see StaticPlatformPlugin | StaticPlatformPlugins} to finish accessory creation.\n */\n DID_FINISH_LAUNCHING = 'didFinishLaunching',\n /**\n * This event is fired when homebridge gets shutdown. This could be a regular shutdown or an unexpected crash.\n * At this stage all Accessories are already unpublished and all PlatformAccessories are already saved to disk!\n */\n SHUTDOWN = 'shutdown',\n}\n\n// eslint-disable-next-line no-restricted-syntax\nexport const enum InternalAPIEvent {\n REGISTER_ACCESSORY = 'registerAccessory',\n REGISTER_PLATFORM = 'registerPlatform',\n\n PUBLISH_EXTERNAL_ACCESSORIES = 'publishExternalAccessories',\n REGISTER_PLATFORM_ACCESSORIES = 'registerPlatformAccessories',\n UPDATE_PLATFORM_ACCESSORIES = 'updatePlatformAccessories',\n UNREGISTER_PLATFORM_ACCESSORIES = 'unregisterPlatformAccessories',\n}\n\nexport interface API {\n\n /**\n * The homebridge API version as a floating point number.\n */\n readonly version: number\n /**\n * The current homebridge semver version.\n */\n readonly serverVersion: string\n\n // ------------------ LEGACY EXPORTS FOR PRE TYPESCRIPT ------------------\n readonly user: typeof User\n readonly hap: HAP\n readonly hapLegacyTypes: HAPLegacyTypes // used for older accessories/platforms\n readonly platformAccessory: typeof PlatformAccessory\n // ------------------------------------------------------------------------\n\n /**\n * Returns true if the current running homebridge version is greater or equal to the\n * passed version string.\n *\n * Example:\n *\n * We assume the homebridge version 1.3.0-beta.12 ({@link serverVersion}) and the following example calls below\n * ```\n * versionGreaterOrEqual(\"1.2.0\"); // will return true\n * versionGreaterOrEqual(\"1.3.0\"); // will return false (the RELEASE version 1.3.0 is bigger than the BETA version 1.3.0-beta.12)\n * versionGreaterOrEqual(\"1.3.0-beta.8); // will return true\n * ```\n *\n * @param version\n */\n versionGreaterOrEqual: (version: string) => boolean\n\n registerAccessory: ((accessoryName: AccessoryName, constructor: AccessoryPluginConstructor) => void) & ((pluginIdentifier: PluginIdentifier, accessoryName: AccessoryName, constructor: AccessoryPluginConstructor) => void)\n\n registerPlatform: (<Config extends PlatformConfig>(platformName: PlatformName, constructor: PlatformPluginConstructor<Config>) => void) & (<Config extends PlatformConfig>(pluginIdentifier: PluginIdentifier, platformName: PlatformName, constructor: PlatformPluginConstructor<Config>) => void)\n registerPlatformAccessories: (pluginIdentifier: PluginIdentifier, platformName: PlatformName, accessories: PlatformAccessory[]) => void\n updatePlatformAccessories: (accessories: PlatformAccessory[]) => void\n unregisterPlatformAccessories: (pluginIdentifier: PluginIdentifier, platformName: PlatformName, accessories: PlatformAccessory[]) => void\n\n publishExternalAccessories: (pluginIdentifier: PluginIdentifier, accessories: PlatformAccessory[]) => void\n\n on: ((event: 'didFinishLaunching', listener: () => void) => this) & ((event: 'shutdown', listener: () => void) => this)\n\n}\n\n// eslint-disable-next-line ts/no-unsafe-declaration-merging\nexport declare interface HomebridgeAPI {\n\n on: ((event: 'didFinishLaunching', listener: () => void) => this) & ((event: 'shutdown', listener: () => void) => this) & ((event: InternalAPIEvent.REGISTER_ACCESSORY, listener: (accessoryName: AccessoryName, accessoryConstructor: AccessoryPluginConstructor, pluginIdentifier?: PluginIdentifier) => void) => this) & ((event: InternalAPIEvent.REGISTER_PLATFORM, listener: (platformName: PlatformName, platformConstructor: PlatformPluginConstructor, pluginIdentifier?: PluginIdentifier) => void) => this) & ((event: InternalAPIEvent.PUBLISH_EXTERNAL_ACCESSORIES, listener: (accessories: PlatformAccessory[]) => void) => this) & ((event: InternalAPIEvent.REGISTER_PLATFORM_ACCESSORIES, listener: (accessories: PlatformAccessory[]) => void) => this) & ((event: InternalAPIEvent.UPDATE_PLATFORM_ACCESSORIES, listener: (accessories: PlatformAccessory[]) => void) => this) & ((event: InternalAPIEvent.UNREGISTER_PLATFORM_ACCESSORIES, listener: (accessories: PlatformAccessory[]) => void) => this)\n\n emit: ((event: 'didFinishLaunching') => boolean) & ((event: 'shutdown') => boolean) & ((event: InternalAPIEvent.REGISTER_ACCESSORY, accessoryName: AccessoryName, accessoryConstructor: AccessoryPluginConstructor, pluginIdentifier?: PluginIdentifier) => boolean) & ((event: InternalAPIEvent.REGISTER_PLATFORM, platformName: PlatformName, platformConstructor: PlatformPluginConstructor, pluginIdentifier?: PluginIdentifier) => boolean) & ((event: InternalAPIEvent.PUBLISH_EXTERNAL_ACCESSORIES, accessories: PlatformAccessory[]) => boolean) & ((event: InternalAPIEvent.REGISTER_PLATFORM_ACCESSORIES, accessories: PlatformAccessory[]) => boolean) & ((event: InternalAPIEvent.UPDATE_PLATFORM_ACCESSORIES, accessories: PlatformAccessory[]) => boolean) & ((event: InternalAPIEvent.UNREGISTER_PLATFORM_ACCESSORIES, accessories: PlatformAccessory[]) => boolean)\n\n}\n\n// eslint-disable-next-line ts/no-unsafe-declaration-merging\nexport class HomebridgeAPI extends EventEmitter implements API {\n public readonly version = 2.7 // homebridge API version\n public readonly serverVersion = getVersion() // homebridge node module version\n\n // ------------------ LEGACY EXPORTS FOR PRE TYPESCRIPT ------------------\n readonly user = User\n readonly hap = hapNodeJs\n readonly hapLegacyTypes = hapNodeJs.LegacyTypes // used for older accessories/platforms\n readonly platformAccessory = PlatformAccessory\n // ------------------------------------------------------------------------\n\n constructor() {\n super()\n }\n\n public versionGreaterOrEqual(version: string): boolean {\n return semver.gte(this.serverVersion, version)\n }\n\n public static isDynamicPlatformPlugin(platformPlugin: PlatformPlugin): platformPlugin is DynamicPlatformPlugin {\n return 'configureAccessory' in platformPlugin\n }\n\n public static isStaticPlatformPlugin(platformPlugin: PlatformPlugin): platformPlugin is StaticPlatformPlugin {\n return 'accessories' in platformPlugin\n }\n\n signalFinished(): void {\n this.emit(APIEvent.DID_FINISH_LAUNCHING)\n }\n\n signalShutdown(): void {\n this.emit(APIEvent.SHUTDOWN)\n }\n\n registerAccessory(accessoryName: AccessoryName, constructor: AccessoryPluginConstructor): void\n registerAccessory(pluginIdentifier: PluginIdentifier, accessoryName: AccessoryName, constructor: AccessoryPluginConstructor): void\n\n registerAccessory(pluginIdentifier: PluginIdentifier | AccessoryName, accessoryName: AccessoryName | AccessoryPluginConstructor, constructor?: AccessoryPluginConstructor): void {\n if (typeof accessoryName === 'function') {\n constructor = accessoryName\n accessoryName = pluginIdentifier\n this.emit(InternalAPIEvent.REGISTER_ACCESSORY, accessoryName, constructor)\n } else {\n this.emit(InternalAPIEvent.REGISTER_ACCESSORY, accessoryName, constructor!, pluginIdentifier)\n }\n }\n\n registerPlatform(platformName: PlatformName, constructor: PlatformPluginConstructor): void\n registerPlatform(pluginIdentifier: PluginIdentifier, platformName: PlatformName, constructor: PlatformPluginConstructor): void\n\n registerPlatform(pluginIdentifier: PluginIdentifier | PlatformName, platformName: PlatformName | PlatformPluginConstructor, constructor?: PlatformPluginConstructor): void {\n if (typeof platformName === 'function') {\n constructor = platformName\n platformName = pluginIdentifier\n this.emit(InternalAPIEvent.REGISTER_PLATFORM, platformName, constructor)\n } else {\n this.emit(InternalAPIEvent.REGISTER_PLATFORM, platformName, constructor!, pluginIdentifier)\n }\n }\n\n publishCameraAccessories(pluginIdentifier: PluginIdentifier, accessories: PlatformAccessory[]): void {\n this.publishExternalAccessories(pluginIdentifier, accessories)\n }\n\n publishExternalAccessories(pluginIdentifier: PluginIdentifier, accessories: PlatformAccessory[]): void {\n if (!PluginManager.isQualifiedPluginIdentifier(pluginIdentifier)) {\n log.info(`One of your plugins incorrectly registered an external accessory using the platform name (${pluginIdentifier}) and not the plugin identifier. Please report this to the developer!`)\n }\n\n accessories.forEach((accessory) => {\n // noinspection SuspiciousTypeOfGuard\n if (!(accessory instanceof PlatformAccessory)) {\n throw new TypeError(`${pluginIdentifier} attempt to register an accessory that isn't PlatformAccessory!`)\n }\n\n accessory._associatedPlugin = pluginIdentifier\n })\n\n this.emit(InternalAPIEvent.PUBLISH_EXTERNAL_ACCESSORIES, accessories)\n }\n\n registerPlatformAccessories(pluginIdentifier: PluginIdentifier, platformName: PlatformName, accessories: PlatformAccessory[]): void {\n accessories.forEach((accessory) => {\n // noinspection SuspiciousTypeOfGuard\n if (!(accessory instanceof PlatformAccessory)) {\n throw new TypeError(`${pluginIdentifier} - ${platformName} attempt to register an accessory that isn't PlatformAccessory!`)\n }\n\n accessory._associatedPlugin = pluginIdentifier\n accessory._associatedPlatform = platformName\n })\n\n this.emit(InternalAPIEvent.REGISTER_PLATFORM_ACCESSORIES, accessories)\n }\n\n updatePlatformAccessories(accessories: PlatformAccessory[]): void {\n this.emit(InternalAPIEvent.UPDATE_PLATFORM_ACCESSORIES, accessories)\n }\n\n unregisterPlatformAccessories(pluginIdentifier: PluginIdentifier, platformName: PlatformName, accessories: PlatformAccessory[]): void {\n accessories.forEach((accessory) => {\n // noinspection SuspiciousTypeOfGuard\n if (!(accessory instanceof PlatformAccessory)) {\n throw new TypeError(`${pluginIdentifier} - ${platformName} attempt to unregister an accessory that isn't PlatformAccessory!`)\n }\n })\n\n this.emit(InternalAPIEvent.UNREGISTER_PLATFORM_ACCESSORIES, accessories)\n }\n}\n", "import type {\n Controller,\n ControllerConstructor,\n SerializedAccessory,\n Service,\n VoidCallback,\n WithUUID,\n} from 'hap-nodejs'\nimport type { ConstructorArgs } from 'hap-nodejs/dist/types.js'\n\nimport type { PlatformName, PluginIdentifier, PluginName } from './api.js'\n\nimport { EventEmitter } from 'node:events'\n\nimport {\n Accessory,\n AccessoryEventTypes,\n Categories,\n} from 'hap-nodejs'\n\nexport type UnknownContext = Record<string, any>\n\nexport interface SerializedPlatformAccessory<T extends UnknownContext = UnknownContext> extends SerializedAccessory {\n\n plugin: PluginName\n platform: PlatformName\n context: T\n\n}\n\n// eslint-disable-next-line no-restricted-syntax\nexport const enum PlatformAccessoryEvent {\n IDENTIFY = 'identify',\n}\n\n// eslint-disable-next-line ts/no-unsafe-declaration-merging\nexport declare interface PlatformAccessory {\n\n on: (event: 'identify', listener: () => void) => this\n\n emit: (event: 'identify') => boolean\n\n}\n\n// eslint-disable-next-line ts/no-unsafe-declaration-merging\nexport class PlatformAccessory<T extends UnknownContext = UnknownContext> extends EventEmitter {\n // somewhat ugly way to inject custom Accessory object, while not changing the publicly exposed constructor signature\n private static injectedAccessory?: Accessory\n\n _associatedPlugin?: PluginIdentifier // present as soon as it is registered\n _associatedPlatform?: PlatformName // not present for external accessories\n\n _associatedHAPAccessory: Accessory\n\n // ---------------- HAP Accessory mirror ----------------\n displayName: string\n UUID: string\n category: Categories\n services: Service[] = []\n // ------------------------------------------------------\n\n /**\n * This is a way for Plugin developers to store custom data with their accessory\n */\n public context: T = {} as T // providing something to store\n\n constructor(displayName: string, uuid: string, category?: Categories) { // category is only useful for external accessories\n super()\n this._associatedHAPAccessory = PlatformAccessory.injectedAccessory\n ? PlatformAccessory.injectedAccessory\n : new Accessory(displayName, uuid)\n\n if (category) {\n this._associatedHAPAccessory.category = category\n }\n\n this.displayName = this._associatedHAPAccessory.displayName\n this.UUID = this._associatedHAPAccessory.UUID\n this.category = category || Categories.OTHER\n this.services = this._associatedHAPAccessory.services\n\n // forward identify event\n this._associatedHAPAccessory.on(AccessoryEventTypes.IDENTIFY, (paired: boolean, callback: VoidCallback) => {\n // @ts-expect-error: empty callback for backwards compatibility\n this.emit(PlatformAccessoryEvent.IDENTIFY, paired, () => {})\n callback()\n })\n }\n\n public addService(service: Service): Service\n public addService<S extends typeof Service>(serviceConstructor: S, ...constructorArgs: ConstructorArgs<S>): Service\n public addService(service: Service | typeof Service, ...constructorArgs: any[]): Service {\n // @ts-expect-error: while the HAP-NodeJS interface was refined, the underlying implementation\n // still only operates on an any[] array. Therefore, do not require any additional checks here\n // we force the parameter unpack with expecting a ts-error.\n return this._associatedHAPAccessory.addService(service, ...constructorArgs)\n }\n\n public removeService(service: Service): void {\n this._associatedHAPAccessory.removeService(service)\n }\n\n public getService<T extends WithUUID<typeof Service>>(name: string | T): Service | undefined {\n return this._associatedHAPAccessory.getService(name)\n }\n\n public getServiceById<T extends WithUUID<typeof Service>>(uuid: string | T, subType: string): Service | undefined {\n return this._associatedHAPAccessory.getServiceById(uuid, subType)\n }\n\n /**\n * Configures a new controller for the given accessory.\n * See {@link https://developers.homebridge.io/HAP-NodeJS/classes/accessory.html#configurecontroller | Accessory.configureController}.\n *\n * @param controller\n */\n public configureController(controller: Controller | ControllerConstructor): void {\n this._associatedHAPAccessory.configureController(controller)\n }\n\n /**\n * Removes a configured controller from the given accessory.\n * See {@link https://developers.homebridge.io/HAP-NodeJS/classes/accessory.html#removecontroller | Accessory.removeController}.\n *\n * @param controller\n */\n public removeController(controller: Controller): void {\n this._associatedHAPAccessory.removeController(controller)\n }\n\n // private\n static serialize(accessory: PlatformAccessory): SerializedPlatformAccessory {\n return {\n plugin: accessory._associatedPlugin!,\n platform: accessory._associatedPlatform!,\n context: accessory.context,\n ...Accessory.serialize(accessory._associatedHAPAccessory),\n }\n }\n\n static deserialize(json: SerializedPlatformAccessory): PlatformAccessory {\n const accessory = Accessory.deserialize(json)\n\n PlatformAccessory.injectedAccessory = accessory\n const platformAccessory = new PlatformAccessory(accessory.displayName, accessory.UUID)\n PlatformAccessory.injectedAccessory = undefined\n\n platformAccessory._associatedPlugin = json.plugin\n platformAccessory._associatedPlatform = json.platform\n platformAccessory.context = json.context\n platformAccessory.category = json.category\n\n return platformAccessory\n }\n}\n", "import type {\n AccessoryIdentifier,\n AccessoryName,\n AccessoryPluginConstructor,\n HomebridgeAPI,\n PlatformIdentifier,\n PlatformName,\n PlatformPluginConstructor,\n PluginIdentifier,\n PluginName,\n} from './api.js'\n\nimport { execSync } from 'node:child_process'\nimport fs from 'node:fs'\nimport { createRequire } from 'node:module'\nimport path from 'node:path'\nimport process from 'node:process'\n\nimport {\n InternalAPIEvent,\n} from './api.js'\nimport { Logger } from './logger.js'\nimport { Plugin } from './plugin.js'\n\nconst log = Logger.internal\nconst require = createRequire(import.meta.url)\nconst paths = require.resolve.paths('')\n\nexport interface PackageJSON { // incomplete type for package.json (just stuff we use here)\n name: string\n version: string\n keywords?: string[]\n\n // see https://nodejs.org/dist/latest-v14.x/docs/api/packages.html#packages_package_entry_points\n exports?: string | Record<string, string | Record<string, string>>\n main?: string\n\n /**\n * When set as module, it marks .js file to be treated as ESM.\n * See https://nodejs.org/dist/latest-v14.x/docs/api/esm.html#esm_enabling\n */\n type?: 'module' | 'commonjs'\n\n engines?: Record<string, string>\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n peerDependencies?: Record<string, string>\n}\n\nexport interface PluginManagerOptions {\n /**\n * Additional path to search for plugins in. Specified relative to the current working directory.\n */\n customPluginPath?: string\n /**\n * If set, only load plugins from the customPluginPath, if set, otherwise only from the primary global node_modules.\n */\n strictPluginResolution?: boolean\n /**\n * When defined, only plugins specified here will be initialized.\n */\n activePlugins?: PluginIdentifier[]\n /**\n * Plugins that are marked as disabled and whose corresponding config blocks should be ignored\n */\n disabledPlugins?: PluginIdentifier[]\n}\n\n/**\n * Utility which exposes methods to search for installed Homebridge plugins\n */\nexport class PluginManager {\n // name must be prefixed with 'homebridge-' or '@scope/homebridge-'\n private static readonly PLUGIN_IDENTIFIER_PATTERN = /^((@[\\w-]*)\\/)?(homebridge-[\\w-]*)$/\n\n private readonly api: HomebridgeAPI\n\n private readonly searchPaths: Set<string> = new Set() // unique set of search paths we will use to discover installed plugins\n private readonly strictPluginResolution: boolean = false\n private readonly activePlugins?: PluginIdentifier[]\n private readonly disabledPlugins?: PluginIdentifier[]\n\n private readonly plugins: Map<PluginIdentifier, Plugin> = new Map()\n // we have some plugins which simply pass a wrong or misspelled plugin name to the api calls, this translation tries to mitigate this\n private readonly pluginIdentifierTranslation: Map<PluginIdentifier, PluginIdentifier> = new Map()\n private readonly accessoryToPluginMap: Map<AccessoryName, Plugin[]> = new Map()\n private readonly platformToPluginMap: Map<PlatformName, Plugin[]> = new Map()\n\n private currentInitializingPlugin?: Plugin // used to match registering plugins, see handleRegisterAccessory and handleRegisterPlatform\n\n constructor(api: HomebridgeAPI, options?: PluginManagerOptions) {\n this.api = api\n\n if (options) {\n if (options.customPluginPath) {\n this.searchPaths.add(path.resolve(process.cwd(), options.customPluginPath))\n }\n\n this.strictPluginResolution = options.strictPluginResolution || false\n\n this.activePlugins = options.activePlugins\n this.disabledPlugins = Array.isArray(options.disabledPlugins) ? options.disabledPlugins : undefined\n }\n\n this.api.on(InternalAPIEvent.REGISTER_ACCESSORY, this.handleRegisterAccessory.bind(this))\n this.api.on(InternalAPIEvent.REGISTER_PLATFORM, this.handleRegisterPlatform.bind(this))\n }\n\n public static isQualifiedPluginIdentifier(identifier: string): boolean {\n return PluginManager.PLUGIN_IDENTIFIER_PATTERN.test(identifier)\n }\n\n public static extractPluginName(name: string): PluginName { // extract plugin name without @scope/ prefix\n return name.match(PluginManager.PLUGIN_IDENTIFIER_PATTERN)![3]\n }\n\n public static extractPluginScope(name: string): string { // extract the \"@scope\" of a npm module name\n return name.match(PluginManager.PLUGIN_IDENTIFIER_PATTERN)![2]\n }\n\n public static getAccessoryName(identifier: AccessoryIdentifier): AccessoryName {\n if (!identifier.includes('.')) {\n return identifier\n }\n\n return identifier.split('.')[1]\n }\n\n public static getPlatformName(identifier: PlatformIdentifier): PlatformIdentifier {\n if (!identifier.includes('.')) {\n return identifier\n }\n\n return identifier.split('.')[1]\n }\n\n public static getPluginIdentifier(identifier: AccessoryIdentifier | PlatformIdentifier): PluginIdentifier {\n return identifier.split('.')[0]\n }\n\n public async initializeInstalledPlugins(): Promise<void> {\n log.info('---')\n\n this.loadInstalledPlugins()\n\n for (const [identifier, plugin] of this.plugins) {\n try {\n await plugin.load()\n } catch (error: any) {\n log.error('====================')\n log.error(`ERROR LOADING PLUGIN ${identifier}:`)\n log.error(error.stack)\n log.error('====================')\n\n this.plugins.delete(identifier)\n continue\n }\n\n if (this.disabledPlugins && this.disabledPlugins.includes(plugin.getPluginIdentifier())) {\n plugin.disabled = true\n }\n\n if (plugin.disabled) {\n log.warn(`Disabled plugin: ${identifier}@${plugin.version}`)\n } else {\n log.info(`Loaded plugin: ${identifier}@${plugin.version}`)\n }\n\n await this.initializePlugin(plugin, identifier)\n\n log.info('---')\n }\n\n this.currentInitializingPlugin = undefined\n }\n\n public async initializePlugin(plugin: Plugin, identifier: string): Promise<void> {\n try {\n this.currentInitializingPlugin = plugin\n await plugin.initialize(this.api) // call the plugin's initializer and pass it our API instance\n } catch (error: any) {\n log.error('====================')\n log.error(`ERROR INITIALIZING PLUGIN ${identifier}:`)\n log.error(error.stack)\n log.error('====================')\n\n this.plugins.delete(identifier)\n }\n }\n\n private handleRegisterAccessory(name: AccessoryName, constructor: AccessoryPluginConstructor, pluginIdentifier?: PluginIdentifier): void {\n if (!this.currentInitializingPlugin) {\n throw new Error(`Unexpected accessory registration. Plugin ${pluginIdentifier ? `'${pluginIdentifier}' ` : ''}tried to register outside the initializer function!`)\n }\n\n if (pluginIdentifier && pluginIdentifier !== this.currentInitializingPlugin.getPluginIdentifier()) {\n log.info(`Plugin '${this.currentInitializingPlugin.getPluginIdentifier()}' tried to register with an incorrect plugin identifier: '${pluginIdentifier}'. Please report this to the developer!`)\n this.pluginIdentifierTranslation.set(pluginIdentifier, this.currentInitializingPlugin.getPluginIdentifier())\n }\n\n this.currentInitializingPlugin.registerAccessory(name, constructor)\n\n let plugins = this.accessoryToPluginMap.get(name)\n if (!plugins) {\n plugins = []\n this.accessoryToPluginMap.set(name, plugins)\n }\n plugins.push(this.currentInitializingPlugin)\n }\n\n private handleRegisterPlatform(name: PlatformName, constructor: PlatformPluginConstructor, pluginIdentifier?: PluginIdentifier): void {\n if (!this.currentInitializingPlugin) {\n throw new Error(`Unexpected platform registration. Plugin ${pluginIdentifier ? `'${pluginIdentifier}' ` : ''}tried to register outside the initializer function!`)\n }\n\n if (pluginIdentifier && pluginIdentifier !== this.currentInitializingPlugin.getPluginIdentifier()) {\n log.debug(`Plugin '${this.currentInitializingPlugin.getPluginIdentifier()}' tried to register with an incorrect plugin identifier: '${pluginIdentifier}'. Please report this to the developer!`)\n this.pluginIdentifierTranslation.set(pluginIdentifier, this.currentInitializingPlugin.getPluginIdentifier())\n }\n\n this.currentInitializingPlugin.registerPlatform(name, constructor)\n\n let plugins = this.platformToPluginMap.get(name)\n if (!plugins) {\n plugins = []\n this.platformToPluginMap.set(name, plugins)\n }\n plugins.push(this.currentInitializingPlugin)\n }\n\n public getPluginForAccessory(accessoryIdentifier: AccessoryIdentifier | AccessoryName): Plugin {\n let plugin: Plugin\n if (!accessoryIdentifier.includes('.')) { // see if it matches exactly one accessory\n let found = this.accessoryToPluginMap.get(accessoryIdentifier)\n\n if (!found) {\n throw new Error(`No plugin was found for the accessory \"${accessoryIdentifier}\" in your config.json. Please make sure the corresponding plugin is installed correctly.`)\n }\n\n if (found.length > 1) {\n const options = found.map(plugin => `${plugin.getPluginIdentifier()}.${accessoryIdentifier}`).join(', ')\n // check if only one of the multiple platforms is not disabled\n found = found.filter(plugin => !plugin.disabled)\n if (found.length !== 1) {\n throw new Error(`The requested accessory '${accessoryIdentifier}' has been registered multiple times. Please be more specific by writing one of: ${options}`)\n }\n }\n\n plugin = found[0]\n accessoryIdentifier = `${plugin.getPluginIdentifier()}.${accessoryIdentifier}`\n } else {\n const pluginIdentifier = PluginManager.getPluginIdentifier(accessoryIdentifier)\n if (!this.hasPluginRegistered(pluginIdentifier)) {\n throw new Error(`The requested plugin '${pluginIdentifier}' was not registered.`)\n }\n\n plugin = this.getPlugin(pluginIdentifier)!\n }\n\n return plugin\n }\n\n public getPluginForPlatform(platformIdentifier: PlatformIdentifier | PlatformName): Plugin {\n let plugin: Plugin\n if (!platformIdentifier.includes('.')) { // see if it matches exactly one platform\n let found = this.platformToPluginMap.get(platformIdentifier)\n\n if (!found) {\n throw new Error(`No plugin was found for the platform \"${platformIdentifier}\" in your config.json. Please make sure the corresponding plugin is installed correctly.`)\n }\n\n if (found.length > 1) {\n const options = found.map(plugin => `${plugin.getPluginIdentifier()}.${platformIdentifier}`).join(', ')\n // check if only one of the multiple platforms is not disabled\n found = found.filter(plugin => !plugin.disabled)\n if (found.length !== 1) {\n throw new Error(`The requested platform '${platformIdentifier}' has been registered multiple times. Please be more specific by writing one of: ${options}`)\n }\n }\n\n plugin = found[0]\n platformIdentifier = `${plugin.getPluginIdentifier()}.${platformIdentifier}`\n } else {\n const pluginIdentifier = PluginManager.getPluginIdentifier(platformIdentifier)\n if (!this.hasPluginRegistered(pluginIdentifier)) {\n throw new Error(`The requested plugin '${pluginIdentifier}' was not registered.`)\n }\n\n plugin = this.getPlugin(pluginIdentifier)!\n }\n\n return plugin\n }\n\n public hasPluginRegistered(pluginIdentifier: PluginIdentifier): boolean {\n return this.plugins.has(pluginIdentifier) || this.pluginIdentifierTranslation.has(pluginIdentifier)\n }\n\n public getPlugin(pluginIdentifier: PluginIdentifier): Plugin | undefined {\n const plugin = this.plugins.get(pluginIdentifier)\n if (plugin) {\n return plugin\n } else {\n const translation = this.pluginIdentifierTranslation.get(pluginIdentifier)\n if (translation) {\n return this.plugins.get(translation)\n }\n }\n\n return undefined\n }\n\n public getPluginByActiveDynamicPlatform(platformName: PlatformName): Plugin | undefined {\n const found = (this.platformToPluginMap.get(platformName) || [])\n .filter(plugin => !!plugin.getActiveDynamicPlatform(platformName))\n\n if (found.length === 0) {\n return undefined\n } else if (found.length > 1) {\n const plugins = found.map(plugin => plugin.getPluginIdentifier()).join(', ')\n throw new Error(`'${platformName}' is an ambiguous platform name. It was registered by multiple plugins: ${plugins}`)\n } else {\n return found[0]\n }\n }\n\n /**\n * Gets all plugins installed on the local system\n */\n private loadInstalledPlugins(): void {\n this.loadDefaultPaths()\n\n this.searchPaths.forEach((searchPath) => { // search for plugins among all known paths\n if (!fs.existsSync(searchPath)) { // just because this path is in require.main.paths doesn't mean it necessarily exists!\n return\n }\n\n if (fs.existsSync(path.join(searchPath, 'package.json'))) { // does this path point inside a single plugin and not a directory containing plugins?\n try {\n this.loadPlugin(searchPath)\n } catch (error: any) {\n log.warn(error.message)\n }\n } else { // read through each directory in this node_modules folder\n const relativePluginPaths = fs.readdirSync(searchPath) // search for directories only\n .filter((relativePath) => {\n try {\n return fs.statSync(path.resolve(searchPath, relativePath)).isDirectory()\n } catch (error: any) {\n log.debug(`Ignoring path ${path.resolve(searchPath, relativePath)} - ${error.message}`)\n return false\n }\n })\n\n // expand out @scoped plugins\n relativePluginPaths.slice()\n .filter(path => path.charAt(0) === '@') // is it a scope directory?\n .forEach((scopeDirectory) => {\n // remove scopeDirectory from the path list\n const index = relativePluginPaths.indexOf(scopeDirectory)\n relativePluginPaths.splice(index, 1)\n\n const absolutePath = path.join(searchPath, scopeDirectory)\n fs.readdirSync(absolutePath)\n .filter(name => PluginManager.isQualifiedPluginIdentifier(name))\n .filter((name) => {\n try {\n return fs.statSync(path.resolve(absolutePath, name)).isDirectory()\n } catch (error: any) {\n log.debug(`Ignoring path ${path.resolve(absolutePath, name)} - ${error.message}`)\n return false\n }\n })\n .forEach(name => relativePluginPaths.push(`${scopeDirectory}/${name}`))\n })\n\n relativePluginPaths\n .filter((pluginIdentifier) => {\n return PluginManager.isQualifiedPluginIdentifier(pluginIdentifier) // needs to be a valid homebridge plugin name\n && (!this.activePlugins || this.activePlugins.includes(pluginIdentifier)) // check if activePlugins is restricted and if so is the plugin is contained\n })\n .forEach((pluginIdentifier) => {\n try {\n const absolutePath = path.resolve(searchPath, pluginIdentifier)\n this.loadPlugin(absolutePath)\n } catch (error: any) {\n log.warn(error.message)\n }\n })\n }\n })\n\n if (this.plugins.size === 0) {\n log.warn('No plugins found.')\n }\n }\n\n public loadPlugin(absolutePath: string): Plugin {\n const packageJson: PackageJSON = PluginManager.loadPackageJSON(absolutePath)\n\n const identifier: PluginIdentifier = packageJson.name\n const name: PluginName = PluginManager.extractPluginName(identifier)\n const scope = PluginManager.extractPluginScope(identifier) // possibly undefined\n\n const alreadyInstalled = this.plugins.get(identifier) // check if there is already a plugin with the same Identifier\n if (alreadyInstalled) {\n throw new Error(`Warning: skipping plugin found at '${absolutePath}' since we already loaded the same plugin from '${alreadyInstalled.getPluginPath()}'.`)\n }\n\n const plugin = new Plugin(name, absolutePath, packageJson, scope)\n this.plugins.set(identifier, plugin)\n return plugin\n }\n\n private static loadPackageJSON(pluginPath: string): PackageJSON {\n const packageJsonPath = path.join(pluginPath, 'package.json')\n let packageJson: PackageJSON\n\n if (!fs.existsSync(packageJsonPath)) {\n throw new Error(`Plugin ${pluginPath} does not contain a package.json.`)\n }\n\n try {\n packageJson = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf8' })) // attempt to parse package.json\n } catch (error: any) {\n throw new Error(`Plugin ${pluginPath} contains an invalid package.json. Error: ${error}`)\n }\n\n if (!packageJson.name || !PluginManager.isQualifiedPluginIdentifier(packageJson.name)) {\n throw new Error(`Plugin ${pluginPath} does not have a package name that begins with 'homebridge-' or '@scope/homebridge-.`)\n }\n\n // verify that it's tagged with the correct keyword\n if (!packageJson.keywords || !packageJson.keywords.includes('homebridge-plugin')) {\n throw new Error(`Plugin ${pluginPath} package.json does not contain the keyword 'homebridge-plugin'.`)\n }\n\n return packageJson\n }\n\n private loadDefaultPaths(): void {\n if (this.strictPluginResolution) {\n // if strict plugin resolution is enabled:\n // * only use custom plugin path, if set;\n // * otherwise add the current npm global prefix (e.g. /usr/local/lib/node_modules)\n if (this.searchPaths.size === 0) {\n this.addNpmPrefixToSearchPaths()\n }\n return\n }\n\n if (paths) {\n // add the paths used by require()\n paths.forEach(path => this.searchPaths.add(path))\n }\n\n // THIS SECTION FROM: https://github.com/yeoman/environment/blob/master/lib/resolver.js\n\n // Adding global npm directories\n // We tried using npm to get the global modules path, but it hasn't work out\n // because of bugs in the parsable implementation of `ls` command and mostly\n // performance issues. So, we go with our best bet for now.\n if (process.env.NODE_PATH) {\n process.env.NODE_PATH\n .split(path.delimiter)\n .filter(path => !!path) // trim out empty values\n .forEach(path => this.searchPaths.add(path))\n } else {\n // Default paths for non-windows systems\n if (process.platform !== 'win32') {\n this.searchPaths.add('/usr/local/lib/node_modules')\n this.searchPaths.add('/usr/lib/node_modules')\n }\n this.addNpmPrefixToSearchPaths()\n }\n }\n\n private addNpmPrefixToSearchPaths(): void {\n if (process.platform === 'win32') {\n this.searchPaths.add(path.join(process.env.APPDATA!, 'npm/node_modules'))\n } else {\n this.searchPaths.add(execSync('/bin/echo -n \"$(npm -g prefix)/lib/node_modules\"', {\n env: Object.assign({\n npm_config_loglevel: 'silent',\n npm_update_notifier: 'false',\n }, process.env),\n }).toString('utf8'))\n }\n }\n}\n", "import type {\n AccessoryIdentifier,\n AccessoryName,\n AccessoryPluginConstructor,\n API,\n DynamicPlatformPlugin,\n PlatformIdentifier,\n PlatformName,\n PlatformPluginConstructor,\n PluginIdentifier,\n PluginInitializer,\n PluginName,\n} from './api.js'\nimport type { PackageJSON } from './pluginManager.js'\n\nimport assert from 'node:assert'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { pathToFileURL } from 'node:url'\n\nimport { satisfies } from 'semver'\n\nimport { Logger } from './logger.js'\nimport { PluginManager } from './pluginManager.js'\nimport getVersion from './version.js'\n\nconst log = Logger.internal\n\n/**\n * Represents a loaded Homebridge plugin.\n */\nexport class Plugin {\n private readonly pluginName: PluginName\n private readonly scope?: string // npm package scope\n private readonly pluginPath: string // like \"/usr/local/lib/node_modules/homebridge-lockitron\"\n private readonly isESM: boolean\n\n public disabled = false // mark the plugin as disabled\n\n // ------------------ package.json content ------------------\n readonly version: string\n private readonly main: string\n private loadContext?: { // used to store data for a limited time until the load method is called, will be reset afterward\n engines?: Record<string, string>\n dependencies?: Record<string, string>\n }\n // ----------------------------------------------------------\n\n private pluginInitializer?: PluginInitializer // default exported function from the plugin that initializes it\n\n private readonly registeredAccessories: Map<AccessoryName, AccessoryPluginConstructor> = new Map()\n private readonly registeredPlatforms: Map<PlatformName, PlatformPluginConstructor> = new Map()\n\n private readonly activeDynamicPlatforms: Map<PlatformName, DynamicPlatformPlugin[]> = new Map()\n\n constructor(name: PluginName, path: string, packageJSON: PackageJSON, scope?: string) {\n this.pluginName = name\n this.scope = scope\n this.pluginPath = path\n\n this.version = packageJSON.version || '0.0.0'\n this.main = ''\n\n // figure out the main module\n // exports is available - https://nodejs.org/dist/latest-v14.x/docs/api/packages.html#packages_package_entry_points\n if (packageJSON.exports) {\n // main entrypoint - https://nodejs.org/dist/latest-v14.x/docs/api/packages.html#packages_main_entry_point_export\n if (typeof packageJSON.exports === 'string') {\n this.main = packageJSON.exports\n } else { // subpath export - https://nodejs.org/dist/latest-v14.x/docs/api/packages.html#packages_subpath_exports\n // conditional exports - https://nodejs.org/dist/latest-v14.x/docs/api/packages.html#packages_conditional_exports\n const exports = packageJSON.exports.import || packageJSON.exports.require || packageJSON.exports.node || packageJSON.exports.default || packageJSON.exports['.']\n\n // check if conditional export is nested\n if (typeof exports !== 'string') {\n if (exports.import) {\n this.main = exports.import\n } else {\n this.main = exports.require || exports.node || exports.default\n }\n } else {\n this.main = exports\n }\n }\n }\n\n // exports search was not successful, fallback to package.main, using index.js as fallback\n if (!this.main) {\n this.main = packageJSON.main || './index.js'\n }\n\n // check if it is an ESM module\n this.isESM = this.main.endsWith('.mjs') || (this.main.endsWith('.js') && packageJSON.type === 'module')\n\n // very temporary fix for first wave of plugins\n if (packageJSON.peerDependencies && (!packageJSON.engines || !packageJSON.engines.homebridge)) {\n packageJSON.engines = packageJSON.engines || {}\n packageJSON.engines.homebridge = packageJSON.peerDependencies.homebridge\n }\n\n this.loadContext = {\n engines: packageJSON.engines,\n dependencies: packageJSON.dependencies,\n }\n }\n\n public getPluginIdentifier(): PluginIdentifier { // return full plugin name with scope prefix\n return (this.scope ? `${this.scope}/` : '') + this.pluginName\n }\n\n public getPluginPath(): string {\n return this.pluginPath\n }\n\n public registerAccessory(name: AccessoryName, constructor: AccessoryPluginConstructor): void {\n if (this.registeredAccessories.has(name)) {\n throw new Error(`Plugin '${this.getPluginIdentifier()}' tried to register an accessory '${name}' which has already been registered!`)\n }\n\n if (!this.disabled) {\n log.info('Registering accessory \\'%s\\'', `${this.getPluginIdentifier()}.${name}`)\n }\n\n this.registeredAccessories.set(name, constructor)\n }\n\n public registerPlatform(name: PlatformName, constructor: PlatformPluginConstructor): void {\n if (this.registeredPlatforms.has(name)) {\n throw new Error(`Plugin '${this.getPluginIdentifier()}' tried to register a platform '${name}' which has already been registered!`)\n }\n\n if (!this.disabled) {\n log.info('Registering platform \\'%s\\'', `${this.getPluginIdentifier()}.${name}`)\n }\n\n this.registeredPlatforms.set(name, constructor)\n }\n\n public getAccessoryConstructor(accessoryIdentifier: AccessoryIdentifier | AccessoryName): AccessoryPluginConstructor {\n const name: AccessoryName = PluginManager.getAccessoryName(accessoryIdentifier)\n\n const constructor = this.registeredAccessories.get(name)\n if (!constructor) {\n throw new Error(`The requested accessory '${name}' was not registered by the plugin '${this.getPluginIdentifier()}'.`)\n }\n\n return constructor\n }\n\n public getPlatformConstructor(platformIdentifier: PlatformIdentifier | PlatformName): PlatformPluginConstructor {\n const name: PlatformName = PluginManager.getPlatformName(platformIdentifier)\n\n const constructor = this.registeredPlatforms.get(name)\n if (!constructor) {\n throw new Error(`The requested platform '${name}' was not registered by the plugin '${this.getPluginIdentifier()}'.`)\n }\n\n // If it's a dynamic platform plugin, ensure it's not enabled multiple times.\n if (this.activeDynamicPlatforms.has(name)) {\n throw new Error(`The dynamic platform ${name} from the plugin ${this.getPluginIdentifier()} is configured `\n + `times in your config.json.`)\n }\n\n return constructor\n }\n\n public assignDynamicPlatform(platformIdentifier: PlatformIdentifier | PlatformName, platformPlugin: DynamicPlatformPlugin): void {\n const name: PlatformName = PluginManager.getPlatformName(platformIdentifier)\n\n let platforms = this.activeDynamicPlatforms.get(name)\n if (!platforms) {\n platforms = []\n this.activeDynamicPlatforms.set(name, platforms)\n }\n\n // the last platform published should be at the first position for easy access\n // we just try to mimic pre 1.0.0 behavior\n platforms.unshift(platformPlugin)\n }\n\n public getActiveDynamicPlatform(platformName: PlatformName): DynamicPlatformPlugin | undefined {\n const platforms = this.activeDynamicPlatforms.get(platformName)\n // we always use the last registered\n return platforms && platforms[0]\n }\n\n public async load(): Promise<void> {\n const context = this.loadContext!\n assert(context, 'Reached illegal state. Plugin state is undefined!')\n this.loadContext = undefined // free up memory\n\n // pluck out the HomeBridge version requirement\n if (!context.engines || !context.engines.homebridge) {\n throw new Error(`Plugin ${this.pluginPath} does not contain the 'homebridge' package in 'engines'.`)\n }\n\n const versionRequired = context.engines.homebridge\n const nodeVersionRequired = context.engines.node\n\n // make sure the version is satisfied by the currently running version of HomeBridge\n if (!satisfies(getVersion(), versionRequired, { includePrerelease: true })) {\n // TODO - change this back to an error\n log.error(`The plugin \"${this.pluginName}\" requires a Homebridge version of ${versionRequired} which does \\\nnot satisfy the current Homebridge version of ${getVersion()}. You may need to update this plugin (or Homebridge) to a newer version. \\\nYou may face unexpected issues or stability problems running this plugin.`)\n }\n\n // make sure the version is satisfied by the currently running version of Node\n if (nodeVersionRequired && !satisfies(process.version, nodeVersionRequired)) {\n log.warn(`The plugin \"${this.pluginName}\" requires Node.js version of ${nodeVersionRequired} which does \\\nnot satisfy the current Node.js version of ${process.version}. You may need to upgrade your installation of Node.js - see https://homebridge.io/w/JTKEF`)\n }\n\n const dependencies = context.dependencies || {}\n if (dependencies.homebridge || dependencies['hap-nodejs']) {\n log.error(`The plugin \"${this.pluginName}\" defines 'homebridge' and/or 'hap-nodejs' in their 'dependencies' section, \\\nmeaning they carry an additional copy of homebridge and hap-nodejs. This not only wastes disk space, but also can cause \\\nmajor incompatibility issues and thus is considered bad practice. Please inform the developer to update their plugin!`)\n }\n\n const mainPath = path.join(this.pluginPath, this.main)\n\n // try to import it and grab the exported initialization hook\n // pathToFileURL(specifier).href to turn a path into a \"file url\"\n // see https://github.com/nodejs/node/issues/31710\n\n const pluginModules = await import(pathToFileURL(mainPath).href)\n\n if (typeof pluginModules === 'function') {\n this.pluginInitializer = pluginModules\n } else if (pluginModules && typeof pluginModules.default === 'function') {\n this.pluginInitializer = pluginModules.default\n } else {\n throw new Error(`Plugin ${this.pluginPath} does not export a initializer function from main.`)\n }\n }\n\n public initialize(api: API): void | Promise<void> {\n if (!this.pluginInitializer) {\n throw new Error('Tried to initialize a plugin which hasn\\'t been loaded yet!')\n }\n\n return this.pluginInitializer(api)\n }\n}\n", "import fs from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst __filename = fileURLToPath(import.meta.url)\nconst __dirname = dirname(__filename)\n\nfunction loadPackageJson(): any {\n const packageJSONPath = join(__dirname, '../package.json')\n return JSON.parse(fs.readFileSync(packageJSONPath, { encoding: 'utf8' }))\n}\n\nexport default function getVersion(): string {\n return loadPackageJson().version\n}\n\nexport function getRequiredNodeVersion(): string {\n return loadPackageJson().engines.node\n}\n", "import os from 'node:os'\nimport path from 'node:path'\n\n/**\n * Manages user settings and storage locations.\n */\nexport class User {\n private static customStoragePath?: string\n private static storageAccessed = false\n\n static configPath(): string {\n return path.join(User.storagePath(), 'config.json')\n }\n\n static persistPath(): string {\n return path.join(User.storagePath(), 'persist') // hap-nodejs data is stored here\n }\n\n static cachedAccessoryPath(): string {\n return path.join(User.storagePath(), 'accessories')\n }\n\n static storagePath(): string {\n User.storageAccessed = true\n\n return User.customStoragePath ? User.customStoragePath : path.join(os.homedir(), '.homebridge')\n }\n\n public static setStoragePath(...storagePathSegments: string[]): void {\n if (User.storageAccessed) {\n throw new Error('Storage path was already accessed and cannot be changed anymore. Try initializing your custom storage path earlier!')\n }\n\n User.customStoragePath = path.resolve(...storagePathSegments)\n }\n}\n", "import type {\n CharacteristicWarning,\n InterfaceName,\n IPAddress,\n MacAddress,\n MDNSAdvertiser,\n PublishInfo,\n VoidCallback,\n} from 'hap-nodejs'\n\nimport type {\n AccessoryIdentifier,\n AccessoryName,\n AccessoryPlugin,\n HomebridgeAPI,\n PlatformIdentifier,\n PlatformName,\n PluginIdentifier,\n StaticPlatformPlugin,\n} from './api.js'\nimport type { ExternalPortsConfiguration, ExternalPortService } from './externalPortService.js'\nimport type { Logging } from './logger.js'\nimport type { SerializedPlatformAccessory } from './platformAccessory.js'\nimport type { Plugin } from './plugin.js'\nimport type { HomebridgeOptions } from './server.js'\n\nimport {\n Accessory,\n AccessoryEventTypes,\n Bridge,\n Categories,\n Characteristic,\n CharacteristicEventTypes,\n CharacteristicWarningType,\n HAPLibraryVersion,\n once,\n Service,\n uuid,\n} from 'hap-nodejs'\n\nimport { InternalAPIEvent } from './api.js'\nimport { getLogPrefix, Logger } from './logger.js'\nimport { PlatformAccessory } from './platformAccessory.js'\nimport { PluginManager } from './pluginManager.js'\nimport { StorageService } from './storageService.js'\nimport { generate } from './util/mac.js'\nimport getVersion from './version.js'\n\nconst log = Logger.internal\n\nexport interface BridgeConfiguration {\n name: string\n username: MacAddress\n pin: string // format like \"000-00-000\"\n advertiser?: MDNSAdvertiser\n port?: number\n bind?: (InterfaceName | IPAddress) | (InterfaceName | IPAddress)[]\n setupID?: string[4]\n manufacturer?: string\n model?: string\n disableIpc?: boolean\n firmwareRevision?: string\n env?: {\n DEBUG?: string\n NODE_OPTIONS?: string\n }\n}\n\nexport interface AccessoryConfig extends Record<string, any> {\n accessory: AccessoryName | AccessoryIdentifier\n name: string\n uuid_base?: string\n _bridge?: BridgeConfiguration\n}\n\nexport interface PlatformConfig extends Record<string, any> {\n platform: PlatformName | PlatformIdentifier\n name?: string\n _bridge?: BridgeConfiguration\n}\n\nexport interface HomebridgeConfig {\n bridge: BridgeConfiguration\n\n accessories: AccessoryConfig[]\n platforms: PlatformConfig[]\n\n plugins?: PluginIdentifier[] // array to define set of active plugins\n\n /**\n * Array of disabled plugins.\n * Unlike the plugins[] config which prevents plugins from being initialised at all, disabled plugins still have their alias loaded, so\n * we can match config blocks of disabled plugins and show an appropriate message in the logs.\n */\n disabledPlugins?: PluginIdentifier[]\n\n // This section is used to control the range of ports (inclusive) that separate accessory (like camera or television) should be bind to\n ports?: ExternalPortsConfiguration\n}\n\nexport interface BridgeOptions extends HomebridgeOptions {\n cachedAccessoriesDir: string\n cachedAccessoriesItemName: string\n}\n\nexport interface CharacteristicWarningOpts {\n ignoreSlow?: boolean\n}\n\nexport class BridgeService {\n public bridge: Bridge\n private storageService: StorageService\n\n private readonly allowInsecureAccess: boolean\n\n private cachedPlatformAccessories: PlatformAccessory[] = []\n private cachedAccessoriesFileLoaded = false\n private readonly publishedExternalAccessories: Map<MacAddress, PlatformAccessory> = new Map()\n\n constructor(\n private api: HomebridgeAPI,\n private pluginManager: PluginManager,\n private externalPortService: ExternalPortService,\n private bridgeOptions: BridgeOptions,\n private bridgeConfig: BridgeConfiguration,\n private config: HomebridgeConfig,\n ) {\n this.storageService = new StorageService(this.bridgeOptions.cachedAccessoriesDir)\n this.storageService.initSync()\n\n // Server is \"secure by default\", meaning it creates a top-level Bridge accessory that\n // will not allow unauthenticated requests. This matches the behavior of actual HomeKit\n // accessories. However, you can set this to true to allow all requests without authentication,\n // which can be useful for easy hacking. Note that this will expose all functions of your\n // bridged accessories, like changing characteristics (i.e. flipping your lights on and off).\n this.allowInsecureAccess = this.bridgeOptions.insecureAccess || false\n\n this.api.on(InternalAPIEvent.REGISTER_PLATFORM_ACCESSORIES, this.handleRegisterPlatformAccessories.bind(this))\n this.api.on(InternalAPIEvent.UPDATE_PLATFORM_ACCESSORIES, this.handleUpdatePlatformAccessories.bind(this))\n this.api.on(InternalAPIEvent.UNREGISTER_PLATFORM_ACCESSORIES, this.handleUnregisterPlatformAccessories.bind(this))\n this.api.on(InternalAPIEvent.PUBLISH_EXTERNAL_ACCESSORIES, this.handlePublishExternalAccessories.bind(this))\n\n this.bridge = new Bridge(bridgeConfig.name, uuid.generate('HomeBridge'))\n this.bridge.on(AccessoryEventTypes.CHARACTERISTIC_WARNING, () => {\n // We register characteristic warning handlers on every bridged accessory (to have a reference to the plugin).\n // For Bridges the warnings will propagate to the main Bridge accessory, thus we need to silence them here.\n // Otherwise, those would be printed twice (by us and HAP-NodeJS as it detects no handlers on the bridge).\n })\n }\n\n // characteristic warning event has additional parameter originatorChain: string[] which is currently unused\n public static printCharacteristicWriteWarning(plugin: Plugin, accessory: Accessory, opts: CharacteristicWarningOpts, warning: CharacteristicWarning): void {\n const wikiInfo = 'See https://homebridge.io/w/JtMGR for more info.'\n switch (warning.type) {\n case CharacteristicWarningType.SLOW_READ:\n case CharacteristicWarningType.SLOW_WRITE:\n if (!opts.ignoreSlow) {\n log.info(getLogPrefix(plugin.getPluginIdentifier()), 'This plugin slows down Homebridge.', warning.message, wikiInfo)\n }\n break\n case CharacteristicWarningType.TIMEOUT_READ:\n case CharacteristicWarningType.TIMEOUT_WRITE:\n log.error(getLogPrefix(plugin.getPluginIdentifier()), 'This plugin slows down Homebridge.', warning.message, wikiInfo)\n break\n case CharacteristicWarningType.WARN_MESSAGE:\n log.info(getLogPrefix(plugin.getPluginIdentifier()), `This plugin generated a warning from the characteristic '${warning.characteristic.displayName}':`, `${warning.message}.`, wikiInfo)\n break\n case CharacteristicWarningType.ERROR_MESSAGE:\n log.error(getLogPrefix(plugin.getPluginIdentifier()), `This plugin threw an error from the characteristic '${warning.characteristic.displayName}':`, `${warning.message}.`, wikiInfo)\n break\n case CharacteristicWarningType.DEBUG_MESSAGE:\n log.debug(getLogPrefix(plugin.getPluginIdentifier()), `Characteristic '${warning.characteristic.displayName}':`, `${warning.message}.`, wikiInfo)\n break\n default: // generic message for yet unknown types\n log.info(getLogPrefix(plugin.getPluginIdentifier()), `This plugin generated a warning from the characteristic '${warning.characteristic.displayName}':`, `${warning.message}.`, wikiInfo)\n break\n }\n if (warning.stack) {\n log.debug(getLogPrefix(plugin.getPluginIdentifier()), warning.stack)\n }\n }\n\n public publishBridge(): void {\n const bridgeConfig = this.bridgeConfig\n\n const info = this.bridge.getService(Service.AccessoryInformation)!\n info.setCharacteristic(Characteristic.Manufacturer, bridgeConfig.manufacturer || 'homebridge.io')\n info.setCharacteristic(Characteristic.Model, bridgeConfig.model || 'homebridge')\n info.setCharacteristic(Characteristic.SerialNumber, bridgeConfig.username)\n info.setCharacteristic(Characteristic.FirmwareRevision, bridgeConfig.firmwareRevision || getVersion())\n\n this.bridge.on(AccessoryEventTypes.LISTENING, (port: number) => {\n log.success('Homebridge v%s (HAP v%s) (%s) is running on port %s.', getVersion(), HAPLibraryVersion(), bridgeConfig.name, port)\n })\n\n const publishInfo: PublishInfo = {\n username: bridgeConfig.username,\n port: bridgeConfig.port,\n pincode: bridgeConfig.pin,\n category: Categories.BRIDGE,\n bind: bridgeConfig.bind,\n addIdentifyingMaterial: true,\n advertiser: bridgeConfig.advertiser,\n }\n\n if (bridgeConfig.setupID && bridgeConfig.setupID.length === 4) {\n publishInfo.setupID = bridgeConfig.setupID\n }\n\n log.debug('Publishing bridge accessory (name: %s, publishInfo: %o).', this.bridge.displayName, BridgeService.strippingPinCode(publishInfo))\n this.bridge.publish(publishInfo, this.allowInsecureAccess)\n }\n\n /**\n * Attempt to load the cached accessories from disk.\n */\n public async loadCachedPlatformAccessoriesFromDisk(): Promise<void> {\n let cachedAccessories: SerializedPlatformAccessory[] | null = null\n\n try {\n cachedAccessories = await this.storageService.getItem<SerializedPlatformAccessory[]>(this.bridgeOptions.cachedAccessoriesItemName)\n } catch (error: any) {\n log.error('Failed to load cached accessories from disk:', error.message)\n if (error instanceof SyntaxError) {\n // syntax error probably means invalid json / corrupted file; try and restore from backup\n cachedAccessories = await this.restoreCachedAccessoriesBackup()\n } else {\n log.error('Not restoring cached accessories - some accessories may be reset.')\n }\n }\n\n if (cachedAccessories) {\n log.info(`Loaded ${cachedAccessories.length} cached accessories from ${this.bridgeOptions.cachedAccessoriesItemName}.`)\n\n this.cachedPlatformAccessories = cachedAccessories.map((serialized) => {\n return PlatformAccessory.deserialize(serialized)\n })\n\n if (cachedAccessories.length) {\n // create a backup of the cache file\n await this.createCachedAccessoriesBackup()\n }\n }\n\n this.cachedAccessoriesFileLoaded = true\n }\n\n /**\n * Return the name of the backup cache file\n */\n private get backupCacheFileName() {\n return `.${this.bridgeOptions.cachedAccessoriesItemName}.bak`\n }\n\n /**\n * Create a backup of the cached file\n * This is used if we ever have trouble reading the main cache file\n */\n private async createCachedAccessoriesBackup(): Promise<void> {\n try {\n await this.storageService.copyItem(this.bridgeOptions.cachedAccessoriesItemName, this.backupCacheFileName)\n } catch (error: any) {\n log.warn(`Failed to create a backup of the ${this.bridgeOptions.cachedAccessoriesItemName} cached accessories file:`, error.message)\n }\n }\n\n /**\n * Restore a cached accessories backup\n * This is used if the main cache file has a JSON syntax error / is corrupted\n */\n private async restoreCachedAccessoriesBackup(): Promise<SerializedPlatformAccessory[] | null> {\n try {\n const cachedAccessories = await this.storageService.getItem<SerializedPlatformAccessory[]>(this.backupCacheFileName)\n if (cachedAccessories && cachedAccessories.length) {\n log.warn(`Recovered ${cachedAccessories.length} accessories from ${this.bridgeOptions.cachedAccessoriesItemName} cache backup.`)\n }\n return cachedAccessories\n } catch (error: any) {\n return null\n }\n }\n\n public restoreCachedPlatformAccessories(): void {\n this.cachedPlatformAccessories = this.cachedPlatformAccessories.filter((accessory) => {\n let plugin = this.pluginManager.getPlugin(accessory._associatedPlugin!)\n if (!plugin) { // a little explainer here. This section is basically here to resolve plugin name changes of dynamic platform plugins\n try {\n // resolve platform accessories by searching for plugins which registered a dynamic platform for the given name\n plugin = this.pluginManager.getPluginByActiveDynamicPlatform(accessory._associatedPlatform!)\n\n if (plugin) { // if it's undefined the no plugin was found\n // could improve on this by calculating the Levenshtein distance to only allow platform ownership changes\n // when something like a typo happened. Are there other reasons the name could change?\n // And how would we define the threshold?\n\n log.info(`When searching for the associated plugin of the accessory '${accessory.displayName}' `\n + `it seems like the plugin name changed from '${accessory._associatedPlugin}' to '${\n plugin.getPluginIdentifier()}'. Plugin association is now being transformed!`)\n\n accessory._associatedPlugin = plugin.getPluginIdentifier() // update the associated plugin to the new one\n }\n } catch (error: any) { // error is thrown if multiple plugins where found for the given platform name\n log.info(`Could not find the associated plugin for the accessory '${accessory.displayName}'. `\n + `Tried to find the plugin by the platform name but ${error.message}`)\n }\n }\n\n const platformPlugins = plugin && plugin.getActiveDynamicPlatform(accessory._associatedPlatform!)\n if (plugin) {\n accessory._associatedHAPAccessory.on(AccessoryEventTypes.CHARACTERISTIC_WARNING, BridgeService.printCharacteristicWriteWarning.bind(this, plugin, accessory._associatedHAPAccessory, {}))\n }\n\n if (!platformPlugins) {\n log.info(`Failed to find plugin to handle accessory ${accessory._associatedHAPAccessory.displayName}`)\n if (!this.bridgeOptions.keepOrphanedCachedAccessories) {\n log.info(`Removing orphaned accessory ${accessory._associatedHAPAccessory.displayName}`)\n return false // filter it from the list\n }\n } else {\n // We set a placeholder for FirmwareRevision before configureAccessory is called so the plugin has the opportunity to override it.\n accessory.getService(Service.AccessoryInformation)?.setCharacteristic(Characteristic.FirmwareRevision, '0')\n platformPlugins.configureAccessory(accessory)\n }\n\n try {\n this.bridge.addBridgedAccessory(accessory._associatedHAPAccessory)\n } catch (error: any) {\n log.warn(`${accessory._associatedPlugin ? getLogPrefix(accessory._associatedPlugin) : ''} Could not restore cached accessory '${accessory._associatedHAPAccessory.displayName}':`, error.message)\n return false // filter it from the list\n }\n return true // keep it in the list\n })\n }\n\n /**\n * Save the cached accessories back to disk.\n */\n public saveCachedPlatformAccessoriesOnDisk(): void {\n try {\n // only save the cache file back to disk if we have already attempted to load it\n // this should prevent the cache being deleted should homebridge be shutdown before it has finished launching\n if (this.cachedAccessoriesFileLoaded) {\n const serializedAccessories = this.cachedPlatformAccessories.map(accessory => PlatformAccessory.serialize(accessory))\n this.storageService.setItemSync(this.bridgeOptions.cachedAccessoriesItemName, serializedAccessories)\n }\n } catch (error: any) {\n log.error('Failed to save cached accessories to disk:', error.message)\n log.error('Your accessories will not persist between restarts until this issue is resolved.')\n }\n }\n\n handleRegisterPlatformAccessories(accessories: PlatformAccessory[]): void {\n const hapAccessories = accessories.map((accessory) => {\n this.cachedPlatformAccessories.push(accessory)\n\n const plugin = this.pluginManager.getPlugin(accessory._associatedPlugin!)\n if (plugin) {\n const platforms = plugin.getActiveDynamicPlatform(accessory._associatedPlatform!)\n\n if (!platforms) {\n log.warn('The plugin \\'%s\\' registered a new accessory for the platform \\'%s\\'. The platform couldn\\'t be found though!', accessory._associatedPlugin!, accessory._associatedPlatform!)\n }\n\n accessory._associatedHAPAccessory.on(AccessoryEventTypes.CHARACTERISTIC_WARNING, BridgeService.printCharacteristicWriteWarning.bind(this, plugin, accessory._associatedHAPAccessory, {}))\n } else {\n log.warn('A platform configured a new accessory under the plugin name \\'%s\\'. However no loaded plugin could be found for the name!', accessory._associatedPlugin)\n }\n\n return accessory._associatedHAPAccessory\n })\n\n this.bridge.addBridgedAccessories(hapAccessories)\n this.saveCachedPlatformAccessoriesOnDisk()\n }\n\n handleUpdatePlatformAccessories(): void {\n // Update persisted accessories\n this.saveCachedPlatformAccessoriesOnDisk()\n }\n\n handleUnregisterPlatformAccessories(accessories: PlatformAccessory[]): void {\n const hapAccessories = accessories.map((accessory) => {\n const index = this.cachedPlatformAccessories.indexOf(accessory)\n if (index >= 0) {\n this.cachedPlatformAccessories.splice(index, 1)\n }\n\n return accessory._associatedHAPAccessory\n })\n\n this.bridge.removeBridgedAccessories(hapAccessories)\n this.saveCachedPlatformAccessoriesOnDisk()\n }\n\n async handlePublishExternalAccessories(accessories: PlatformAccessory[]): Promise<void> {\n const accessoryPin = this.bridgeConfig.pin\n\n for (const accessory of accessories) {\n const hapAccessory = accessory._associatedHAPAccessory\n const advertiseAddress = generate(hapAccessory.UUID)\n\n // get external port allocation\n const accessoryPort = await this.externalPortService.requestPort(advertiseAddress)\n\n if (this.publishedExternalAccessories.has(advertiseAddress)) {\n throw new Error(`Accessory ${hapAccessory.displayName} experienced an address collision.`)\n } else {\n this.publishedExternalAccessories.set(advertiseAddress, accessory)\n }\n\n const plugin = this.pluginManager.getPlugin(accessory._associatedPlugin!)\n if (plugin) {\n hapAccessory.on(AccessoryEventTypes.CHARACTERISTIC_WARNING, BridgeService.printCharacteristicWriteWarning.bind(this, plugin, hapAccessory, { ignoreSlow: true }))\n } else if (PluginManager.isQualifiedPluginIdentifier(accessory._associatedPlugin!)) {\n // we did already complain in api.ts if it wasn't a qualified name\n log.warn('A platform configured a external accessory under the plugin name \\'%s\\'. However no loaded plugin could be found for the name!', accessory._associatedPlugin)\n }\n\n hapAccessory.on(AccessoryEventTypes.LISTENING, (port: number) => {\n log.success('%s is running on port %s.', hapAccessory.displayName, port)\n log.info('Please add [%s] manually in Home app. Setup Code: %s', hapAccessory.displayName, accessoryPin)\n })\n\n const publishInfo: PublishInfo = {\n username: advertiseAddress,\n pincode: accessoryPin,\n category: accessory.category,\n port: accessoryPort,\n bind: this.bridgeConfig.bind,\n addIdentifyingMaterial: true,\n advertiser: this.bridgeConfig.advertiser,\n }\n\n log.debug('Publishing external accessory (name: %s, publishInfo: %o).', hapAccessory.displayName, BridgeService.strippingPinCode(publishInfo))\n hapAccessory.publish(publishInfo, this.allowInsecureAccess)\n }\n }\n\n public createHAPAccessory(plugin: Plugin, accessoryInstance: AccessoryPlugin, displayName: string, accessoryType: AccessoryName | AccessoryIdentifier, uuidBase?: string): Accessory | undefined {\n const services = (accessoryInstance.getServices() || [])\n .filter(service => !!service) // filter out undefined values; a common mistake\n const controllers = ((accessoryInstance.getControllers && accessoryInstance.getControllers()) || [])\n .filter(controller => !!controller)\n\n if (services.length === 0 && controllers.length === 0) { // check that we only add valid accessory with at least one service\n return undefined\n }\n\n // The returned \"services\" for this accessory are simply an array of new-API-style\n // Service instances which we can add to a created HAP-NodeJS Accessory directly.\n const accessoryUUID = uuid.generate(`${accessoryType}:${uuidBase || displayName}`)\n const accessory = new Accessory(displayName, accessoryUUID)\n\n // listen for the identify event if the accessory instance has defined an identify() method\n if (accessoryInstance.identify) {\n accessory.on(AccessoryEventTypes.IDENTIFY, (paired: boolean, callback: VoidCallback) => {\n // @ts-expect-error: empty callback for backwards compatibility\n accessoryInstance.identify!(() => {})\n callback()\n })\n }\n\n const informationService = accessory.getService(Service.AccessoryInformation)!\n services.forEach((service) => {\n // if you returned an AccessoryInformation service, merge its values with ours\n if (service instanceof Service.AccessoryInformation) {\n service.setCharacteristic(Characteristic.Name, displayName) // ensure display name is set\n // ensure the plugin has not hooked already some listeners (some weird ones do).\n // Otherwise, they would override our identify listener registered by the HAP-NodeJS accessory\n service.getCharacteristic(Characteristic.Identify).removeAllListeners(CharacteristicEventTypes.SET)\n\n // pull out any values and listeners (get and set) you may have defined\n informationService.replaceCharacteristicsFromService(service)\n } else {\n accessory.addService(service)\n }\n })\n\n accessory.on(AccessoryEventTypes.CHARACTERISTIC_WARNING, BridgeService.printCharacteristicWriteWarning.bind(this, plugin, accessory, {}))\n\n controllers.forEach((controller) => {\n accessory.configureController(controller)\n })\n\n return accessory\n }\n\n public async loadPlatformAccessories(plugin: Plugin, platformInstance: StaticPlatformPlugin, platformType: PlatformName | PlatformIdentifier, logger: Logging): Promise<void> {\n // Plugin 1.0, load accessories\n return new Promise((resolve) => {\n // warn the user if the static platform is blocking the startup of Homebridge for to long\n const loadDelayWarningInterval = setInterval(() => {\n log.warn(getLogPrefix(plugin.getPluginIdentifier()), 'This plugin is taking long time to load and preventing Homebridge from starting. See https://homebridge.io/w/JtMGR for more info.')\n }, 20000)\n\n platformInstance.accessories(once((accessories: AccessoryPlugin[]) => {\n // clear the load delay warning interval\n clearInterval(loadDelayWarningInterval)\n\n // loop through accessories adding them to the list and registering them\n accessories.forEach((accessoryInstance, index) => {\n // @ts-expect-error: assume this property was set\n const accessoryName = accessoryInstance.name\n\n // @ts-expect-error: optional base uuid\n const uuidBase: string | undefined = accessoryInstance.uuid_base\n\n log.info('Initializing platform accessory \\'%s\\'...', accessoryName)\n\n const accessory = this.createHAPAccessory(plugin, accessoryInstance, accessoryName, platformType, uuidBase)\n\n if (accessory) {\n this.bridge.addBridgedAccessory(accessory)\n } else {\n logger('Platform %s returned an accessory at index %d with an empty set of services. Won\\'t adding it to the bridge!', platformType, index)\n }\n })\n\n resolve()\n }))\n })\n }\n\n teardown(): void {\n this.bridge.unpublish()\n for (const accessory of this.publishedExternalAccessories.values()) {\n accessory._associatedHAPAccessory.unpublish()\n }\n\n this.saveCachedPlatformAccessoriesOnDisk()\n\n this.api.signalShutdown()\n }\n\n private static strippingPinCode(publishInfo: PublishInfo): PublishInfo {\n const info = {\n ...publishInfo,\n }\n info.pincode = '***-**-***'\n return info\n }\n}\n", "import path from 'node:path'\n\nimport fs from 'fs-extra'\n\nexport class StorageService {\n constructor(\n public baseDirectory: string,\n ) {}\n\n public initSync(): void {\n return fs.ensureDirSync(this.baseDirectory)\n }\n\n public getItemSync<T>(itemName: string): T | null {\n const filePath = path.resolve(this.baseDirectory, itemName)\n\n if (!fs.pathExistsSync(filePath)) {\n return null\n }\n\n return fs.readJsonSync(filePath)\n }\n\n public async getItem<T>(itemName: string): Promise<T | null> {\n const filePath = path.resolve(this.baseDirectory, itemName)\n\n if (!await fs.pathExists(filePath)) {\n return null\n }\n\n return await fs.readJson(filePath)\n }\n\n public setItemSync(itemName: string, data: Record<any, any> | Array<any>): void {\n return fs.writeJsonSync(path.resolve(this.baseDirectory, itemName), data)\n }\n\n public setItem(itemName: string, data: Record<any, any> | Array<any>): Promise<void> {\n return fs.writeJson(path.resolve(this.baseDirectory, itemName), data)\n }\n\n public copyItem(srcItemName: string, destItemName: string): Promise<void> {\n return fs.copyFile(path.resolve(this.baseDirectory, srcItemName), path.resolve(this.baseDirectory, destItemName))\n }\n\n public copyItemSync(srcItemName: string, destItemName: string): void {\n return fs.copyFileSync(path.resolve(this.baseDirectory, srcItemName), path.resolve(this.baseDirectory, destItemName))\n }\n\n public removeItemSync(itemName: string): void {\n return fs.removeSync(path.resolve(this.baseDirectory, itemName))\n }\n}\n", "/* global NodeJS */\n\nimport type { Buffer } from 'node:buffer'\n\nimport crypto from 'node:crypto'\n\nconst validMac = /^(?:[0-9A-F]{2}:){5}[0-9A-F]{2}$/\n\nexport type MacAddress = string\n\nexport function validMacAddress(address: string): boolean {\n return validMac.test(address)\n}\n\nexport function generate(data: string | Buffer | NodeJS.TypedArray | DataView): MacAddress {\n const sha1sum = crypto.createHash('sha1')\n sha1sum.update(data)\n const s = sha1sum.digest('hex')\n\n let i = 0\n return 'xx:xx:xx:xx:xx:xx'.replace(/x/g, () => s[i++]).toUpperCase()\n}\n", "import type { MacAddress } from 'hap-nodejs'\n\nimport type { HomebridgeAPI } from './api.js'\nimport type {\n AccessoryConfig,\n BridgeConfiguration,\n BridgeOptions,\n HomebridgeConfig,\n PlatformConfig,\n} from './bridgeService.js'\nimport type { ExternalPortService } from './externalPortService.js'\nimport type { IpcService } from './ipcService.js'\nimport type { Logging } from './logger.js'\nimport type { Plugin } from './plugin.js'\nimport type { HomebridgeOptions } from './server.js'\n\nimport child_process from 'node:child_process'\nimport path, { dirname } from 'node:path'\nimport process from 'node:process'\nimport { fileURLToPath } from 'node:url'\n\nimport fs from 'fs-extra'\n\nimport { PluginType } from './api.js'\nimport { IpcOutgoingEvent } from './ipcService.js'\nimport { Logger } from './logger.js'\nimport { User } from './user.js'\n\nconst __filename = fileURLToPath(import.meta.url)\nconst __dirname = dirname(__filename)\n\n// eslint-disable-next-line no-restricted-syntax\nexport const enum ChildProcessMessageEventType {\n /**\n * Sent from the child process when it is ready to accept config\n */\n READY = 'ready',\n\n /**\n * Sent to the child process with a ChildProcessLoadEventData payload\n */\n LOAD = 'load',\n\n /**\n * Sent from the child process once it has loaded the plugin\n */\n LOADED = 'loaded',\n\n /**\n * Sent to the child process telling it to start\n */\n START = 'start',\n\n /**\n * Sent from the child process when the bridge is online\n */\n ONLINE = 'online',\n\n /**\n * Sent from the child when it wants to request port allocation for an external accessory\n */\n PORT_REQUEST = 'portRequest',\n\n /**\n * Sent from the parent with the port allocation response\n */\n PORT_ALLOCATED = 'portAllocated',\n\n /**\n * Sent from the child to update its current status\n */\n STATUS_UPDATE = 'status',\n}\n\n// eslint-disable-next-line no-restricted-syntax\nexport const enum ChildBridgeStatus {\n /**\n * When the child bridge is loading, or restarting\n */\n PENDING = 'pending',\n\n /**\n * The child bridge is online and has published it's accessory\n */\n OK = 'ok',\n\n /**\n * The bridge is shutting down, or the process ended unexpectedly\n */\n DOWN = 'down',\n}\n\nexport interface ChildProcessMessageEvent<T> {\n id: ChildProcessMessageEventType\n data?: T\n}\n\nexport interface ChildProcessLoadEventData {\n type: PluginType\n identifier: string\n pluginPath: string\n pluginConfig: Array<PlatformConfig | AccessoryConfig>\n bridgeConfig: BridgeConfiguration\n homebridgeConfig: HomebridgeConfig\n bridgeOptions: BridgeOptions\n}\n\nexport interface ChildProcessPluginLoadedEventData {\n version: string\n}\n\nexport interface ChildProcessPortRequestEventData {\n username: MacAddress\n}\n\nexport interface ChildProcessPortAllocatedEventData {\n username: MacAddress\n port?: number\n}\n\nexport interface ChildBridgePairedStatusEventData {\n paired: boolean | null\n setupUri: string | null\n}\n\nexport interface ChildMetadata {\n status: ChildBridgeStatus\n paired?: boolean | null\n setupUri?: string | null\n username: MacAddress\n pin: string\n name: string\n plugin: string\n identifier: string\n manuallyStopped: boolean\n pid?: number\n}\n\n/**\n * Manages the child processes of platforms/accessories being exposed as separate forked bridges.\n * A child bridge runs a single platform or accessory.\n */\nexport class ChildBridgeService {\n private child?: child_process.ChildProcess\n private args: string[] = []\n private processEnv: child_process.ForkOptions = {}\n private shuttingDown = false\n private lastBridgeStatus: ChildBridgeStatus = ChildBridgeStatus.PENDING\n private pairedStatus: boolean | null = null\n private manuallyStopped = false\n private setupUri: string | null = null\n private pluginConfig: Array<PlatformConfig | AccessoryConfig> = []\n private log: Logging\n private displayName?: string\n\n constructor(\n public type: PluginType,\n public identifier: string,\n private plugin: Plugin,\n private bridgeConfig: BridgeConfiguration,\n private homebridgeConfig: HomebridgeConfig,\n private homebridgeOptions: HomebridgeOptions,\n private api: HomebridgeAPI,\n private ipcService: IpcService,\n private externalPortService: ExternalPortService,\n ) {\n this.log = Logger.withPrefix(this.plugin.getPluginIdentifier())\n this.api.on('shutdown', () => {\n this.shuttingDown = true\n this.teardown()\n })\n\n // make sure we don't hit the max listeners limit\n this.api.setMaxListeners(this.api.getMaxListeners() + 1)\n }\n\n /**\n * Start the child bridge service\n */\n public start(): void {\n this.setProcessFlags()\n this.setProcessEnv()\n this.startChildProcess()\n\n // set display name\n if (this.pluginConfig.length > 1 || this.pluginConfig.length === 0) {\n this.displayName = this.plugin.getPluginIdentifier()\n } else {\n this.displayName = this.pluginConfig[0]?.name || this.plugin.getPluginIdentifier()\n }\n\n // re-configured log with display name\n this.log = Logger.withPrefix(this.displayName)\n }\n\n /**\n * Add a config block to a child bridge.\n * Platform child bridges can only contain one config block.\n * @param config\n */\n public addConfig(config: PlatformConfig | AccessoryConfig): void {\n this.pluginConfig.push(config)\n }\n\n private get bridgeStatus(): ChildBridgeStatus {\n return this.lastBridgeStatus\n }\n\n private set bridgeStatus(value: ChildBridgeStatus) {\n this.lastBridgeStatus = value\n this.sendStatusUpdate()\n }\n\n /**\n * Start the child bridge process\n */\n private startChildProcess(): void {\n this.bridgeStatus = ChildBridgeStatus.PENDING\n\n this.child = child_process.fork(path.resolve(__dirname, 'childBridgeFork.js'), this.args, this.processEnv)\n\n this.child.stdout?.on('data', (data) => {\n process.stdout.write(data)\n })\n\n this.child.stderr?.on('data', (data) => {\n process.stderr.write(data)\n })\n\n this.child.on('exit', () => {\n this.log.warn('Child bridge process ended')\n })\n\n this.child.on('error', (e) => {\n this.bridgeStatus = ChildBridgeStatus.DOWN\n this.log.error('Child process error', e)\n })\n\n this.child.once('close', (code, signal) => {\n this.bridgeStatus = ChildBridgeStatus.DOWN\n this.handleProcessClose(code, signal)\n })\n\n // handle incoming ipc messages from the child process\n this.child.on('message', (message: ChildProcessMessageEvent<unknown>) => {\n if (typeof message !== 'object' || !message.id) {\n return\n }\n\n switch (message.id) {\n case ChildProcessMessageEventType.READY: {\n this.log(`Launched child bridge with PID ${this.child?.pid}`)\n this.loadPlugin()\n break\n }\n case ChildProcessMessageEventType.LOADED: {\n const version = (message.data as ChildProcessPluginLoadedEventData).version\n if (this.pluginConfig.length > 1) {\n this.log(`Loaded ${this.plugin.getPluginIdentifier()} v${version} child bridge successfully with ${this.pluginConfig.length} accessories`)\n } else {\n this.log(`Loaded ${this.plugin.getPluginIdentifier()} v${version} child bridge successfully`)\n }\n this.startBridge()\n break\n }\n case ChildProcessMessageEventType.ONLINE: {\n this.bridgeStatus = ChildBridgeStatus.OK\n break\n }\n case ChildProcessMessageEventType.PORT_REQUEST: {\n this.handlePortRequest(message.data as ChildProcessPortRequestEventData)\n break\n }\n case ChildProcessMessageEventType.STATUS_UPDATE: {\n this.pairedStatus = (message.data as ChildBridgePairedStatusEventData).paired\n this.setupUri = (message.data as ChildBridgePairedStatusEventData).setupUri\n this.sendStatusUpdate()\n break\n }\n }\n })\n }\n\n /**\n * Called when the child bridge process exits, if Homebridge is not shutting down, it will restart the process\n * @param code\n * @param signal\n */\n private handleProcessClose(code: number | null, signal: string | null): void {\n this.log(`Process Ended. Code: ${code}, Signal: ${signal}`)\n\n setTimeout(() => {\n if (!this.shuttingDown) {\n this.log('Restarting Process...')\n this.startChildProcess()\n }\n }, 7000)\n }\n\n /**\n * Helper function to send a message to the child process\n * @param type\n * @param data\n */\n private sendMessage<T = unknown>(type: ChildProcessMessageEventType, data?: T): void {\n if (this.child && this.child.connected) {\n this.child.send({\n id: type,\n data,\n })\n }\n }\n\n /**\n * Some plugins may make use of the homebridge process flags\n * These will be passed through to the forked process\n */\n private setProcessFlags(): void {\n if (this.homebridgeOptions.debugModeEnabled) {\n this.args.push('-D')\n }\n\n if (this.homebridgeOptions.forceColourLogging) {\n this.args.push('-C')\n }\n\n if (this.homebridgeOptions.insecureAccess) {\n this.args.push('-I')\n }\n\n if (this.homebridgeOptions.noLogTimestamps) {\n this.args.push('-T')\n }\n\n if (this.homebridgeOptions.keepOrphanedCachedAccessories) {\n this.args.push('-K')\n }\n\n if (this.homebridgeOptions.customStoragePath) {\n this.args.push('-U', this.homebridgeOptions.customStoragePath)\n }\n\n if (this.homebridgeOptions.customPluginPath) {\n this.args.push('-P', this.homebridgeOptions.customPluginPath)\n }\n }\n\n /**\n * Set environment variables for the child process\n */\n private setProcessEnv(): void {\n this.processEnv = {\n env: {\n ...process.env,\n DEBUG: `${process.env.DEBUG || ''} ${this.bridgeConfig.env?.DEBUG || ''}`.trim(),\n NODE_OPTIONS: `${process.env.NODE_OPTIONS || ''} ${this.bridgeConfig.env?.NODE_OPTIONS || ''}`.trim(),\n },\n silent: true,\n }\n }\n\n /**\n * Tell the child process to load the given plugin\n */\n private loadPlugin(): void {\n const bridgeConfig: BridgeConfiguration = {\n name: this.bridgeConfig.name || this.displayName || this.plugin.getPluginIdentifier(),\n port: this.bridgeConfig.port,\n username: this.bridgeConfig.username,\n advertiser: this.homebridgeConfig.bridge.advertiser,\n pin: this.bridgeConfig.pin || this.homebridgeConfig.bridge.pin,\n bind: this.homebridgeConfig.bridge.bind,\n setupID: this.bridgeConfig.setupID,\n manufacturer: this.bridgeConfig.manufacturer || this.homebridgeConfig.bridge.manufacturer,\n model: this.bridgeConfig.model || this.homebridgeConfig.bridge.model,\n firmwareRevision: this.bridgeConfig.firmwareRevision || this.homebridgeConfig.bridge.firmwareRevision,\n }\n\n const bridgeOptions: BridgeOptions = {\n cachedAccessoriesDir: User.cachedAccessoryPath(),\n cachedAccessoriesItemName: `cachedAccessories.${this.bridgeConfig.username.replace(/:/g, '').toUpperCase()}`,\n }\n\n // shallow copy the homebridge options to the bridge options object\n Object.assign(bridgeOptions, this.homebridgeOptions)\n\n this.sendMessage<ChildProcessLoadEventData>(ChildProcessMessageEventType.LOAD, {\n type: this.type,\n identifier: this.identifier,\n pluginPath: this.plugin.getPluginPath(),\n pluginConfig: this.pluginConfig,\n bridgeConfig,\n bridgeOptions,\n homebridgeConfig: { // need to break this out to avoid a circular structure to JSON from other plugins modifying their config at runtime.\n bridge: this.homebridgeConfig.bridge,\n ports: this.homebridgeConfig.ports,\n disabledPlugins: [], // not used by child bridges\n accessories: [], // not used by child bridges\n platforms: [], // not used by child bridges\n },\n })\n }\n\n /**\n * Tell the child bridge to start broadcasting\n */\n private startBridge(): void {\n this.sendMessage(ChildProcessMessageEventType.START)\n }\n\n /**\n * Handle external port requests from child\n */\n private async handlePortRequest(request: ChildProcessPortRequestEventData) {\n const port = await this.externalPortService.requestPort(request.username)\n this.sendMessage<ChildProcessPortAllocatedEventData>(ChildProcessMessageEventType.PORT_ALLOCATED, {\n username: request.username,\n port,\n })\n }\n\n /**\n * Send sigterm to the child bridge\n */\n private teardown(): void {\n if (this.child && this.child.connected) {\n this.bridgeStatus = ChildBridgeStatus.DOWN\n this.child.kill('SIGTERM')\n }\n }\n\n /**\n * Trigger sending child bridge metadata to the process parent via IPC\n */\n private sendStatusUpdate(): void {\n this.ipcService.sendMessage(IpcOutgoingEvent.CHILD_BRIDGE_STATUS_UPDATE, this.getMetadata())\n }\n\n /**\n * Restarts the child bridge process\n */\n public restartChildBridge(): void {\n if (this.manuallyStopped) {\n this.startChildBridge()\n } else {\n this.log.warn('Restarting child bridge...')\n this.refreshConfig()\n this.teardown()\n }\n }\n\n /**\n * Stops the child bridge, not starting it again\n */\n public stopChildBridge(): void {\n if (!this.shuttingDown) {\n this.log.warn('Stopping child bridge (will not restart)...')\n this.shuttingDown = true\n this.manuallyStopped = true\n this.child?.removeAllListeners('close')\n this.teardown()\n } else {\n this.log.warn('Bridge already shutting down or stopped.')\n }\n }\n\n /**\n * Starts the child bridge, only if it was manually stopped and is no longer running\n */\n public startChildBridge(): void {\n if (this.manuallyStopped && this.bridgeStatus === ChildBridgeStatus.DOWN && (!this.child || !this.child.connected)) {\n this.log.warn('Starting child bridge...')\n this.refreshConfig()\n this.startChildProcess()\n this.shuttingDown = false\n this.manuallyStopped = false\n } else {\n this.log.warn('Cannot start child bridge, it is still running or was not manually stopped')\n }\n }\n\n /**\n * Read the config.json file from disk and refresh the plugin config block for just this plugin\n */\n public async refreshConfig(): Promise<void> {\n try {\n const homebridgeConfig: HomebridgeConfig = await fs.readJson(User.configPath())\n\n if (this.type === PluginType.PLATFORM) {\n const config = homebridgeConfig.platforms?.filter(x => x.platform === this.identifier && x._bridge?.username === this.bridgeConfig.username)\n if (config.length) {\n this.pluginConfig = config\n this.bridgeConfig = this.pluginConfig[0]._bridge || this.bridgeConfig\n } else {\n this.log.warn('Platform config could not be found, using existing config.')\n }\n } else if (this.type === PluginType.ACCESSORY) {\n const config = homebridgeConfig.accessories?.filter(x => x.accessory === this.identifier && x._bridge?.username === this.bridgeConfig.username)\n if (config.length) {\n this.pluginConfig = config\n this.bridgeConfig = this.pluginConfig[0]._bridge || this.bridgeConfig\n } else {\n this.log.warn('Accessory config could not be found, using existing config.')\n }\n }\n } catch (error: any) {\n this.log.error('Failed to refresh plugin config:', error.message)\n }\n }\n\n /**\n * Returns metadata about this child bridge\n */\n public getMetadata(): ChildMetadata {\n return {\n status: this.bridgeStatus,\n paired: this.pairedStatus,\n setupUri: this.setupUri,\n username: this.bridgeConfig.username,\n pin: this.bridgeConfig.pin || this.homebridgeConfig.bridge.pin,\n name: this.bridgeConfig.name || this.displayName || this.plugin.getPluginIdentifier(),\n plugin: this.plugin.getPluginIdentifier(),\n identifier: this.identifier,\n pid: this.child?.pid,\n manuallyStopped: this.manuallyStopped,\n }\n }\n}\n", "import { EventEmitter } from 'node:events'\nimport process from 'node:process'\n\n// eslint-disable-next-line no-restricted-syntax\nexport const enum IpcIncomingEvent {\n RESTART_CHILD_BRIDGE = 'restartChildBridge',\n STOP_CHILD_BRIDGE = 'stopChildBridge',\n START_CHILD_BRIDGE = 'startChildBridge',\n CHILD_BRIDGE_METADATA_REQUEST = 'childBridgeMetadataRequest',\n}\n\n// eslint-disable-next-line no-restricted-syntax\nexport const enum IpcOutgoingEvent {\n SERVER_STATUS_UPDATE = 'serverStatusUpdate',\n CHILD_BRIDGE_METADATA_RESPONSE = 'childBridgeMetadataResponse',\n CHILD_BRIDGE_STATUS_UPDATE = 'childBridgeStatusUpdate',\n}\n\n// eslint-disable-next-line ts/no-unsafe-declaration-merging\nexport declare interface IpcService {\n on: ((event: IpcIncomingEvent.RESTART_CHILD_BRIDGE, listener: (childBridgeUsername: string) => void) => this) & ((event: IpcIncomingEvent.STOP_CHILD_BRIDGE, listener: (childBridgeUsername: string) => void) => this) & ((event: IpcIncomingEvent.START_CHILD_BRIDGE, listener: (childBridgeUsername: string) => void) => this) & ((event: IpcIncomingEvent.CHILD_BRIDGE_METADATA_REQUEST, listener: () => void) => this)\n}\n\n// eslint-disable-next-line ts/no-unsafe-declaration-merging\nexport class IpcService extends EventEmitter {\n constructor() {\n super()\n }\n\n /**\n * Start the IPC service listeners/\n * Currently this will only listen for messages from a parent process.\n */\n public start(): void {\n process.on('message', (message: { id: string, data: never }) => {\n if (!message || typeof message !== 'object' || !message.id) {\n return\n }\n this.emit(message.id, message.data)\n })\n }\n\n /**\n * Send a message to connected IPC clients.\n * Currently, this will only send messages if Homebridge was launched as a child_process.fork()\n * from another Node.js process (such as hb-service).\n */\n public sendMessage(id: IpcOutgoingEvent, data: unknown): void {\n if (process.send) {\n process.send({\n id,\n data,\n })\n }\n }\n}\n", "import type { MacAddress } from 'hap-nodejs'\n\nimport type { ChildBridgeFork } from './childBridgeFork.js'\n\nimport { Logger } from './logger.js'\n\nexport interface ExternalPortsConfiguration {\n start: number\n end: number\n}\n\n/**\n * Allocates ports from the user defined `config.ports` option\n * This service is used to allocate ports for external accessories on the main bridge, and child bridges.\n */\nexport class ExternalPortService {\n private nextExternalPort?: number\n private allocatedPorts: Map<MacAddress, number | undefined> = new Map()\n\n constructor(\n private externalPorts?: ExternalPortsConfiguration,\n ) { }\n\n /**\n * Returns the next available port in the external port config.\n * If the external port is not configured by the user it will return null.\n * If the port range has been exhausted it will return null.\n */\n public async requestPort(username: MacAddress): Promise<number | undefined> {\n // check to see if this device has already requested an external port\n const existingPortAllocation = this.allocatedPorts.get(username)\n if (existingPortAllocation) {\n return existingPortAllocation\n }\n\n // get the next unused port\n const port = this.getNextFreePort()\n this.allocatedPorts.set(username, port)\n return port\n }\n\n private getNextFreePort(): number | undefined {\n if (!this.externalPorts) {\n return undefined\n }\n\n if (this.nextExternalPort === undefined) {\n this.nextExternalPort = this.externalPorts.start\n return this.nextExternalPort\n }\n\n this.nextExternalPort++\n\n if (this.nextExternalPort <= this.externalPorts.end) {\n return this.nextExternalPort\n }\n\n Logger.internal.warn('External port pool ran out of ports. Falling back to random port assignment.')\n\n return undefined\n }\n}\n\n/**\n * This is the child bridge version of the port allocation service.\n * It requests a free port from the main bridge's port service.\n */\nexport class ChildBridgeExternalPortService extends ExternalPortService {\n constructor(\n private childBridge: ChildBridgeFork,\n ) {\n super()\n }\n\n public async requestPort(username: MacAddress): Promise<number | undefined> {\n return await this.childBridge.requestExternalPort(username)\n }\n}\n"],
5
- "mappings": "AAIA,OAAOA,MAAa,eAEpB,OAAS,WAAAC,OAAe,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mBAAAC,EACA,kBAAAC,EACA,uBAAAJ,CACF,EAEMY,EAAS,IAAIC,EAAOF,CAAO,EAE3BG,EAAgB,CAACC,EAAiBC,KAA4B,CAC9DX,IAGJA,EAAe,GAEfhB,EAAI,KAAK,sCAAuC0B,CAAM,EACtD,WAAW,IAAMrB,EAAQ,KAAK,IAAMsB,EAAS,EAAG,GAAI,EAEpDJ,EAAO,SAAS,EAClB,EACAlB,EAAQ,GAAG,SAAUoB,EAAc,KAAK,OAAW,SAAU,CAAC,CAAC,EAC/DpB,EAAQ,GAAG,UAAWoB,EAAc,KAAK,OAAW,UAAW,EAAE,CAAC,EAElE,IAAMG,GAAgBC,GAAuB,CACvCA,EAAM,OACR7B,EAAI,MAAM6B,EAAM,KAAK,EAGlBb,GACHX,EAAQ,KAAKA,EAAQ,IAAK,SAAS,CAEvC,EACAA,EAAQ,GAAG,oBAAqBuB,EAAY,EAC5CL,EAAO,MAAM,EAAE,MAAMK,EAAY,CACnC",
6
- "names": ["process", "Command", "HAPStorage", "satisfies", "util", "chalk", "Logger", "_Logger", "prefix", "loggerStuff", "logger", "log", "logging", "enabled", "chalk", "message", "parameters", "level", "util", "loggingFunction", "getLogPrefix", "date", "fs", "process", "chalk", "AccessoryEventTypes", "MDNSAdvertiser", "qrcode", "EventEmitter", "hapNodeJs", "semver", "EventEmitter", "Accessory", "AccessoryEventTypes", "Categories", "PlatformAccessory", "_PlatformAccessory", "EventEmitter", "displayName", "uuid", "category", "Accessory", "Categories", "AccessoryEventTypes", "paired", "callback", "service", "constructorArgs", "name", "subType", "controller", "accessory", "json", "platformAccessory", "execSync", "fs", "createRequire", "path", "process", "assert", "path", "process", "pathToFileURL", "satisfies", "fs", "dirname", "join", "fileURLToPath", "__filename", "__dirname", "loadPackageJson", "packageJSONPath", "getVersion", "getRequiredNodeVersion", "log", "Logger", "Plugin", "name", "path", "packageJSON", "scope", "exports", "constructor", "accessoryIdentifier", "PluginManager", "platformIdentifier", "platformPlugin", "platforms", "platformName", "context", "assert", "versionRequired", "nodeVersionRequired", "satisfies", "getVersion", "process", "dependencies", "mainPath", "pluginModules", "pathToFileURL", "api", "log", "Logger", "require", "createRequire", "paths", "PluginManager", "_PluginManager", "api", "options", "path", "process", "identifier", "name", "plugin", "error", "constructor", "pluginIdentifier", "plugins", "accessoryIdentifier", "found", "platformIdentifier", "translation", "platformName", "searchPath", "fs", "relativePluginPaths", "relativePath", "scopeDirectory", "index", "absolutePath", "packageJson", "scope", "alreadyInstalled", "Plugin", "pluginPath", "packageJsonPath", "execSync", "os", "path", "User", "_User", "storagePathSegments", "log", "Logger", "HomebridgeAPI", "EventEmitter", "getVersion", "User", "hapNodeJs", "PlatformAccessory", "version", "semver", "platformPlugin", "pluginIdentifier", "accessoryName", "constructor", "platformName", "accessories", "PluginManager", "log", "accessory", "Accessory", "AccessoryEventTypes", "Bridge", "Categories", "Characteristic", "CharacteristicEventTypes", "CharacteristicWarningType", "HAPLibraryVersion", "once", "Service", "uuid", "path", "fs", "StorageService", "baseDirectory", "itemName", "filePath", "data", "srcItemName", "destItemName", "crypto", "validMac", "validMacAddress", "address", "generate", "data", "sha1sum", "s", "i", "log", "Logger", "BridgeService", "_BridgeService", "api", "pluginManager", "externalPortService", "bridgeOptions", "bridgeConfig", "config", "StorageService", "Bridge", "uuid", "AccessoryEventTypes", "plugin", "accessory", "opts", "warning", "wikiInfo", "CharacteristicWarningType", "getLogPrefix", "info", "Service", "Characteristic", "getVersion", "port", "HAPLibraryVersion", "publishInfo", "Categories", "cachedAccessories", "error", "serialized", "PlatformAccessory", "platformPlugins", "serializedAccessories", "accessories", "hapAccessories", "index", "accessoryPin", "hapAccessory", "advertiseAddress", "generate", "accessoryPort", "PluginManager", "accessoryInstance", "displayName", "accessoryType", "uuidBase", "services", "service", "controllers", "controller", "accessoryUUID", "Accessory", "paired", "callback", "informationService", "CharacteristicEventTypes", "platformInstance", "platformType", "logger", "resolve", "loadDelayWarningInterval", "once", "accessoryName", "child_process", "path", "dirname", "process", "fileURLToPath", "fs", "EventEmitter", "process", "IpcService", "EventEmitter", "process", "message", "id", "data", "__filename", "fileURLToPath", "__dirname", "dirname", "ChildBridgeService", "type", "identifier", "plugin", "bridgeConfig", "homebridgeConfig", "homebridgeOptions", "api", "ipcService", "externalPortService", "Logger", "config", "value", "child_process", "path", "__dirname", "data", "process", "code", "signal", "message", "version", "bridgeOptions", "User", "request", "port", "fs", "x", "error", "ExternalPortService", "externalPorts", "username", "existingPortAllocation", "port", "Logger", "log", "Logger", "Server", "_Server", "options", "HomebridgeAPI", "IpcService", "ExternalPortService", "pluginManagerOptions", "PluginManager", "bridgeConfig", "User", "BridgeService", "AccessoryEventTypes", "status", "promises", "childBridge", "configPath", "defaultBridge", "fs", "log", "config", "error", "bridge", "username", "validMacAddress", "MDNSAdvertiser", "accessoryConfig", "index", "accessoryIdentifier", "displayName", "plugin", "constructor", "logger", "Logger", "ChildBridgeService", "accessoryInstance", "accessory", "platformConfig", "platformIdentifier", "process", "platform", "type", "identifier", "x", "pin", "qrcode", "chalk", "log", "Logger", "requiredNodeVersion", "getRequiredNodeVersion", "satisfies", "process", "cli", "insecureAccess", "hideQRCode", "keepOrphans", "customPluginPath", "strictPluginResolution", "noLogTimestamps", "debugModeEnabled", "forceColourLogging", "customStoragePath", "shuttingDown", "Command", "getVersion", "path", "User", "HAPStorage", "options", "server", "Server", "signalHandler", "signal", "signalNum", "errorHandler", "error"]
7
- }
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,mBAAmB;AAInB,OAAO,OAAO,MAAM,cAAc,CAAA;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAClC,OAAO,gCAAgC,CAAA;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAA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CAAC,CAAA;IAElC,MAAM,aAAa,GAAG,CAAC,MAAe,EAAE,SAAiB,EAAQ,EAAE;QACjE,IAAI,YAAY,EAAE,CAAC;YACjB,OAAM;QACR,CAAC;QACD,YAAY,GAAG,IAAI,CAAA;QAEnB,GAAG,CAAC,IAAI,CAAC,qCAAqC,EAAE,MAAM,CAAC,CAAA;QACvD,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC,EAAE,IAAI,CAAC,CAAA;QAErD,MAAM,CAAC,QAAQ,EAAE,CAAA;IACnB,CAAC,CAAA;IACD,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAA;IAChE,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC,CAAA;IAEnE,MAAM,YAAY,GAAG,CAAC,KAAY,EAAQ,EAAE;QAC1C,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAChB,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACxB,CAAC;QAED,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;QACtC,CAAC;IACH,CAAC,CAAA;IACD,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAA;IAC7C,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;AACpC,CAAC"}
@@ -0,0 +1,33 @@
1
+ import type { MacAddress } from 'hap-nodejs';
2
+ import type { ChildBridgeFork } from './childBridgeFork.js';
3
+ export interface ExternalPortsConfiguration {
4
+ start: number;
5
+ end: number;
6
+ }
7
+ /**
8
+ * Allocates ports from the user defined `config.ports` option
9
+ * This service is used to allocate ports for external accessories on the main bridge, and child bridges.
10
+ */
11
+ export declare class ExternalPortService {
12
+ private externalPorts?;
13
+ private nextExternalPort?;
14
+ private allocatedPorts;
15
+ constructor(externalPorts?: ExternalPortsConfiguration | undefined);
16
+ /**
17
+ * Returns the next available port in the external port config.
18
+ * If the external port is not configured by the user it will return null.
19
+ * If the port range has been exhausted it will return null.
20
+ */
21
+ requestPort(username: MacAddress): Promise<number | undefined>;
22
+ private getNextFreePort;
23
+ }
24
+ /**
25
+ * This is the child bridge version of the port allocation service.
26
+ * It requests a free port from the main bridge's port service.
27
+ */
28
+ export declare class ChildBridgeExternalPortService extends ExternalPortService {
29
+ private childBridge;
30
+ constructor(childBridge: ChildBridgeFork);
31
+ requestPort(username: MacAddress): Promise<number | undefined>;
32
+ }
33
+ //# sourceMappingURL=externalPortService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"externalPortService.d.ts","sourceRoot":"","sources":["../src/externalPortService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAI3D,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;;GAGG;AACH,qBAAa,mBAAmB;IAK5B,OAAO,CAAC,aAAa,CAAC;IAJxB,OAAO,CAAC,gBAAgB,CAAC,CAAQ;IACjC,OAAO,CAAC,cAAc,CAAiD;gBAG7D,aAAa,CAAC,EAAE,0BAA0B,YAAA;IAGpD;;;;OAIG;IACU,WAAW,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAa3E,OAAO,CAAC,eAAe;CAoBxB;AAED;;;GAGG;AACH,qBAAa,8BAA+B,SAAQ,mBAAmB;IAEnE,OAAO,CAAC,WAAW;gBAAX,WAAW,EAAE,eAAe;IAKzB,WAAW,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;CAG5E"}
@@ -0,0 +1,59 @@
1
+ import { Logger } from './logger.js';
2
+ /**
3
+ * Allocates ports from the user defined `config.ports` option
4
+ * This service is used to allocate ports for external accessories on the main bridge, and child bridges.
5
+ */
6
+ export class ExternalPortService {
7
+ externalPorts;
8
+ nextExternalPort;
9
+ allocatedPorts = new Map();
10
+ constructor(externalPorts) {
11
+ this.externalPorts = externalPorts;
12
+ }
13
+ /**
14
+ * Returns the next available port in the external port config.
15
+ * If the external port is not configured by the user it will return null.
16
+ * If the port range has been exhausted it will return null.
17
+ */
18
+ async requestPort(username) {
19
+ // check to see if this device has already requested an external port
20
+ const existingPortAllocation = this.allocatedPorts.get(username);
21
+ if (existingPortAllocation) {
22
+ return existingPortAllocation;
23
+ }
24
+ // get the next unused port
25
+ const port = this.getNextFreePort();
26
+ this.allocatedPorts.set(username, port);
27
+ return port;
28
+ }
29
+ getNextFreePort() {
30
+ if (!this.externalPorts) {
31
+ return undefined;
32
+ }
33
+ if (this.nextExternalPort === undefined) {
34
+ this.nextExternalPort = this.externalPorts.start;
35
+ return this.nextExternalPort;
36
+ }
37
+ this.nextExternalPort++;
38
+ if (this.nextExternalPort <= this.externalPorts.end) {
39
+ return this.nextExternalPort;
40
+ }
41
+ Logger.internal.warn('External port pool ran out of ports. Falling back to random port assignment.');
42
+ return undefined;
43
+ }
44
+ }
45
+ /**
46
+ * This is the child bridge version of the port allocation service.
47
+ * It requests a free port from the main bridge's port service.
48
+ */
49
+ export class ChildBridgeExternalPortService extends ExternalPortService {
50
+ childBridge;
51
+ constructor(childBridge) {
52
+ super();
53
+ this.childBridge = childBridge;
54
+ }
55
+ async requestPort(username) {
56
+ return await this.childBridge.requestExternalPort(username);
57
+ }
58
+ }
59
+ //# sourceMappingURL=externalPortService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"externalPortService.js","sourceRo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