UNPKG

homebridge-switchbot-bluetooth-platform

Version:

A Homebridge platform Plugin for controlling SwitchBot bots using BLE (Bluetooth Low Energry)

45 lines 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AccessoryFactory = void 0; const settings_1 = require("../settings"); const botAccessory_1 = require("./botAccessory"); class AccessoryFactory { constructor(hap, log) { this.hap = hap; this.log = log; } adaptAccessoryConfig(config) { const { scanDuration = settings_1.DEFAULT_SCAN_DURATION, scanRetries = settings_1.DEFAULT_SCAN_RETRIES, scanRetryCooldown = settings_1.DEFAULT_SCAN_RETRY_COOLDOWN, autoTurnOffInPressMode = settings_1.DEFAULT_AUTO_OFF_IN_PRESS_MODE, } = config; return { ...config, address: config.address.toLowerCase().trim(), scanDuration, scanRetries, scanRetryCooldown, autoTurnOffInPressMode, }; } buildFromConfig(config) { try { const { name, type } = config; const accessoryParams = this.adaptAccessoryConfig(config); switch (type) { case 'bot': return new botAccessory_1.BotAccessory(name, this.hap, this.log, accessoryParams); case 'contact': case 'curtain': case 'meter': case 'motion': default: this.log.error(`Accessory type '${type}' is not supported`); return null; } } catch (e) { this.log.error(`An error has occoured while building acessory from config. ${e}`); return null; } } } exports.AccessoryFactory = AccessoryFactory; //# sourceMappingURL=accessoryFactory.js.map