{"record":{"id":"ae19c0631e298e9d","repo":"homebridge/homebridge","slug":"plugin-this-getpluginidentifier-tried-to-re","errorCode":null,"errorMessage":"Plugin '${this.getPluginIdentifier()}' tried to register an accessory '${name}' which has already been registered!","messagePattern":"Plugin '(.+?)' tried to register an accessory '(.+?)' which has already been registered!","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/plugin.ts","lineNumber":109,"sourceCode":"    }\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","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/homebridge/homebridge/blob/edf54930340d67cade23d01abd41b03cd9621e8b/src/plugin.ts#L91-L127","documentation":"Plugin.registerAccessory() maintains a Map of accessory name -> constructor for the plugin. Calling api.registerAccessory() twice with the same accessory name is treated as a plugin bug (usually a double-initialization) and throws immediately instead of silently overwriting the first registration.","triggerScenarios":"A plugin's default export (initializer) calls api.registerAccessory('MyAccessory', ...) twice — e.g. the initializer runs twice, or the same name is registered conditionally in two branches that both execute.","commonSituations":"Hot-reload/dev setups that re-require the plugin module and re-run the initializer on the same API instance; copy-pasted registerAccessory calls with duplicate name strings; bundling issues where the plugin module is instantiated twice.","solutions":["Search the plugin for duplicate api.registerAccessory() calls with the same name and remove/merge them.","Guard registration with a module-level flag so the initializer only registers once.","Ensure the plugin initializer is only invoked once per process (avoid re-requiring/re-executing the module).","Check for duplicated name string literals — use a single exported constant for each accessory name."],"exampleFix":"// before\nexport default (api) => {\n  api.registerAccessory('MyLight', MyLight)\n  api.registerAccessory('MyLight', MyLightAlt) // throws\n}\n// after\nexport default (api) => {\n  api.registerAccessory('MyLight', MyLight)\n}","handlingStrategy":"validation","validationCode":"const registered = new Set()\nfunction registerOnce(api, name, ctor) {\n  if (registered.has(name)) return\n  api.registerAccessory(name, ctor)\n  registered.add(name)\n}","typeGuard":null,"tryCatchPattern":"try {\n  api.registerAccessory('MyLight', MyLight)\n} catch (e) {\n  if (e instanceof Error && e.message.includes('already been registered')) {\n    log.warn('Accessory already registered; ignoring duplicate registration')\n  } else throw e\n}","preventionTips":["Keep all api.registerAccessory() calls in one place in the initializer.","Use an idempotence guard so re-running the initializer cannot double-register.","Define accessory names as exported constants to avoid string duplicates."],"tags":["plugin-development","duplicate-registration","accessory"],"backgroundTag":"duplicate-registration","analyzedSha":"edf54930340d67cade23d01abd41b03cd9621e8b","analyzedAt":"2026-08-30T21:28:53.235Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}