Skip to content

Select which components to check for updates #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Configuration sample:
{
"platform": "PluginUpdate",
"sensorType": "motion",
"checkHomebridge": true,
"checkHomebridgeUI": true,
"checkPlugins": true,
"forceNcu": false
}
]
Expand All @@ -30,4 +33,9 @@ Configuration sample:

* "platform": Must always be "PluginUpdate" (required)
* "sensorType": What type of sensor will be exposed to HomeKit. Can be `motion`, `contact`, `occupancy`, `humidity`, `light`, `air`, `leak`, `smoke`, `dioxide`, or `monoxide` (Default: `motion`)
* "checkHomebridge": Check if an update is available for the Homebridge server
* "checkHomebridgeUI: Check if an update is available for the Homebridge UI
* "checkPlugins": Check if updates are available for any installed plugins
* "forceNcu": Force use of npm-check-updates instead of homebridge-config-ui-x. (Default: `false`)

Homebridge, Homebridge UI, and plugin updates can be selected independently. This allows you for example, to ignore available Homebridge, Homebridge UI available updates if you are running Homebridge in a Docker container and wish to only update these components when a new Docker image is available.
18 changes: 18 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@
}
]
},
"checkHomebridgeUpdates": {
"title": "Check for Homebridge updates",
"type": "boolean",
"description": "Check if an update is available for the Homebridge server",
"default": true
},
"checkHomebridgeUIUpdates": {
"title": "Check for Homebridge Config UI updates",
"type": "boolean",
"description": "Check if an update is available for the Homebridge UI",
"default": true
},
"checkPluginUpdates": {
"title": "Check for plugin updates",
"type": "boolean",
"description": "Check if updates are available for any installed plugins",
"default": true
},
"forceNcu": {
"title": "Force npm-check-updates",
"type": "boolean",
Expand Down
3 changes: 3 additions & 0 deletions src/configTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ export interface PluginUpdatePlatformConfig {
platform: PlatformName | PlatformIdentifier
forceNcu?: boolean
sensorType?: string
checkHomebridge?: boolean
checkHomebridgeUI?: boolean
checkPlugins?: boolean
}
44 changes: 36 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
PlatformAccessoryEvent,
} from 'homebridge'

import { UiApi } from './ui-api.js'
import { InstalledPlugin, UiApi } from './ui-api.js'

let hap: HAP
let Accessory: typeof PlatformAccessory
Expand All @@ -47,6 +47,9 @@ class PluginUpdatePlatform implements DynamicPlatformPlugin {
private readonly useNcu: boolean
private readonly isDocker: boolean
private readonly sensorInfo: SensorInfo
private readonly checkHB: boolean
private readonly checkHBUI: boolean
private readonly checkPlugins: boolean
private service?: Service
private timer?: NodeJS.Timeout

Expand All @@ -63,6 +66,10 @@ class PluginUpdatePlatform implements DynamicPlatformPlugin {
this.isDocker = fs.existsSync('/homebridge/package.json')
this.sensorInfo = this.getSensorInfo(this.config.sensorType)

this.checkHB = this.config.checkHomebridge || true;
this.checkHBUI = this.config.checkHomebridgeUI || true;
this.checkPlugins = this.config.checkPlugins || true;

api.on(APIEvent.DID_FINISH_LAUNCHING, this.addUpdateAccessory.bind(this))
}

Expand Down Expand Up @@ -118,15 +125,36 @@ class PluginUpdatePlatform implements DynamicPlatformPlugin {
}

async checkUi(): Promise<number> {
const plugins = await this.uiApi.getPlugins()
const homebridge = await this.uiApi.getHomebridge()
plugins.push(homebridge)
let updatesAvailable: InstalledPlugin[] = []

if (this.checkHB) {
const homebridge = await this.uiApi.getHomebridge()

const results = plugins.filter(plugin => plugin.updateAvailable)
this.log.debug(`homebridge-config-ui-x reports ${results.length
} outdated package(s): ${JSON.stringify(results)}`)
if (homebridge.updateAvailable) {
updatesAvailable.push(homebridge)
}
}

if (this.checkHBUI || this.checkPlugins) {
let plugins = await this.uiApi.getPlugins()

// Filter out Homebridge UI plugin
if (!this.checkHBUI) {
plugins = plugins.filter(plugin => plugin.name !== 'homebridge-config-ui-x')
}

// Select only Homebridge UI plugin
if (!this.checkPlugins) {
plugins = plugins.filter(plugin => plugin.name === 'homebridge-config-ui-x')
}

plugins = plugins.filter(plugin => plugin.updateAvailable)
updatesAvailable.push(...plugins)
}

this.log.debug(`homebridge-config-ui-x reports ${updatesAvailable.length} outdated package(s): ${JSON.stringify(updatesAvailable)}`)

return results.length
return updatesAvailable.length
}

doCheck(): void {
Expand Down
Loading