fix: Destroy cameras after failed initialization (#1551)

This commit is contained in:
Dermot Duffy
2024-09-21 13:17:22 -07:00
committed by GitHub
parent 5481c5956c
commit 15d33f63fb
2 changed files with 8 additions and 3 deletions
+7 -2
View File
@@ -237,14 +237,18 @@ export class CameraManager {
async ([cameraConfig, engine]) => await engine.createCamera(hass, cameraConfig),
);
const destroyCameras = async () => {
cameras.forEach((camera) => camera.destroy());
};
const cameraIDs: Set<string> = new Set();
// Do the additions based off the result-order, to ensure the map order is
// preserved.
cameras.forEach((camera) => {
for (const camera of cameras) {
const cameraID = getCameraID(camera.getConfig());
if (!cameraID) {
await destroyCameras();
throw new CameraInitializationError(
localize('error.no_camera_id'),
camera.getConfig(),
@@ -252,6 +256,7 @@ export class CameraManager {
}
if (cameraIDs.has(cameraID)) {
await destroyCameras();
throw new CameraInitializationError(
localize('error.duplicate_camera_id'),
camera.getConfig(),
@@ -261,7 +266,7 @@ export class CameraManager {
// Always ensure the actual ID used in the card is in the configuration itself.
camera.setID(cameraID);
cameraIDs.add(cameraID);
});
}
await this._store.setCameras(cameras);
+1 -1
View File
@@ -57,5 +57,5 @@ div.message div.icon {
.message pre {
margin-top: 20px;
overflow-x: scroll;
overflow-x: auto;
}