feat(da12): record updated_at on SensorRecord when a value arrives
This commit is contained in:
@@ -20,10 +20,12 @@ class SensorTable:
|
||||
if 1 <= rec.id <= MAX_CHANNELS:
|
||||
self._rows[rec.id] = rec
|
||||
|
||||
def apply_current(self, sid: int, value: float | None) -> None:
|
||||
def apply_current(self, sid: int, value: float | None, *, at: float | None = None) -> None:
|
||||
rec = self._rows.get(sid)
|
||||
if rec is not None:
|
||||
rec.value = value
|
||||
if at is not None:
|
||||
rec.updated_at = at
|
||||
|
||||
def apply_average(self, upd: m.AverageUpdate) -> None:
|
||||
rec = self._rows.get(upd.id)
|
||||
|
||||
@@ -24,6 +24,7 @@ class SensorRecord: # type 'A' — full sensor record
|
||||
disp: int
|
||||
dp: int
|
||||
calc: int
|
||||
updated_at: float | None = None # monotonic time the value last changed; None until a C/I frame
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -57,3 +57,18 @@ def test_station_settings_ordered():
|
||||
s.upsert(m.SettingLine(2, "B\tvb", 0))
|
||||
s.upsert(m.SettingLine(1, "A\tva", -1))
|
||||
assert [line.row for line in s.all()] == [1, 2]
|
||||
|
||||
|
||||
def test_apply_current_stamps_updated_at():
|
||||
t = SensorTable()
|
||||
t.upsert(_rec(1))
|
||||
t.apply_current(1, 5.0, at=123.0)
|
||||
assert t.get(1).value == 5.0
|
||||
assert t.get(1).updated_at == 123.0
|
||||
|
||||
|
||||
def test_apply_current_without_at_leaves_timestamp_none():
|
||||
t = SensorTable()
|
||||
t.upsert(_rec(1))
|
||||
t.apply_current(1, 5.0)
|
||||
assert t.get(1).updated_at is None
|
||||
|
||||
Reference in New Issue
Block a user