Skip to content

Commit 35da722

Browse files
justjam2013bwp91
authored andcommitted
delete unpaired bridges when toggling bridges off
1 parent 0771c29 commit 35da722

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ All notable changes to `homebridge-config-ui-x` will be documented in this file.
1414

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

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

ui/src/app/core/manage-plugins/plugin-bridge/plugin-bridge.component.ts

+19
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class PluginBridgeComponent implements OnInit {
4747
public showConfigFields: boolean[] = []
4848
public saveInProgress = false
4949
public canShowBridgeDebug = false
50+
public deleteBridgeIds: string[] = []
5051

5152
constructor() {}
5253

@@ -85,6 +86,9 @@ export class PluginBridgeComponent implements OnInit {
8586

8687
async toggleExternalBridge(block: any, enable: boolean, index: number) {
8788
if (!enable) {
89+
// Store unpaired child bridge id for deletion, so no bridges are orphaned
90+
this.deleteBridgeIds.push(block._bridge.username)
91+
8892
delete block._bridge
8993
return
9094
}
@@ -102,6 +106,10 @@ export class PluginBridgeComponent implements OnInit {
102106
env: bridgeCache?.env,
103107
}
104108

109+
if (this.deleteBridgeIds.includes(block._bridge.username)) {
110+
this.deleteBridgeIds = this.deleteBridgeIds.filter(id => id !== block._bridge.username)
111+
}
112+
105113
this.bridgeCache.set(index, block._bridge)
106114
await this.getDeviceInfo(block._bridge.username)
107115
}
@@ -132,6 +140,17 @@ export class PluginBridgeComponent implements OnInit {
132140

133141
try {
134142
await firstValueFrom(this.$api.post(`/config-editor/plugin/${encodeURIComponent(this.plugin.name)}`, this.configBlocks))
143+
144+
// Delete unpaired bridges, so no bridges are orphaned
145+
for (const childBridgeId of this.deleteBridgeIds) {
146+
try {
147+
await firstValueFrom(this.$api.delete(`/server/pairings/${childBridgeId.replace(/:/g, '')}`))
148+
} catch (error) {
149+
console.error(error)
150+
this.$toastr.error(this.$translate.instant('settings.unpair_bridge.unpair_error'), this.$translate.instant('toast.title_error'))
151+
}
152+
}
153+
135154
this.$activeModal.close()
136155
this.$modal.open(RestartHomebridgeComponent, {
137156
size: 'lg',

0 commit comments

Comments
 (0)