30 lines
1.7 KiB
Python
30 lines
1.7 KiB
Python
"""Admission for replacing the computer of an existing vehicle, never its identity."""
|
|
import time
|
|
from datetime import datetime
|
|
|
|
from .trust import PairingError
|
|
|
|
|
|
def check_replacement(fleet, row):
|
|
if row["enrollment"] == "pending":
|
|
raise PairingError("Дождитесь завершения текущей привязки БК или отзовите её.")
|
|
control = fleet.rover_control.view(row["node_id"])
|
|
if control["controlling"] or (control["fresh"] and control["snapshot"].get("state") in
|
|
("preparing", "ready", "driving", "stopping")):
|
|
raise PairingError("Сначала завершите управление аппаратом и дождитесь остановки.")
|
|
fleet.device_enrollment.prune()
|
|
if any(entry["binding"] == row["binding"]["binding_id"]
|
|
and entry["public"]["state"] in ("queued", "running")
|
|
for (vehicle_id, _), entry in fleet.device_enrollment.pending.items()
|
|
if vehicle_id == row["id"]):
|
|
raise PairingError("Дождитесь завершения подключения беспроводного устройства.")
|
|
for receipt in row.get("sensor_commands", {}).values():
|
|
if receipt.get("state") not in ("queued", "running"):
|
|
continue
|
|
try:
|
|
deadline = datetime.fromisoformat(receipt["command"]["deadline_at"].replace("Z", "+00:00")).timestamp()
|
|
except (KeyError, ValueError, TypeError):
|
|
deadline = float("inf")
|
|
if deadline > time.time():
|
|
raise PairingError("Дождитесь завершения операции с устройствами БК.")
|