feat(sfm): Series-4 identify, status and settings into the shared models
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
8e7333b899
commit
ece9ec79e3
2 files changed
+85
-1
No files matched your search
+54
-1
@@ -14,7 +14,7 @@ from micromate.client import MicromateClient
|
||||
from minimateplus.transport import BaseTransport, SerialTransport, TcpTransport
|
||||
|
||||
from .errors import CallHomeInProgress, WrongUnit, translate
|
||||
from .models import UnitAddress
|
||||
from .models import UnitAddress, UnitInfo, UnitSettings, UnitStatus
|
||||
from .series import normalise_serial
|
||||
|
||||
log = logging.getLogger("sfm.device_access")
|
||||
@@ -162,3 +162,56 @@ class Series4Session:
|
||||
_close(self._client)
|
||||
self._client = None
|
||||
log.info("hang-up: %s at %s", self.serial, self.address.key)
|
||||
|
||||
|
||||
# ── Operations (each runs inside Series4Session.run) ──────────────────────────
|
||||
|
||||
def s4_identify(client: Any, serial: str) -> UnitInfo:
|
||||
info = client.connect()
|
||||
return UnitInfo(
|
||||
serial=info.serial, series=4, model=info.model,
|
||||
firmware=None, # the version string lives in 0x01, undecoded
|
||||
monitoring=info.monitoring, active_setup=info.active_setup,
|
||||
detail={"manufacturer": info.manufacturer, "firmware_line": info.firmware_line},
|
||||
)
|
||||
|
||||
|
||||
def s4_status(client: Any, serial: str) -> UnitStatus:
|
||||
st = client.get_state()
|
||||
count = client.get_event_count()
|
||||
return UnitStatus(
|
||||
serial=serial, series=4, monitoring=st.monitoring, battery_volts=st.battery_volts,
|
||||
memory_total_bytes=st.memory_total_bytes, memory_free_bytes=st.memory_free_bytes,
|
||||
device_time=st.device_time.isoformat() if st.device_time else None,
|
||||
event_count=count,
|
||||
)
|
||||
|
||||
|
||||
def s4_settings(client: Any, serial: str) -> UnitSettings:
|
||||
s = client.get_setup()
|
||||
return UnitSettings(
|
||||
serial=serial, series=4, setup_name=s.name, record_mode=s.record_mode_name,
|
||||
sample_rate=s.sample_rate, record_time_s=s.record_time_s,
|
||||
histogram_interval_s=s.histogram_interval_s,
|
||||
geo_trigger_ips=s.geo_trigger_ips[0], # the keypad writes all three the same
|
||||
notes=dict(s.notes),
|
||||
detail={
|
||||
"pretrigger_s": s.pretrigger_s,
|
||||
"auto_record_stop": s.auto_record_stop,
|
||||
"auto_stop_after_s": s.auto_stop_after_s,
|
||||
"geophones_active": s.geophones_active,
|
||||
"mic_active": s.mic_active,
|
||||
"trigger_on_geophones": s.trigger_on_geophones,
|
||||
"trigger_on_mic": s.trigger_on_mic,
|
||||
"geo_trigger_ips_per_channel": list(s.geo_trigger_ips),
|
||||
"mic_type": s.mic_type,
|
||||
"mic_trigger_psi": s.mic_trigger_psi,
|
||||
"mic_trigger_db": s.mic_trigger_db,
|
||||
"job_number_enabled": s.job_number_enabled,
|
||||
"job_number": s.job_number,
|
||||
"scaled_distance_enabled": s.scaled_distance_enabled,
|
||||
"distance_ft": s.distance_ft,
|
||||
"charge_weight_lb": s.charge_weight_lb,
|
||||
"scaled_distance": s.scaled_distance,
|
||||
},
|
||||
)
|
||||
@@ -179,3 +179,34 @@ def test_a_failure_mid_request_hangs_up():
|
||||
with pytest.raises(NoAnswer):
|
||||
s.run(lambda c: c.get_state())
|
||||
assert not s.is_open
|
||||
|
||||
|
||||
# ── operations ────────────────────────────────────────────────────────────────
|
||||
|
||||
from sfm.device_access.s4 import s4_identify, s4_settings, s4_status # noqa: E402
|
||||
|
||||
|
||||
def test_s4_identify():
|
||||
info = s4_identify(FakeMicromateClient(monitoring=True), "UM20147")
|
||||
assert (info.serial, info.series, info.model, info.monitoring) == ("UM20147", 4, "MM/ISEE/S", True)
|
||||
assert info.active_setup == "test2.MMB"
|
||||
assert info.firmware is None and info.detail["firmware_line"] == "thor"
|
||||
|
||||
|
||||
def test_s4_status_includes_the_cheap_event_count():
|
||||
st = s4_status(FakeMicromateClient(events=5), "UM20147")
|
||||
assert (st.series, st.monitoring, st.battery_volts, st.event_count) == (4, False, 3.8, 5)
|
||||
assert (st.memory_total_bytes, st.memory_free_bytes) == (15_000_000, 14_799_296)
|
||||
assert st.device_time == "2026-10-20T18:07:58"
|
||||
|
||||
|
||||
def test_s4_settings_maps_the_decoded_setup():
|
||||
s = s4_settings(FakeMicromateClient(), "UM20147")
|
||||
assert (s.series, s.setup_name, s.record_mode) == (4, "test2.MMB", "Histogram Combo")
|
||||
assert (s.sample_rate, s.record_time_s, s.histogram_interval_s) == (1024, 10.0, 2)
|
||||
assert s.geo_trigger_ips == pytest.approx(0.5, abs=1e-6)
|
||||
assert list(s.notes) == ["Location", "Client", "Company", "General Notes"]
|
||||
assert s.detail["pretrigger_s"] == 1.0
|
||||
assert s.detail["mic_type"] == "linear"
|
||||
assert s.detail["mic_trigger_db"] == pytest.approx(131.0, abs=0.01)
|
||||
assert s.detail["geo_trigger_ips_per_channel"] == pytest.approx([0.5, 0.5, 0.5], abs=1e-6)
|
||||
Reference in new issue
Block a user