@homebridge-plugins/homebridge-roomba
Version:
homebridge-plugin for Roomba devices
36 lines • 1.6 kB
JavaScript
import RoombaPlatform from './Platform.HAP.js';
import RoombaMatterPlatform from './Platform.Matter.js';
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js';
/**
* Creates a proxy constructor that instantiates the correct platform
* implementation — Matter or HAP — depending on runtime availability
* and the user's configuration.
*
* - If `enableMatter` is `false` in the config, HAP is always used.
* - If Matter is available and enabled on the Homebridge host, the Matter
* platform is used; otherwise the HAP platform is used.
* - If Matter platform initialization throws, HAP is used as a fallback.
*/
export function createPlatformProxy(HAPPlatform, MatterPlatform) {
return class RoombaPlatformProxy {
constructor(log, config, api) {
const enableMatter = config.enableMatter !== false;
const matterAvailable = !!(api?.isMatterAvailable?.() && api?.isMatterEnabled?.());
if (enableMatter && matterAvailable) {
try {
return new MatterPlatform(log, config, api);
}
catch (error) {
log.warn(`Matter platform failed to initialize, falling back to HAP: ${error?.message ?? error}`);
}
}
return new HAPPlatform(log, config, api);
}
};
}
// Register our platform with homebridge.
export default (api) => {
const ProxyCtor = createPlatformProxy(RoombaPlatform, RoombaMatterPlatform);
api.registerPlatform(PLUGIN_NAME, PLATFORM_NAME, ProxyCtor);
};
//# sourceMappingURL=index.js.map