UNPKG

homebridge-aron-airquality

Version:

homebridge plugin airquality

71 lines (53 loc) 1.94 kB
require('./Devices/WeatherService'); var package = require("./package.json"); var HomebridgeAPI; module.exports = function(homebridge) { if(!checkPlatformConfig(homebridge, "WeatherPlatform")){ return ; } HomebridgeAPI = homebridge; HomebridgeAPI.registerPlatform('homebridge-weather', 'WeatherPlatform', WeatherPlatform, true); } function checkPlatformConfig(homebridge, platform){ var configJSON = require(homebridge.user.configPath()); var platforms = configJSON.platforms; for(var i in platforms) { if(platforms[i]['platform'] === platform) { return true; } } return false; } function WeatherPlatform(log, config, api) { if(null == config) { return; } this.HomebridgeAPI = HomebridgeAPI; this.log = log; this.config = config; if (api) { this.api = api; } this.log.info("Loading v%s ",package.version); this.api.on('didFinishLaunching', function() { this.log.info("Done!"); }.bind(this)); } WeatherPlatform.prototype.accessories = function(callback) { var LoadedAccessories = []; if(this.config['hidelearn'] == false){ LoadedAccessories.push(new MiRemoteirLearn(this, this.config['learnconfig'])); } var deviceCfgs = this.config['deviceCfgs']; if(deviceCfgs instanceof Array) { for (var i = 0; i < deviceCfgs.length; i++) { var deviceCfg = deviceCfgs[i]; if(null == deviceCfg['city'] || "" == deviceCfg['city'] || null == deviceCfg['name'] || "" == deviceCfg['name']) { continue; } LoadedAccessories.push(new WeatherService(this, deviceCfg)); } this.log.info("Loaded accessories: " + LoadedAccessories.length); } callback(LoadedAccessories); }