homebridge-switchbot-bluetooth-platform
Version:
A Homebridge platform Plugin for controlling SwitchBot bots using BLE (Bluetooth Low Energry)
47 lines • 1.88 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SwitchbotPlatform = void 0;
const accessoryFactory_1 = require("../accessories/accessoryFactory");
class SwitchbotPlatform {
constructor(log, config, api) {
this.logDevice = (config) => {
this.log.debug(config.type);
this.log.debug(config.name);
this.log.debug(config.address);
};
this.resolveDevicesFromConfig = () => {
const { devices } = this.config;
if (!devices) {
return [];
}
return this.config.devices
.map((config) => {
this.logDevice(config);
return this.accessoryFactory.buildFromConfig(config);
})
.filter((device) => Boolean(device));
};
this.log = log;
this.config = config;
this.api = api;
this.accessoryFactory = new accessoryFactory_1.AccessoryFactory(this.api.hap, this.log);
this.log.info('SwitchBot Platform Initializing');
}
/*
* This method is called to retrieve all accessories exposed by the platform.
* The Platform can delay the response by invoking the callback at a later time,
* it will delay the bridge startup though, so keep it to a minimum.
* The set of exposed accessories CANNOT change over the lifetime of the plugin!
*/
accessories(callback) {
const deviceList = this.resolveDevicesFromConfig();
const deviceCount = deviceList.length;
if (!deviceCount) {
this.log.error('No Devices were defined in config');
}
this.log(`Initialized SwitchBot devices. device count: ${deviceCount}`);
callback(deviceList);
}
}
exports.SwitchbotPlatform = SwitchbotPlatform;
//# sourceMappingURL=SwitchbotPlatform.js.map