fix: Destroy cameras after failed initialization (#1551)
This commit is contained in:
@@ -237,14 +237,18 @@ export class CameraManager {
|
|||||||
async ([cameraConfig, engine]) => await engine.createCamera(hass, cameraConfig),
|
async ([cameraConfig, engine]) => await engine.createCamera(hass, cameraConfig),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const destroyCameras = async () => {
|
||||||
|
cameras.forEach((camera) => camera.destroy());
|
||||||
|
};
|
||||||
const cameraIDs: Set<string> = new Set();
|
const cameraIDs: Set<string> = new Set();
|
||||||
|
|
||||||
// Do the additions based off the result-order, to ensure the map order is
|
// Do the additions based off the result-order, to ensure the map order is
|
||||||
// preserved.
|
// preserved.
|
||||||
cameras.forEach((camera) => {
|
for (const camera of cameras) {
|
||||||
const cameraID = getCameraID(camera.getConfig());
|
const cameraID = getCameraID(camera.getConfig());
|
||||||
|
|
||||||
if (!cameraID) {
|
if (!cameraID) {
|
||||||
|
await destroyCameras();
|
||||||
throw new CameraInitializationError(
|
throw new CameraInitializationError(
|
||||||
localize('error.no_camera_id'),
|
localize('error.no_camera_id'),
|
||||||
camera.getConfig(),
|
camera.getConfig(),
|
||||||
@@ -252,6 +256,7 @@ export class CameraManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cameraIDs.has(cameraID)) {
|
if (cameraIDs.has(cameraID)) {
|
||||||
|
await destroyCameras();
|
||||||
throw new CameraInitializationError(
|
throw new CameraInitializationError(
|
||||||
localize('error.duplicate_camera_id'),
|
localize('error.duplicate_camera_id'),
|
||||||
camera.getConfig(),
|
camera.getConfig(),
|
||||||
@@ -261,7 +266,7 @@ export class CameraManager {
|
|||||||
// Always ensure the actual ID used in the card is in the configuration itself.
|
// Always ensure the actual ID used in the card is in the configuration itself.
|
||||||
camera.setID(cameraID);
|
camera.setID(cameraID);
|
||||||
cameraIDs.add(cameraID);
|
cameraIDs.add(cameraID);
|
||||||
});
|
}
|
||||||
|
|
||||||
await this._store.setCameras(cameras);
|
await this._store.setCameras(cameras);
|
||||||
|
|
||||||
|
|||||||
@@ -57,5 +57,5 @@ div.message div.icon {
|
|||||||
|
|
||||||
.message pre {
|
.message pre {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
overflow-x: scroll;
|
overflow-x: auto;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user