feat(sfm): DeviceAccess lists and downloads events for both series

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
serversdownandClaude Haiku 5.5 committed 2026-10-21 17:02:19 -04:00
1 parent 0a01a8d2db
commit 9e2d8b62c3
3 files changed
+114 -5

No files matched your search

+19 -4
View File
@@ -10,11 +10,13 @@ import time
from typing import Any, Callable, Dict, Optional
from .errors import ConnectFailed, DeviceError, NoAnswer, WrongUnit
from .events import parse_event_id
from .locks import UnitLocks
from .models import UnitAddress, UnitInfo, UnitSettings, UnitStatus
from .models import DownloadedEvent, EventList, UnitAddress, UnitInfo, UnitSettings, UnitStatus
from .s3 import Series3Adapter, default_s3_client_factory
from .s4 import (
Series4Session, default_s4_client_factory, s4_identify, s4_settings, s4_status,
Series4Session, default_s4_client_factory, s4_download_event, s4_identify, s4_list_events,
s4_settings, s4_status,
)
from .series import normalise_serial, series_for_serial
@@ -56,6 +58,18 @@ class DeviceAccess:
def settings(self, address: UnitAddress, serial: str) -> UnitSettings:
return self._dispatch(address, serial, self._s3.settings, s4_settings)
def list_events(self, address: UnitAddress, serial: str) -> EventList:
return self._dispatch(address, serial, self._s3.list_events, s4_list_events)
def download_event(self, address: UnitAddress, serial: str, event_id: str) -> DownloadedEvent:
"""Read-only on the unit. Holds the unit for the whole download, so
other requests for it wait, then get 423."""
key, stamp = parse_event_id(event_id, serial) # BadRequest before any I/O
return self._dispatch(
address, serial,
lambda a, s: self._s3.download_event(a, s, key, stamp),
lambda c, s: s4_download_event(c, s, key, stamp))
def held_serial(self, address: UnitAddress) -> Optional[str]:
"""Serial of the OPEN held Series-4 line at this address, else None. No I/O."""
with self._sessions_guard:
@@ -99,8 +113,9 @@ class DeviceAccess:
self._forget_if_closed(address, session)
# A held line the peer dropped still reads open (the transport only
# learns at EOF), so the first request on it times out or fails.
# Call up fresh and retry ONCE. Safe only because phase 1a
# operations are reads (idempotent); writes (phase 3) must NOT
# Call up fresh and retry ONCE. Safe only because every operation
# here is a read (identify, status, settings, list, download -- all
# idempotent); writes (phase 3) must NOT
# inherit this -- a write whose ack was lost must never be sent twice.
if was_held and isinstance(exc, (NoAnswer, ConnectFailed)):
self._drop(address.key, session)
+7 -1
View File
@@ -14,7 +14,9 @@ from micromate.client import MicromateClient
from micromate.protocol import THOR_CHUNK_SIZE
from minimateplus.transport import BaseTransport, SerialTransport, TcpTransport
from .errors import CallHomeInProgress, EventNotFound, MalformedReply, StaleEvent, WrongUnit, translate
from .errors import (
CallHomeInProgress, DeviceError, EventNotFound, MalformedReply, StaleEvent, WrongUnit, translate,
)
from .events import iso_of, make_event_id, stamp_of
from .models import DownloadedEvent, EventList, EventRef, UnitAddress, UnitInfo, UnitSettings, UnitStatus
from .series import normalise_serial
@@ -157,6 +159,10 @@ class Series4Session:
log.warning("RADIO RING from %s -- released the line so the call reaches THOR",
self.address.key)
raise CallHomeInProgress(_RING_MESSAGE) from exc
except DeviceError:
# The operation's own verdict (event not found, stale id): the line
# is healthy, so keep it. Library errors still hang up below.
raise
except Exception as exc:
self.hang_up()
raise translate(exc, connecting=False) from exc