Files
ha_explore/backend/app/scan_state.py
2026-02-21 16:55:10 +01:00

40 lines
998 B
Python

from datetime import datetime
from typing import Optional
class ScanState:
def __init__(self):
self.status: str = "idle" # idle, scanning, done, error
self.last_scan: Optional[datetime] = None
self.progress: int = 0
self.total: int = 0
self.error: str = ""
def start(self):
self.status = "scanning"
self.progress = 0
self.total = 0
self.error = ""
def finish(self, count: int):
self.status = "done"
self.progress = count
self.total = count
self.last_scan = datetime.utcnow()
def fail(self, error: str):
self.status = "error"
self.error = error
def to_dict(self) -> dict:
return {
"scan_status": self.status,
"last_scan": self.last_scan.isoformat() if self.last_scan else None,
"progress": self.progress,
"total": self.total,
"error": self.error,
}
scan_state = ScanState()