@@ -47,6 +47,7 @@ export class PluginBridgeComponent implements OnInit {
47
47
public showConfigFields : boolean [ ] = [ ]
48
48
public saveInProgress = false
49
49
public canShowBridgeDebug = false
50
+ public deleteBridgeIds : string [ ] = [ ]
50
51
51
52
constructor ( ) { }
52
53
@@ -85,6 +86,9 @@ export class PluginBridgeComponent implements OnInit {
85
86
86
87
async toggleExternalBridge ( block : any , enable : boolean , index : number ) {
87
88
if ( ! enable ) {
89
+ // Store unpaired child bridge id for deletion, so no bridges are orphaned
90
+ this . deleteBridgeIds . push ( block . _bridge . username )
91
+
88
92
delete block . _bridge
89
93
return
90
94
}
@@ -102,6 +106,10 @@ export class PluginBridgeComponent implements OnInit {
102
106
env : bridgeCache ?. env ,
103
107
}
104
108
109
+ if ( this . deleteBridgeIds . includes ( block . _bridge . username ) ) {
110
+ this . deleteBridgeIds = this . deleteBridgeIds . filter ( id => id !== block . _bridge . username )
111
+ }
112
+
105
113
this . bridgeCache . set ( index , block . _bridge )
106
114
await this . getDeviceInfo ( block . _bridge . username )
107
115
}
@@ -132,6 +140,17 @@ export class PluginBridgeComponent implements OnInit {
132
140
133
141
try {
134
142
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
+
135
154
this . $activeModal . close ( )
136
155
this . $modal . open ( RestartHomebridgeComponent , {
137
156
size : 'lg' ,
0 commit comments