@homebridge-plugins/homebridge-rainbird
Version:
The Rainbird plugin allows you to access your Rainbird device(s) from HomeKit.
27 lines • 1.21 kB
JavaScript
/**
* Creates a proxy class that instantiates the correct platform implementation
* (HAP or Matter) at runtime based on availability and user configuration.
*
* @param HAPPlatform The HAP platform class constructor.
* @param MatterPlatform The Matter platform class constructor.
* @returns A proxy class that delegates to the correct platform implementation.
*/
export function createPlatformProxy(HAPPlatform, MatterPlatform) {
return class RainbirdPlatformProxy {
/** The instantiated platform implementation (HAP or Matter) */
impl;
constructor(log, config, api) {
const preferMatter = config?.options?.preferMatter ?? true;
const enableMatter = config?.options?.enableMatter ?? true;
const matterAvailable = !!(api?.isMatterAvailable?.() && api?.isMatterEnabled?.());
if (enableMatter && preferMatter && MatterPlatform && matterAvailable) {
this.impl = new MatterPlatform(log, config, api);
return this.impl;
}
// Fallback to HAP
this.impl = new HAPPlatform(log, config, api);
return this.impl;
}
};
}
//# sourceMappingURL=utils.js.map