feat(sfm): call-home state and enable/disable by serial -- GET /device/call_home/state, POST /device/call_home/{enable,disable} (phase 4)
- DeviceAccess.call_home_state (a read) and set_call_home (change=True: never retried, audit required for a live change, dry run without one), routed by series like start/stop. A config write is read back on its own window: up to 3 reads, 1 s apart, not the monitoring one. - Routes, serial required (422 without), all three serial-aware: the state as a dict; enable / disable through _change_response, so their statuses are start/stop's and an unconfirmed change carries sent + audit_id. The legacy GET / POST /device/call_home are unchanged (a Micromate serial is still refused there, 501). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
1 parent
453d42e32a
commit
06fa56db09
4 files changed
+233
-3
No files matched your search
@@ -425,6 +425,7 @@ _SERIAL_AWARE_PATHS = frozenset({
|
||||
"/device/info", "/device/connect", "/device/monitor/status", "/device/settings",
|
||||
"/device/events", "/device/events/download",
|
||||
"/device/monitor/start", "/device/monitor/stop",
|
||||
"/device/call_home/state", "/device/call_home/enable", "/device/call_home/disable",
|
||||
})
|
||||
|
||||
|
||||
@@ -2055,6 +2056,64 @@ def device_monitor_stop(
|
||||
# ── Call home config endpoints ───────────────────────────────────────────────
|
||||
|
||||
|
||||
@app.get("/device/call_home/state")
|
||||
def device_call_home_state(
|
||||
serial: str = Query(..., description=_SERIAL_DOC),
|
||||
host: Optional[str] = Query(None, description="TCP host — modem IP"),
|
||||
tcp_port: int = Query(DEFAULT_TCP_PORT, description=f"TCP port (default {DEFAULT_TCP_PORT})"),
|
||||
port: Optional[str] = Query(None, description="Serial port (e.g. COM5)"),
|
||||
baud: Optional[int] = Query(None, description="Serial baud rate"),
|
||||
) -> dict:
|
||||
"""The unit's call-home switch and dial string, by serial, both series (phase 4).
|
||||
|
||||
`enabled` is null when the enable byte is not a value ever measured;
|
||||
`detail` keeps `byte5` and the whole block as read."""
|
||||
return _via_device_access(lambda: _device_access().call_home_state(
|
||||
_unit_address(port, baud, host, tcp_port), serial))
|
||||
|
||||
|
||||
def _set_call_home(enabled: bool, port, baud, host, tcp_port, serial, dry_run, even_if_already, caller):
|
||||
return _change_response(lambda: _device_access().set_call_home(
|
||||
_unit_address(port, baud, host, tcp_port), serial, enabled=enabled, dry_run=dry_run,
|
||||
even_if_already=even_if_already, caller=caller or "api"))
|
||||
|
||||
|
||||
@app.post("/device/call_home/enable")
|
||||
def device_call_home_enable(
|
||||
port: Optional[str] = Query(None, description="Serial port (e.g. COM5)"),
|
||||
baud: Optional[int] = Query(None, description="Serial baud rate"),
|
||||
host: Optional[str] = Query(None, description="TCP host — modem IP"),
|
||||
tcp_port: int = Query(DEFAULT_TCP_PORT, description=f"TCP port (default {DEFAULT_TCP_PORT})"),
|
||||
serial: str = Query(..., description=_SERIAL_DOC),
|
||||
dry_run: bool = Query(False, description="Return the planned frames; send nothing"),
|
||||
even_if_already: bool = Query(False, description="Send even if call-home is already on"),
|
||||
caller: Optional[str] = Query(None, description="Who is asking (recorded in the audit row)"),
|
||||
):
|
||||
"""Turn the unit's automatic call-home ON (spec row 9), by serial, both series.
|
||||
|
||||
The same audited change as /device/monitor/start: identity read first (a
|
||||
different unit is a 409, nothing sent), the 0x2C block read, one write that
|
||||
changes only the enable byte (0x7E + 0x7F), never retried, then read back.
|
||||
Statuses as /device/monitor/start; a change that went out but was not
|
||||
confirmed carries `sent` and `audit_id`."""
|
||||
return _set_call_home(True, port, baud, host, tcp_port, serial, dry_run, even_if_already, caller)
|
||||
|
||||
|
||||
@app.post("/device/call_home/disable")
|
||||
def device_call_home_disable(
|
||||
port: Optional[str] = Query(None, description="Serial port (e.g. COM5)"),
|
||||
baud: Optional[int] = Query(None, description="Serial baud rate"),
|
||||
host: Optional[str] = Query(None, description="TCP host — modem IP"),
|
||||
tcp_port: int = Query(DEFAULT_TCP_PORT, description=f"TCP port (default {DEFAULT_TCP_PORT})"),
|
||||
serial: str = Query(..., description=_SERIAL_DOC),
|
||||
dry_run: bool = Query(False, description="Return the planned frames; send nothing"),
|
||||
even_if_already: bool = Query(False, description="Send even if call-home is already off"),
|
||||
caller: Optional[str] = Query(None, description="Who is asking (recorded in the audit row)"),
|
||||
):
|
||||
"""Turn the unit's automatic call-home OFF -- as /device/call_home/enable."""
|
||||
return _set_call_home(False, port, baud, host, tcp_port, serial, dry_run, even_if_already, caller)
|
||||
|
||||
|
||||
@app.get("/device/call_home")
|
||||
def device_call_home_get(
|
||||
port: Optional[str] = Query(None, description="Serial port (e.g. COM5)"),
|
||||
|
||||
Reference in new issue
Block a user