Skip to content

Commit

Permalink
fix: Destroy cameras after failed initialization (#1551)
Browse files Browse the repository at this point in the history
  • Loading branch information
dermotduffy committed Sep 21, 2024
1 parent 5481c59 commit 15d33f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/camera-manager/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,26 @@ 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(),
);
}

if (cameraIDs.has(cameraID)) {
await destroyCameras();
throw new CameraInitializationError(
localize('error.duplicate_camera_id'),
camera.getConfig(),
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/scss/message.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ div.message div.icon {

.message pre {
margin-top: 20px;
overflow-x: scroll;
overflow-x: auto;
}

0 comments on commit 15d33f6

Please sign in to comment.