@silizia/homebridge-dioder 0.2.6 → 0.2.7
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.
- package/dist/matter.js +9 -2
- package/dist/matter.js.map +1 -1
- package/package.json +1 -1
package/dist/matter.js
CHANGED
|
@@ -31,7 +31,13 @@ var DioderAccessory = class {
|
|
|
31
31
|
colorControl: {
|
|
32
32
|
currentHue: 0,
|
|
33
33
|
currentSaturation: 254,
|
|
34
|
-
colorMode: this.api.matter.types.ColorControl.ColorMode.CurrentHueAndCurrentSaturation
|
|
34
|
+
colorMode: this.api.matter.types.ColorControl.ColorMode.CurrentHueAndCurrentSaturation,
|
|
35
|
+
currentX: 41942,
|
|
36
|
+
currentY: 21626,
|
|
37
|
+
colorTemperatureMireds: 250,
|
|
38
|
+
colorTempPhysicalMinMireds: 147,
|
|
39
|
+
colorTempPhysicalMaxMireds: 454,
|
|
40
|
+
coupleColorTempToLevelMinMireds: 147
|
|
35
41
|
}
|
|
36
42
|
},
|
|
37
43
|
handlers: {
|
|
@@ -169,7 +175,8 @@ var DioderPlatform = class {
|
|
|
169
175
|
};
|
|
170
176
|
//#endregion
|
|
171
177
|
//#region src/matter/index.ts
|
|
172
|
-
function main(api) {
|
|
178
|
+
async function main(api) {
|
|
179
|
+
await api.loadMatterAPI();
|
|
173
180
|
api.registerPlatform("Dioder", DioderPlatform);
|
|
174
181
|
}
|
|
175
182
|
//#endregion
|
package/dist/matter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matter.js","names":[],"sources":["../src/matter/DioderAccessory.ts","../src/matter/DioderPlatform.ts","../src/matter/index.ts"],"sourcesContent":["import { colord, type HsvColor } from 'colord';\nimport type { MatterAccessory, Logging, API, MatterRequests } from 'homebridge';\nimport lg from 'lgpio';\n\nimport type { LedConfig } from './DioderPlatform';\n\nconst MIN_PWM = 0.5; // min pwm to get actually light from dioder, depends on PWM_RANGE\nconst PWM_FREQUENCY = 10000;\nconst GAMMA_COR = 2.8;\n\nexport default class DioderAccessory {\n private readonly accessory: MatterAccessory<Record<string, never>>;\n\n constructor(\n private readonly api: API,\n private readonly log: Logging,\n private readonly gpiochip: number,\n private readonly config: LedConfig,\n accessory?: MatterAccessory<Record<string, never>>\n ) {\n if (!DEV) {\n lg.gpioClaimOutput(gpiochip, this.config.rPin);\n lg.gpioClaimOutput(gpiochip, this.config.gPin);\n lg.gpioClaimOutput(gpiochip, this.config.bPin);\n }\n\n this.accessory = accessory ?? {\n UUID: this.api.hap.uuid.generate(this.config.name),\n displayName: this.config.name,\n deviceType: this.api.matter.deviceTypes.ExtendedColorLight,\n serialNumber: '42',\n manufacturer: 'Silizia',\n model: 'Fancy LED',\n clusters: {\n onOff: { onOff: false },\n levelControl: { currentLevel: 254, minLevel: 1, maxLevel: 254 },\n colorControl: { currentHue: 0, currentSaturation: 254, colorMode: this.api.matter.types.ColorControl.ColorMode.CurrentHueAndCurrentSaturation },\n },\n handlers: {\n onOff: { on: (): Promise<void> => this.handleOn(), off: (): void => this.handleOff() },\n levelControl: { moveToLevelWithOnOff: (request): void => this.handleSetLevel(request) },\n colorControl: { moveToHueAndSaturationLogic: (request): void => this.handleSetHueSaturation(request) },\n },\n context: {},\n };\n }\n\n getBrightness(): number {\n return (this.accessory?.clusters?.levelControl?.currentLevel ?? 254 / 254) * 100;\n }\n\n getHsv(): HsvColor {\n const mh = this.accessory?.clusters?.colorControl?.currentHue ?? 0;\n const ms = this.accessory?.clusters?.colorControl?.currentSaturation ?? 254;\n const v = this.getBrightness();\n return { h: (mh / 254) * 360, s: (ms / 254) * 100, v };\n }\n\n pwm(r: number, g: number, b: number): void {\n if (DEV) {\n this.log.info(`pwm r: ${r}, g: ${g}, b: ${b} for gpiochip: ${this.gpiochip} with freq: ${this.config.freq ?? PWM_FREQUENCY}`);\n this.log.info(`rpin ${this.config.rPin} to ${r === 0 ? 'off' : (r / 255) ** GAMMA_COR * (100 - MIN_PWM) + MIN_PWM}`);\n this.log.info(`gpin ${this.config.gPin} to ${g === 0 ? 'off' : (g / 255) ** GAMMA_COR * (100 - MIN_PWM) + MIN_PWM}`);\n this.log.info(`bpin ${this.config.bPin} to ${b === 0 ? 'off' : (b / 255) ** GAMMA_COR * (100 - MIN_PWM) + MIN_PWM}`);\n } else {\n lg.txPwm(\n this.gpiochip,\n this.config.rPin,\n this.config.freq ?? PWM_FREQUENCY,\n r === 0 ? 0 : (r / 255) ** GAMMA_COR * (100 - MIN_PWM) + MIN_PWM,\n 0,\n r === 0 ? 1 : 0\n );\n lg.txPwm(\n this.gpiochip,\n this.config.gPin,\n this.config.freq ?? PWM_FREQUENCY,\n g === 0 ? 0 : (g / 255) ** GAMMA_COR * (100 - MIN_PWM) + MIN_PWM,\n 0,\n g === 0 ? 1 : 0\n );\n lg.txPwm(\n this.gpiochip,\n this.config.bPin,\n this.config.freq ?? PWM_FREQUENCY,\n b === 0 ? 0 : (b / 255) ** GAMMA_COR * (100 - MIN_PWM) + MIN_PWM,\n 0,\n b === 0 ? 1 : 0\n );\n }\n }\n\n setHSV(c: HsvColor): void {\n if (c.v > 0) {\n const { r, g, b } = colord(c).toRgb();\n this.pwm(r, g, b);\n this.log.info(`MATTER: set ${this.config.name} r: ${r}, g: ${g}, b: ${b} or h: ${c.h}, s: ${c.s}, v: ${c.v}`);\n } else {\n this.log.warn('Skipping color change while light bulb being off');\n }\n }\n\n // oxlint-disable-next-line typescript/require-await\n private async handleOn(): Promise<void> {\n this.log.info(`${this.config.name}: turning on.`);\n const hsv = this.getHsv();\n /*! if (hsv.v === 0) {\n await this.api.matter.updateAccessoryState(\n this.accessory.UUID,\n this.api.matter.clusterNames.LevelControl,\n { currentLevel: 254 }\n );\n hsv.v = 100;\n }*/\n this.setHSV(hsv);\n }\n\n private handleOff(): void {\n this.log.info(`${this.config.name}: turning off.`);\n this.pwm(0, 0, 0);\n }\n\n private handleSetLevel(request: MatterRequests.MoveToLevel): void {\n this.log.info(`${this.config.name}: MoveToLevel request: ${JSON.stringify(request)}`);\n const { level /* transitionTime */ } = request;\n const hsv = this.getHsv();\n hsv.v = (level / 254) * 100;\n this.setHSV(hsv);\n this.log.info(`${this.config.name}: setting brightness to ${hsv.v}%.`);\n }\n\n private handleSetHueSaturation(request: { hue: number; saturation: number; transitionTime: number }): void {\n this.log.info(`${this.config.name}: MoveToHueAndSaturation request: ${JSON.stringify(request)}`);\n const { hue, saturation /* transitionTime */ } = request;\n const hsv = { h: (hue / 254) * 360, s: (saturation / 254) * 100, v: this.getBrightness() };\n this.setHSV(hsv);\n this.log.info(`${this.config.name}: setting color to h: ${hsv.h}°, s: ${hsv.s}%, v: ${hsv.v}%.`);\n }\n\n getAccessory(): MatterAccessory<Record<string, never>> {\n return this.accessory;\n }\n}\n","import type { MatterAccessory, API, Logging, PlatformConfig, DynamicPlatformPlugin } from 'homebridge';\nimport lg from 'lgpio';\n\nimport DioderAccessory from './DioderAccessory';\n\ndeclare global {\n var DEV: boolean;\n}\n\nexport interface LedConfig {\n name: string;\n rPin: number;\n gPin: number;\n bPin: number;\n freq: number;\n}\n\ninterface GradiantConfig {\n name: string;\n colors: string[];\n}\n\ninterface DioderConfig extends PlatformConfig {\n leds: LedConfig[];\n gradientAnim: GradiantConfig[];\n rainbowAnim: { enabled: boolean };\n}\n\nconst PLUGIN_NAME = '@silizia/homebridge-dioder';\n\nexport default class DioderPlatform implements DynamicPlatformPlugin {\n public readonly accessories: Map<string, MatterAccessory> = new Map();\n public readonly outdatedAccessories: MatterAccessory<Record<string, never>>[] = [];\n private gpiochip?: number;\n\n constructor(\n public readonly log: Logging,\n public readonly config: DioderConfig,\n public readonly api: API\n ) {\n this.log.debug('Finished initializing platform: Dioder');\n this.api.on('didFinishLaunching', () => {\n this.log.debug('Executed didFinishLaunching callback');\n const removedAccessories = new Map(this.accessories);\n const newAccessories: MatterAccessory[] = [];\n // DioderAccessories\n this.gpiochip = DEV ? 0 : lg.gpiochipOpen(0);\n for (const c of this.config.leds || []) {\n const uuid = this.api.matter.uuid.generate(JSON.stringify(c.name));\n const existingAccessory = this.accessories.get(uuid) as MatterAccessory<Record<string, never>>;\n if (existingAccessory) {\n removedAccessories.delete(uuid);\n this.log.info('Restoring existing accessory from cache:', existingAccessory.displayName);\n // oxlint-disable-next-line no-new\n new DioderAccessory(this.api, this.log, this.gpiochip, c, existingAccessory);\n } else {\n this.log.info('Adding new accessory:', c.name);\n const device = new DioderAccessory(this.api, this.log, this.gpiochip, c);\n newAccessories.push(device.getAccessory());\n }\n }\n // removed unused Accessories\n if (removedAccessories.size > 0) {\n const ra = Array.from(removedAccessories).map(([_k, v]) => v);\n this.log.warn(\n 'removing unused accessories',\n ra.map(a => `${a.displayName} (${a.UUID})`)\n );\n this.api.matter.unregisterPlatformAccessories(PLUGIN_NAME, 'Dioder', ra);\n }\n if (newAccessories.length > 0) {\n this.log.info(\n 'added new accessories',\n newAccessories.map(a => `${a.displayName} (${a.UUID})`)\n );\n this.api.matter.registerPlatformAccessories(PLUGIN_NAME, 'Dioder', newAccessories);\n }\n });\n this.api.on('shutdown', () => {\n if (!DEV && this.gpiochip !== undefined) {\n for (const c of this.config.leds || []) {\n lg.gpioFree(this.gpiochip, c.rPin);\n lg.gpioFree(this.gpiochip, c.gPin);\n lg.gpioFree(this.gpiochip, c.bPin);\n }\n lg.gpiochipClose(this.gpiochip);\n }\n });\n }\n\n // oxlint-disable-next-line no-empty-function, class-methods-use-this\n configureAccessory(): void {}\n\n configureMatterAccessory(accessory: MatterAccessory): void {\n this.log.info('Loading accessory from cache:', accessory.displayName, accessory.UUID);\n this.accessories.set(accessory.UUID, accessory);\n }\n}\n","import type { API } from 'homebridge';\n\nimport DioderPlatform from './DioderPlatform';\n\nexport default function main(api: API): void {\n api.registerPlatform('Dioder', DioderPlatform);\n}\n"],"mappings":";;;AAMA,MAAM,UAAU;AAChB,MAAM,gBAAgB;AACtB,MAAM,YAAY;AAElB,IAAqB,kBAArB,MAAqC;CACnC;CAEA,YACE,KACA,KACA,U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,KAAK,KAAK,KAAK,KAAK,UAAU,EAAE;AACxE,oBAAe,KAAK,OAAO,cAAc,CAAC;;;AAI9C,OAAI,mBAAmB,OAAO,GAAG;IAC/B,MAAM,KAAK,MAAM,KAAK,mBAAmB,CAAC,KAAK,CAAC,IAAI,OAAO,EAAE;AAC7D,SAAK,IAAI,KACP,+BACA,GAAG,KAAI,MAAK,GAAG,EAAE,YAAY,IAAI,EAAE,KAAK,GAAG,CAC5C;AACD,SAAK,IAAI,OAAO,8BAA8B,aAAa,UAAU,GAAG;;AAE1E,OAAI,eAAe,SAAS,GAAG;AAC7B,SAAK,IAAI,KACP,yBACA,eAAe,KAAI,MAAK,GAAG,EAAE,YAAY,IAAI,EAAE,KAAK,GAAG,CACxD;AACD,SAAK,IAAI,OAAO,4BAA4B,aAAa,UAAU,eAAe;;IAEpF;AACF,OAAK,IAAI,GAAG,kBAAkB;AAC5B,OAAY,KAAK,aAAa,KAAA,GAAW;AACvC,SAAK,MAAM,KAAK,KAAK,OAAO,QAAQ,EAAE,EAAE;AACtC,QAAG,SAAS,KAAK,UAAU,EAAE,KAAK;AAClC,QAAG,SAAS,KAAK,UAAU,EAAE,KAAK;AAClC,QAAG,SAAS,KAAK,UAAU,EAAE,KAAK;;AAEpC,OAAG,cAAc,KAAK,SAAS;;IAEjC;;CAIJ,qBAA2B;CAE3B,yBAAyB,WAAkC;AACzD,OAAK,IAAI,KAAK,iCAAiC,UAAU,aAAa,UAAU,KAAK;AACrF,OAAK,YAAY,IAAI,UAAU,MAAM,UAAU;;;;;AC3FnD,SAAwB,KAAK,KAAgB;AAC3C,KAAI,iBAAiB,UAAU,eAAe"}
|
|
1
|
+
{"version":3,"file":"matter.js","names":[],"sources":["../src/matter/DioderAccessory.ts","../src/matter/DioderPlatform.ts","../src/matter/index.ts"],"sourcesContent":["import { colord, type HsvColor } from 'colord';\nimport type { MatterAccessory, Logging, API, MatterRequests } from 'homebridge';\nimport lg from 'lgpio';\n\nimport type { LedConfig } from './DioderPlatform';\n\nconst MIN_PWM = 0.5; // min pwm to get actually light from dioder, depends on PWM_RANGE\nconst PWM_FREQUENCY = 10000;\nconst GAMMA_COR = 2.8;\n\nexport default class DioderAccessory {\n private readonly accessory: MatterAccessory<Record<string, never>>;\n\n constructor(\n private readonly api: API,\n private readonly log: Logging,\n private readonly gpiochip: number,\n private readonly config: LedConfig,\n accessory?: MatterAccessory<Record<string, never>>\n ) {\n if (!DEV) {\n lg.gpioClaimOutput(gpiochip, this.config.rPin);\n lg.gpioClaimOutput(gpiochip, this.config.gPin);\n lg.gpioClaimOutput(gpiochip, this.config.bPin);\n }\n\n this.accessory = accessory ?? {\n UUID: this.api.hap.uuid.generate(this.config.name),\n displayName: this.config.name,\n deviceType: this.api.matter.deviceTypes.ExtendedColorLight,\n serialNumber: '42',\n manufacturer: 'Silizia',\n model: 'Fancy LED',\n clusters: {\n onOff: { onOff: false },\n levelControl: { currentLevel: 254, minLevel: 1, maxLevel: 254 },\n colorControl: {\n currentHue: 0,\n currentSaturation: 254,\n colorMode: this.api.matter.types.ColorControl.ColorMode.CurrentHueAndCurrentSaturation,\n currentX: 41942,\n currentY: 21626,\n colorTemperatureMireds: 250,\n colorTempPhysicalMinMireds: 147,\n colorTempPhysicalMaxMireds: 454,\n coupleColorTempToLevelMinMireds: 147,\n },\n },\n handlers: {\n onOff: { on: (): Promise<void> => this.handleOn(), off: (): void => this.handleOff() },\n levelControl: { moveToLevelWithOnOff: (request): void => this.handleSetLevel(request) },\n colorControl: { moveToHueAndSaturationLogic: (request): void => this.handleSetHueSaturation(request) },\n },\n context: {},\n };\n }\n\n getBrightness(): number {\n return (this.accessory?.clusters?.levelControl?.currentLevel ?? 254 / 254) * 100;\n }\n\n getHsv(): HsvColor {\n const mh = this.accessory?.clusters?.colorControl?.currentHue ?? 0;\n const ms = this.accessory?.clusters?.colorControl?.currentSaturation ?? 254;\n const v = this.getBrightness();\n return { h: (mh / 254) * 360, s: (ms / 254) * 100, v };\n }\n\n pwm(r: number, g: number, b: number): void {\n if (DEV) {\n this.log.info(`pwm r: ${r}, g: ${g}, b: ${b} for gpiochip: ${this.gpiochip} with freq: ${this.config.freq ?? PWM_FREQUENCY}`);\n this.log.info(`rpin ${this.config.rPin} to ${r === 0 ? 'off' : (r / 255) ** GAMMA_COR * (100 - MIN_PWM) + MIN_PWM}`);\n this.log.info(`gpin ${this.config.gPin} to ${g === 0 ? 'off' : (g / 255) ** GAMMA_COR * (100 - MIN_PWM) + MIN_PWM}`);\n this.log.info(`bpin ${this.config.bPin} to ${b === 0 ? 'off' : (b / 255) ** GAMMA_COR * (100 - MIN_PWM) + MIN_PWM}`);\n } else {\n lg.txPwm(\n this.gpiochip,\n this.config.rPin,\n this.config.freq ?? PWM_FREQUENCY,\n r === 0 ? 0 : (r / 255) ** GAMMA_COR * (100 - MIN_PWM) + MIN_PWM,\n 0,\n r === 0 ? 1 : 0\n );\n lg.txPwm(\n this.gpiochip,\n this.config.gPin,\n this.config.freq ?? PWM_FREQUENCY,\n g === 0 ? 0 : (g / 255) ** GAMMA_COR * (100 - MIN_PWM) + MIN_PWM,\n 0,\n g === 0 ? 1 : 0\n );\n lg.txPwm(\n this.gpiochip,\n this.config.bPin,\n this.config.freq ?? PWM_FREQUENCY,\n b === 0 ? 0 : (b / 255) ** GAMMA_COR * (100 - MIN_PWM) + MIN_PWM,\n 0,\n b === 0 ? 1 : 0\n );\n }\n }\n\n setHSV(c: HsvColor): void {\n if (c.v > 0) {\n const { r, g, b } = colord(c).toRgb();\n this.pwm(r, g, b);\n this.log.info(`MATTER: set ${this.config.name} r: ${r}, g: ${g}, b: ${b} or h: ${c.h}, s: ${c.s}, v: ${c.v}`);\n } else {\n this.log.warn('Skipping color change while light bulb being off');\n }\n }\n\n // oxlint-disable-next-line typescript/require-await\n private async handleOn(): Promise<void> {\n this.log.info(`${this.config.name}: turning on.`);\n const hsv = this.getHsv();\n /*! if (hsv.v === 0) {\n await this.api.matter.updateAccessoryState(\n this.accessory.UUID,\n this.api.matter.clusterNames.LevelControl,\n { currentLevel: 254 }\n );\n hsv.v = 100;\n }*/\n this.setHSV(hsv);\n }\n\n private handleOff(): void {\n this.log.info(`${this.config.name}: turning off.`);\n this.pwm(0, 0, 0);\n }\n\n private handleSetLevel(request: MatterRequests.MoveToLevel): void {\n this.log.info(`${this.config.name}: MoveToLevel request: ${JSON.stringify(request)}`);\n const { level /* transitionTime */ } = request;\n const hsv = this.getHsv();\n hsv.v = (level / 254) * 100;\n this.setHSV(hsv);\n this.log.info(`${this.config.name}: setting brightness to ${hsv.v}%.`);\n }\n\n private handleSetHueSaturation(request: { hue: number; saturation: number; transitionTime: number }): void {\n this.log.info(`${this.config.name}: MoveToHueAndSaturation request: ${JSON.stringify(request)}`);\n const { hue, saturation /* transitionTime */ } = request;\n const hsv = { h: (hue / 254) * 360, s: (saturation / 254) * 100, v: this.getBrightness() };\n this.setHSV(hsv);\n this.log.info(`${this.config.name}: setting color to h: ${hsv.h}°, s: ${hsv.s}%, v: ${hsv.v}%.`);\n }\n\n getAccessory(): MatterAccessory<Record<string, never>> {\n return this.accessory;\n }\n}\n","import type { MatterAccessory, API, Logging, PlatformConfig, DynamicPlatformPlugin } from 'homebridge';\nimport lg from 'lgpio';\n\nimport DioderAccessory from './DioderAccessory';\n\ndeclare global {\n var DEV: boolean;\n}\n\nexport interface LedConfig {\n name: string;\n rPin: number;\n gPin: number;\n bPin: number;\n freq: number;\n}\n\ninterface GradiantConfig {\n name: string;\n colors: string[];\n}\n\ninterface DioderConfig extends PlatformConfig {\n leds: LedConfig[];\n gradientAnim: GradiantConfig[];\n rainbowAnim: { enabled: boolean };\n}\n\nconst PLUGIN_NAME = '@silizia/homebridge-dioder';\n\nexport default class DioderPlatform implements DynamicPlatformPlugin {\n public readonly accessories: Map<string, MatterAccessory> = new Map();\n public readonly outdatedAccessories: MatterAccessory<Record<string, never>>[] = [];\n private gpiochip?: number;\n\n constructor(\n public readonly log: Logging,\n public readonly config: DioderConfig,\n public readonly api: API\n ) {\n this.log.debug('Finished initializing platform: Dioder');\n this.api.on('didFinishLaunching', () => {\n this.log.debug('Executed didFinishLaunching callback');\n const removedAccessories = new Map(this.accessories);\n const newAccessories: MatterAccessory[] = [];\n // DioderAccessories\n this.gpiochip = DEV ? 0 : lg.gpiochipOpen(0);\n for (const c of this.config.leds || []) {\n const uuid = this.api.matter.uuid.generate(JSON.stringify(c.name));\n const existingAccessory = this.accessories.get(uuid) as MatterAccessory<Record<string, never>>;\n if (existingAccessory) {\n removedAccessories.delete(uuid);\n this.log.info('Restoring existing accessory from cache:', existingAccessory.displayName);\n // oxlint-disable-next-line no-new\n new DioderAccessory(this.api, this.log, this.gpiochip, c, existingAccessory);\n } else {\n this.log.info('Adding new accessory:', c.name);\n const device = new DioderAccessory(this.api, this.log, this.gpiochip, c);\n newAccessories.push(device.getAccessory());\n }\n }\n // removed unused Accessories\n if (removedAccessories.size > 0) {\n const ra = Array.from(removedAccessories).map(([_k, v]) => v);\n this.log.warn(\n 'removing unused accessories',\n ra.map(a => `${a.displayName} (${a.UUID})`)\n );\n this.api.matter.unregisterPlatformAccessories(PLUGIN_NAME, 'Dioder', ra);\n }\n if (newAccessories.length > 0) {\n this.log.info(\n 'added new accessories',\n newAccessories.map(a => `${a.displayName} (${a.UUID})`)\n );\n this.api.matter.registerPlatformAccessories(PLUGIN_NAME, 'Dioder', newAccessories);\n }\n });\n this.api.on('shutdown', () => {\n if (!DEV && this.gpiochip !== undefined) {\n for (const c of this.config.leds || []) {\n lg.gpioFree(this.gpiochip, c.rPin);\n lg.gpioFree(this.gpiochip, c.gPin);\n lg.gpioFree(this.gpiochip, c.bPin);\n }\n lg.gpiochipClose(this.gpiochip);\n }\n });\n }\n\n // oxlint-disable-next-line no-empty-function, class-methods-use-this\n configureAccessory(): void {}\n\n configureMatterAccessory(accessory: MatterAccessory): void {\n this.log.info('Loading accessory from cache:', accessory.displayName, accessory.UUID);\n this.accessories.set(accessory.UUID, accessory);\n }\n}\n","import type { API } from 'homebridge';\n\nimport DioderPlatform from './DioderPlatform';\n\ninterface DioderAPI extends API {\n loadMatterAPI(): Promise<void>;\n}\n\nexport default async function main(api: DioderAPI): Promise<void> {\n await api.loadMatterAPI();\n api.registerPlatform('Dioder', DioderPlatform);\n}\n"],"mappings":";;;AAMA,MAAM,UAAU;AAChB,MAAM,gBAAgB;AACtB,MAAM,YAAY;AAElB,IAAqB,kBAArB,MAAqC;CACnC;CAEA,YACE,KACA,KACA,UACA,QACA,WACA;AALiB,OAAA,MAAA;AACA,OAAA,MAAA;AACA,OAAA,WAAA;AACA,OAAA,SAAA;AAIf,KAAG,gBAAgB,UAAU,KAAK,OAAO,KAAK;AAC9C,KAAG,gBAAgB,UAAU,KAAK,OAAO,KAAK;AAC9C,KAAG,gBAAgB,UAAU,KAAK,OAAO,KAAK;AAGhD,OAAK,YAAY,aAAa;GAC5B,MAAM,KAAK,IAAI,IAAI,KAAK,SAAS,KAAK,OAAO,KAAK;GAClD,aAAa,KAAK,OAAO;GACzB,YAAY,KAAK,IAAI,OAAO,YAAY;GACxC,cAAc;GACd,cAAc;GACd,OAAO;GACP,UAAU;IACR,OAAO,EAAE,OAAO,OAAO;IACvB,cAAc;KAAE,cAAc;KAAK,UAAU;KAAG,UAAU;KAAK;IAC/D,cAAc;KACZ,YAAY;KACZ,mBAAmB;KACnB,WAAW,KAAK,IAAI,OAAO,MAAM,aAAa,UAAU;KACxD,UAAU;KACV,UAAU;KACV,wBAAwB;KACxB,4BAA4B;KAC5B,4BAA4B;KAC5B,iCAAiC;KAClC;IACF;GACD,UAAU;IACR,OAAO;KAAE,UAAyB,KAAK,UAAU;KAAE,WAAiB,KAAK,WAAW;KAAE;IACtF,cAAc,EAAE,uBAAuB,YAAkB,KAAK,eAAe,QAAQ,EAAE;IACvF,cAAc,EAAE,8BAA8B,YAAkB,KAAK,uBAAuB,QAAQ,EAAE;IACvG;GACD,SAAS,EAAE;GACZ;;CAGH,gBAAwB;AACtB,UAAQ,KAAK,WAAW,UAAU,cAAc,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