This commit is contained in:
2026-06-02 14:02:09 +05:00
parent f263d84a8d
commit 847c87fd7e
9 changed files with 79 additions and 29 deletions
+23
View File
@@ -89,6 +89,29 @@ class Config:
def enabled_cameras(self) -> list[Camera]:
return [c for c in self.cameras if c.enabled]
# ── слоты записи ────────────────────────────────────────────
# Папка камеры в хранилище = номер её слота (позиция в списке, 1-based) с
# ведущим нулём: слот 5 → «05», слот 12 → «12». Так совпадает со столбцом ID в UI.
def slot_of(self, cam_id: str) -> int | None:
for i, c in enumerate(self.cameras, start=1):
if c.id == cam_id:
return i
return None
def archive_dir(self, cam_id: str) -> str:
"""Имя подпапки записи камеры в хранилище. Откат на id, если камеры нет в списке."""
slot = self.slot_of(cam_id)
return f"{slot:02d}" if slot is not None else cam_id
def camera_by_archive_dir(self, name: str) -> Camera | None:
"""Обратное: имя папки-слота («05») → камера в этом слоте. None для нечисловых
(легаси-папки по старому id индексируются под своим именем как раньше)."""
if name.isdigit():
idx = int(name)
if 1 <= idx <= len(self.cameras):
return self.cameras[idx - 1]
return None
# ── хранилища ───────────────────────────────────────────────
def storage_by_id(self, sid: str) -> StorageItem | None:
return next((s for s in self.storage.items if s.id == sid), None)