bugfixes
This commit is contained in:
@@ -74,6 +74,63 @@ def test_keyed_decrypt_marks_decrypted():
|
||||
assert dev.status == "decrypted"
|
||||
|
||||
|
||||
def test_send_interval_estimate():
|
||||
store = DeviceStore()
|
||||
# telegrams at t=0,16,32,64 -> gaps 16,16,32 (one missed) -> median 16
|
||||
for t in (1000.0, 1016.0, 1032.0, 1064.0):
|
||||
store.upsert_discovery(_dll("777"), now=t)
|
||||
dev = store.get("777")
|
||||
assert dev.interval_samples == 3
|
||||
assert dev.interval_estimate == 16
|
||||
assert dev.interval_last == 32
|
||||
assert dev.interval_min == 16
|
||||
|
||||
|
||||
def test_json_only_still_counts_and_intervals():
|
||||
# Regression: a device whose DLL line fails to parse still gets counted
|
||||
# (and its interval inferred) from the JSON telegrams alone.
|
||||
store = DeviceStore()
|
||||
for t in (2000.0, 2016.0, 2032.0):
|
||||
store.apply_json(
|
||||
{"type": "json", "id": "37287397", "name": "scan", "driver": "qheatv2",
|
||||
"media": "radio converter (meter side)", "fields": {"total_kwh": 0}},
|
||||
now=t,
|
||||
)
|
||||
dev = store.get("37287397")
|
||||
assert dev.count == 3
|
||||
assert dev.interval_samples == 2
|
||||
assert dev.interval_estimate == 16
|
||||
|
||||
|
||||
def test_dll_and_its_json_count_once():
|
||||
# The DLL and its own JSON (same telegram, ~same instant) must not double.
|
||||
store = DeviceStore()
|
||||
store.upsert_discovery(_dll("123"), now=3000.0)
|
||||
store.apply_json(
|
||||
{"type": "json", "id": "123", "name": "scan", "fields": {"x": 1}},
|
||||
now=3000.05,
|
||||
)
|
||||
assert store.get("123").count == 1
|
||||
|
||||
|
||||
def test_single_telegram_has_no_interval():
|
||||
store = DeviceStore()
|
||||
store.upsert_discovery(_dll("888"), now=1000.0)
|
||||
dev = store.get("888")
|
||||
assert dev.interval_samples == 0
|
||||
assert dev.interval_estimate is None
|
||||
|
||||
|
||||
def test_duplicate_burst_does_not_pollute_interval():
|
||||
store = DeviceStore()
|
||||
store.upsert_discovery(_dll("999"), now=1000.0)
|
||||
store.upsert_discovery(_dll("999"), now=1000.002) # duplicate DLL burst
|
||||
store.upsert_discovery(_dll("999"), now=1016.0)
|
||||
dev = store.get("999")
|
||||
assert dev.interval_samples == 1
|
||||
assert dev.interval_estimate == 16 # not ~0 from the burst
|
||||
|
||||
|
||||
def test_unencrypted_device_is_open_not_locked():
|
||||
store = DeviceStore()
|
||||
store.upsert_discovery(_dll("333"))
|
||||
|
||||
Reference in New Issue
Block a user