Skip to content

Commit 5cb70bb

Browse files
authored
Filter Out Disabled Update Notifications from Available Updates (#188)
1 parent 564f323 commit 5cb70bb

File tree

3 files changed

+114
-20
lines changed

3 files changed

+114
-20
lines changed

src/ignore-plugins.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,45 @@ describe('Plugin Update Filtering', () => {
102102
expect(ignoredWithUpdates).toHaveLength(1)
103103
expect(ignoredWithUpdates[0].name).toBe('homebridge-plugin-ignored')
104104
})
105+
106+
it('should filter homebridge-config-ui-x when in ignore list', () => {
107+
const mockPlugins = [
108+
{
109+
name: 'homebridge-config-ui-x',
110+
installedVersion: '4.0.0',
111+
latestVersion: '4.1.0',
112+
updateAvailable: true,
113+
},
114+
]
115+
116+
const ignoredPlugins = ['homebridge-config-ui-x']
117+
118+
// Test filtering homebridge-config-ui-x updates when ignored
119+
const shouldFilterUI = ignoredPlugins.includes('homebridge-config-ui-x')
120+
expect(shouldFilterUI).toBe(true)
121+
122+
// Simulate what would happen in the checkUi() method
123+
const uiPlugin = mockPlugins.find(plugin => plugin.name === 'homebridge-config-ui-x')
124+
const shouldAddUpdate = uiPlugin && uiPlugin.updateAvailable && !shouldFilterUI
125+
expect(shouldAddUpdate).toBe(false)
126+
})
127+
128+
it('should filter homebridge core updates when in ignore list', () => {
129+
const mockHomebridge = {
130+
name: 'homebridge',
131+
installedVersion: '1.0.0',
132+
latestVersion: '1.1.0',
133+
updateAvailable: true,
134+
}
135+
136+
const ignoredPlugins = ['homebridge']
137+
138+
// Test filtering homebridge core updates when ignored
139+
const shouldFilterHomebridge = ignoredPlugins.includes('homebridge')
140+
expect(shouldFilterHomebridge).toBe(true)
141+
142+
// Simulate what would happen in the checkUi() method
143+
const shouldAddUpdate = mockHomebridge.updateAvailable && !shouldFilterHomebridge
144+
expect(shouldAddUpdate).toBe(false)
145+
})
105146
})

src/index.ts

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -170,50 +170,74 @@ class PluginUpdatePlatform implements DynamicPlatformPlugin {
170170

171171
let logLevel = (this.firstDailyRun === true) ? LogLevel.INFO : LogLevel.DEBUG
172172
const updatesAvailable: InstalledPlugin[] = []
173+
174+
// Get ignored plugins from API if respectDisabledPlugins is enabled
175+
let ignoredPlugins: string[] = []
176+
if (this.respectDisabledPlugins) {
177+
try {
178+
ignoredPlugins = await this.uiApi.getIgnoredPlugins()
179+
this.log.debug(`Retrieved ${ignoredPlugins.length} ignored plugin(s) from homebridge-config-ui-x: ${ignoredPlugins.join(', ')}`)
180+
} catch (error) {
181+
this.log.warn(`Failed to retrieve ignored plugins list, filtering disabled: ${error}`)
182+
ignoredPlugins = []
183+
}
184+
} else {
185+
this.log.debug('respectDisabledPlugins is disabled, skipping plugin filtering')
186+
}
173187

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

177191
if (homebridge.updateAvailable) {
178-
updatesAvailable.push(homebridge)
192+
// Check if homebridge core updates are ignored
193+
const isIgnored = this.respectDisabledPlugins && ignoredPlugins.includes('homebridge')
194+
195+
if (!isIgnored) {
196+
updatesAvailable.push(homebridge)
179197

180-
const version: string = homebridge.latestVersion
198+
const version: string = homebridge.latestVersion
181199

182-
if (this.hbUpdates.length === 0 || !this.hbUpdates.includes(version)) logLevel = LogLevel.INFO
183-
this.log.log(logLevel, `Homebridge update available: ${version}`)
200+
if (this.hbUpdates.length === 0 || !this.hbUpdates.includes(version)) logLevel = LogLevel.INFO
201+
this.log.log(logLevel, `Homebridge update available: ${version}`)
184202

185-
this.hbUpdates = [version]
203+
this.hbUpdates = [version]
204+
} else {
205+
this.log.debug(`Ignoring Homebridge core update: ${homebridge.latestVersion} (update notifications disabled in homebridge-config-ui-x)`)
206+
}
186207
}
187208
}
188209

