Skip to content

Commit

Permalink
Zigbee2mqtt : Remove containers when disabling integration (GladysAss…
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles authored and cicoub13 committed Oct 15, 2024
1 parent 5903f5e commit c4bd1a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions server/services/zigbee2mqtt/lib/disconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,28 @@ async function disconnect() {
this.gladysConnected = false;
this.emitStatusEvent();

// Stop MQTT container
// Stop & remove MQTT container
let dockerContainer = await this.gladys.system.getContainers({
all: true,
filters: { name: [mqttContainerDescriptor.name] },
});
if (dockerContainer.length > 0) {
[container] = dockerContainer;
await this.gladys.system.stopContainer(container.id);
await this.gladys.system.removeContainer(container.id);
}
this.mqttRunning = false;
this.emitStatusEvent();

// Stop zigbee2mqtt container
// Stop & remove zigbee2mqtt container
dockerContainer = await this.gladys.system.getContainers({
all: true,
filters: { name: [zigbee2mqttContainerDescriptor.name] },
});
if (dockerContainer.length > 0) {
[container] = dockerContainer;
await this.gladys.system.stopContainer(container.id);
await this.gladys.system.removeContainer(container.id);
}
this.zigbee2mqttRunning = false;
this.zigbee2mqttConnected = false;
Expand Down
3 changes: 3 additions & 0 deletions server/test/services/zigbee2mqtt/lib/disconnect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('zigbee2mqtt disconnect', () => {
system: {
getContainers: fake.resolves([container]),
stopContainer: fake.resolves(true),
removeContainer: fake.resolves(true),
},
};

Expand Down Expand Up @@ -71,6 +72,7 @@ describe('zigbee2mqtt disconnect', () => {
},
});
assert.calledTwice(gladys.system.stopContainer);
assert.calledTwice(gladys.system.removeContainer);
});

it('mqtt connected', async () => {
Expand All @@ -96,6 +98,7 @@ describe('zigbee2mqtt disconnect', () => {
},
});
assert.calledTwice(gladys.system.stopContainer);
assert.calledTwice(gladys.system.removeContainer);
assert.calledOnce(mqtt.end);
assert.calledOnce(mqtt.removeAllListeners);

Expand Down

0 comments on commit c4bd1a6

Please sign in to comment.