Add offline and ntfy alerts
Co-authored-by: Copilot <[email protected]>
This commit is contained in:
@@ -274,6 +274,47 @@ def _mounted_source(partition, mount_point, read_only):
|
||||
return mount_point, True, False
|
||||
|
||||
|
||||
def dashcam_storage_usage(mount_point=DEFAULT_MOUNT_POINT):
|
||||
with _device_lock:
|
||||
partition = find_dashcam_partition()
|
||||
if partition is None:
|
||||
return {"status": "no_device"}
|
||||
source, mounted_here, _remounted = _mounted_source(
|
||||
partition, mount_point, read_only=True
|
||||
)
|
||||
if source is None:
|
||||
return {
|
||||
"status": "mount_failed",
|
||||
"path": partition["path"],
|
||||
}
|
||||
try:
|
||||
usage = shutil.disk_usage(source)
|
||||
used_percent = round(
|
||||
usage.used / (usage.used + usage.free) * 100, 1
|
||||
)
|
||||
result = {
|
||||
"status": "ok",
|
||||
"path": partition["path"],
|
||||
"total_bytes": usage.total,
|
||||
"used_bytes": usage.used,
|
||||
"free_bytes": usage.free,
|
||||
"used_percent": used_percent,
|
||||
}
|
||||
except OSError as error:
|
||||
result = {
|
||||
"status": "read_failed",
|
||||
"path": partition["path"],
|
||||
"error": str(error),
|
||||
}
|
||||
finally:
|
||||
if mounted_here and not unmount_device(mount_point):
|
||||
result = {
|
||||
"status": "unmount_failed",
|
||||
"path": partition["path"],
|
||||
}
|
||||
return result
|
||||
|
||||
|
||||
def list_dashcam_files(mount_point=DEFAULT_MOUNT_POINT):
|
||||
"""List video files on the detected dashcam without copying them."""
|
||||
with _device_lock:
|
||||
|
||||
Reference in New Issue
Block a user