Skip to content

Commit

Permalink
delete unpaired bridges when toggling bridges off
Browse files Browse the repository at this point in the history
  • Loading branch information
justjam2013 authored and bwp91 committed Dec 25, 2024
1 parent 0771c29 commit 35da722
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ All notable changes to `homebridge-config-ui-x` will be documented in this file.

- format svg files nicely as part of lint
- upgrade angular from `v18` to `v19`
- delete unpaired bridges when toggling bridges off (#2284) (@justjam2013) (fixes [#2257](https://github.com/homebridge/homebridge-config-ui-x/issues/2257))

## v4.65.2 (2024-12-15)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class PluginBridgeComponent implements OnInit {
public showConfigFields: boolean[] = []
public saveInProgress = false
public canShowBridgeDebug = false
public deleteBridgeIds: string[] = []

constructor() {}

Expand Down Expand Up @@ -85,6 +86,9 @@ export class PluginBridgeComponent implements OnInit {

async toggleExternalBridge(block: any, enable: boolean, index: number) {
if (!enable) {
// Store unpaired child bridge id for deletion, so no bridges are orphaned
this.deleteBridgeIds.push(block._bridge.username)

delete block._bridge
return
}
Expand All @@ -102,6 +106,10 @@ export class PluginBridgeComponent implements OnInit {
env: bridgeCache?.env,
}

if (this.deleteBridgeIds.includes(block._bridge.username)) {
this.deleteBridgeIds = this.deleteBridgeIds.filter(id => id !== block._bridge.username)
}

this.bridgeCache.set(index, block._bridge)
await this.getDeviceInfo(block._bridge.username)
}
Expand Down Expand Up @@ -132,6 +140,17 @@ export class PluginBridgeComponent implements OnInit {

try {
await firstValueFrom(this.$api.post(`/config-editor/plugin/${encodeURIComponent(this.plugin.name)}`, this.configBlocks))

// Delete unpaired bridges, so no bridges are orphaned
for (const childBridgeId of this.deleteBridgeIds) {
try {
await firstValueFrom(this.$api.delete(`/server/pairings/${childBridgeId.replace(/:/g, '')}`))
} catch (error) {
console.error(error)
this.$toastr.error(this.$translate.instant('settings.unpair_bridge.unpair_error'), this.$translate.instant('toast.title_error'))
}
}

this.$activeModal.close()
this.$modal.open(RestartHomebridgeComponent, {
size: 'lg',
Expand Down

0 comments on commit 35da722

Please sign in to comment.