From ac43c7781cf3f76fbee2cd0413499f08f8c88610 Mon Sep 17 00:00:00 2001 From: Luke Rhodes Date: Sat, 17 Mar 2018 23:38:37 +1100 Subject: [PATCH] Display whether there are updates to the plugin available. --- helpers/checkForUpdates.js | 21 +++++++++++++++++++++ platform.js | 5 +++++ 2 files changed, 26 insertions(+) create mode 100644 helpers/checkForUpdates.js diff --git a/helpers/checkForUpdates.js b/helpers/checkForUpdates.js new file mode 100644 index 00000000..24b3062c --- /dev/null +++ b/helpers/checkForUpdates.js @@ -0,0 +1,21 @@ +const versionCheck = require('github-version-checker'); +const pkg = require('../package.json'); + +const options = { + repo: 'lprhodes/homebridge-broadlink-rm', + currentVersion: pkg.version, + includePreReleases: false +}; + + +const checkForUpdates = (log) => { + versionCheck (options, (update, error) => { + if (error) throw error; + + if (update) { + log(`\x1b[32m[UPDATE AVAILABLE] \x1b[30mVersion ${update.tag_name} of homebridge-broadlink-rm is available: ${update.html_url}`); + } + }); +} + +module.exports = checkForUpdates; \ No newline at end of file diff --git a/platform.js b/platform.js index 6825c886..67b6a5c2 100644 --- a/platform.js +++ b/platform.js @@ -2,6 +2,7 @@ const { HomebridgePlatform } = require('homebridge-platform-helper'); const npmPackage = require('./package.json'); const Accessory = require('./accessories'); +const checkForUpdates = require('./helpers/checkForUpdates') const classTypes = { 'air-conditioner': Accessory.AirCon, @@ -27,6 +28,7 @@ const BroadlinkRMPlatform = class extends HomebridgePlatform { if (config && (config.hideWelcomeMessage || config.isUnitTest)) return; setTimeout(() => { + console.log('') console.log(`**************************************************************************************************************`) console.log(`** Welcome to version ${npmPackage.version} of the Homebridge Broadlink RM Plugin!`) console.log(`** Find out what's in the latest release here: https://github.com/lprhodes/homebridge-broadlink-rm/releases`) @@ -39,6 +41,7 @@ const BroadlinkRMPlatform = class extends HomebridgePlatform { console.log(`** You can disable this message by adding "hideWelcomeMessage": true to the config (see config-sample.json).`) console.log(`**`) console.log(`**************************************************************************************************************`) + console.log('') }, 1500) } @@ -47,6 +50,8 @@ const BroadlinkRMPlatform = class extends HomebridgePlatform { this.showMessage(); + checkForUpdates(log); + if (!config.accessories) config.accessories = [] // Add a Learn Code accessory if none exist in the config