189210
if (this.checkHBUI || this.checkPlugins) {
190211
const plugins = await this.uiApi.getPlugins()
191-
let ignoredPlugins: string[] = []
192-
193-
// Get ignored plugins from API if respectDisabledPlugins is enabled
194-
if (this.respectDisabledPlugins) {
195-
ignoredPlugins = await this.uiApi.getIgnoredPlugins()
196-
}
197212

198213
if (this.checkHBUI) {
199214
const homebridgeUiPlugins = plugins.filter(plugin => plugin.name === 'homebridge-config-ui-x')
200215

201216
// Only one plugin is returned
202217
homebridgeUiPlugins.forEach((homebridgeUI) => {
203218
if (homebridgeUI.updateAvailable) {
204-
updatesAvailable.push(homebridgeUI)
219+
// Check if homebridge-config-ui-x updates are ignored
220+
const isIgnored = this.respectDisabledPlugins && ignoredPlugins.includes('homebridge-config-ui-x')
221+
222+
if (!isIgnored) {
223+
updatesAvailable.push(homebridgeUI)
205224

206-
const version: string = homebridgeUI.latestVersion
225+
const version: string = homebridgeUI.latestVersion
207226

208-
if (this.hbUIUpdates.length === 0 || !this.hbUIUpdates.includes(version)) logLevel = LogLevel.INFO
209-
this.log.log(logLevel, `Homebridge UI update available: ${version}`)
227+
if (this.hbUIUpdates.length === 0 || !this.hbUIUpdates.includes(version)) logLevel = LogLevel.INFO
228+
this.log.log(logLevel, `Homebridge UI update available: ${version}`)
210229

211-
this.hbUIUpdates = [version]
230+
this.hbUIUpdates = [version]
231+
} else {
232+
this.log.debug(`Ignoring Homebridge UI update: ${homebridgeUI.latestVersion} (update notifications disabled in homebridge-config-ui-x)`)
233+
}
212234
}
213235
})
214236
}
215237

216238
if (this.checkPlugins) {
239+
this.log.debug(`Checking ${plugins.length} plugins for updates (respectDisabledPlugins: ${this.respectDisabledPlugins})`)
240+
217241
const filteredPlugins = plugins.filter(plugin => {
218242
// Always exclude homebridge-config-ui-x
219243
if (plugin.name === 'homebridge-config-ui-x') {
@@ -223,13 +247,16 @@ class PluginUpdatePlatform implements DynamicPlatformPlugin {
223247
// If respectDisabledPlugins is enabled, check API ignored list
224248
if (this.respectDisabledPlugins) {
225249
if (ignoredPlugins.includes(plugin.name)) {
250+
this.log.debug(`Filtering out plugin ${plugin.name} (ignored in homebridge-config-ui-x)`)
226251
return false
227252
}
228253
}
229254

230255
return true
231256
})
232257

258+
this.log.debug(`After filtering: ${filteredPlugins.length} plugins to check for updates`)
259+
233260
filteredPlugins.forEach((plugin) => {
234261
if (plugin.updateAvailable) {
235262
updatesAvailable.push(plugin)
@@ -251,7 +278,7 @@ class PluginUpdatePlatform implements DynamicPlatformPlugin {
251278
ignoredPlugins.includes(plugin.name)
252279
)
253280
if (ignoredWithUpdates.length > 0) {
254-
this.log.debug(`Ignoring updates for ${ignoredWithUpdates.length} plugin(s): ${ignoredWithUpdates.map(p => p.name).join(', ')}`)
281+
this.log.info(`Ignoring updates for ${ignoredWithUpdates.length} plugin(s): ${ignoredWithUpdates.map(p => p.name).join(', ')}`)
255282
}
256283
}
257284
}
@@ -273,6 +300,15 @@ class PluginUpdatePlatform implements DynamicPlatformPlugin {
273300
}
274301

275302
this.log.log(logLevel, `Found ${updatesAvailable.length} available update(s)`)
303+
304+
// Provide additional diagnostic information in debug mode
305+
if (this.respectDisabledPlugins && ignoredPlugins.length > 0) {
306+
this.log.debug(`Filtering enabled with ${ignoredPlugins.length} ignored plugins: ${ignoredPlugins.join(', ')}`)
307+
} else if (this.respectDisabledPlugins) {
308+
this.log.debug('Filtering enabled but no ignored plugins found')
309+
} else {
310+
this.log.debug('Plugin filtering is disabled (respectDisabledPlugins: false)')
311+
}
276312

277313
return updatesAvailable.length
278314
}

src/ui-api.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,29 @@ export class UiApi {
122122
public async getIgnoredPlugins(): Promise<Array<string>> {
123123
if (this.isConfigured()) {
124124
try {
125-
return await this.makeCall('/config-editor/ui/plugins/hide-updates-for') as Array<string>
126-
} catch (error) {
127-
this.log.warn(`Failed to retrieve ignored plugins list: ${error}`)
125+
this.log.debug('Calling /config-editor/ui/plugins/hide-updates-for API endpoint')
126+
const result = await this.makeCall('/config-editor/ui/plugins/hide-updates-for')
127+
128+
// Validate the response format
129+
if (!Array.isArray(result)) {
130+
this.log.warn(`Unexpected response format from ignored plugins API: ${typeof result}, expected array`)
131+
return []
132+
}
133+
134+
const ignoredPlugins = result as Array<string>
135+
this.log.debug(`API returned ${ignoredPlugins.length} ignored plugins: ${ignoredPlugins.join(', ')}`)
136+
return ignoredPlugins
137+
} catch (error: any) {
138+
// Check if it's a 404 error (API endpoint doesn't exist)
139+
if (error?.response?.status === 404) {
140+
this.log.warn('Ignored plugins API endpoint not found - requires homebridge-config-ui-x v5.6.2-beta.2 or later')
141+
} else {
142+
this.log.warn(`Failed to retrieve ignored plugins list from /config-editor/ui/plugins/hide-updates-for: ${error}`)
143+
}
128144
return []
129145
}
130146
} else {
147+
this.log.debug('homebridge-config-ui-x not configured, cannot retrieve ignored plugins list')
131148
return []
132149
}
133150
}

0 commit comments

Comments
 (0)