Skip to content

Commit

Permalink
Display whether there are updates to the plugin available.
Browse files Browse the repository at this point in the history
  • Loading branch information
lprhodes committed Mar 17, 2018
1 parent cfb86ad commit ac43c77
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions helpers/checkForUpdates.js
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 5 additions & 0 deletions platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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`)
Expand All @@ -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)
}

Expand All @@ -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
Expand Down

0 comments on commit ac43c77

Please sign in to comment.