bugfixes
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -48,6 +48,15 @@ async def test_device_appears_and_selects():
|
||||
assert app.selected_id == "76348799"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ctrl_c_quits():
|
||||
app = OmsApp(device="none", autostart=False)
|
||||
async with app.run_test() as pilot:
|
||||
await pilot.press("ctrl+c")
|
||||
await pilot.pause()
|
||||
assert app._exit is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_key_via_modal():
|
||||
app = OmsApp(device="none", autostart=False)
|
||||
|
||||
@@ -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"))
|
||||
|
||||
@@ -33,6 +33,22 @@ def test_parse_json():
|
||||
assert "rssi_dbm" not in ev["fields"]
|
||||
|
||||
|
||||
def test_parse_dll_with_nested_parens_in_media():
|
||||
# "Radio converter (meter side)" has parentheses inside the media name.
|
||||
line = (
|
||||
"(telegram) DLL L=3c C=44 (from meter SND_NR) M=4493 (QDS) A=37027095 "
|
||||
"VER=23 TYPE=37 (Radio converter (meter side)) (driver qheatv2) DEV= RSSI=0"
|
||||
)
|
||||
ev = parse_line(line)
|
||||
assert ev is not None
|
||||
assert ev["type"] == "dll"
|
||||
assert ev["id"] == "37027095"
|
||||
assert ev["manufacturer"] == "QDS"
|
||||
assert ev["media"] == "Radio converter (meter side)"
|
||||
assert ev["driver"] == "qheatv2"
|
||||
assert ev["rssi"] == 0
|
||||
|
||||
|
||||
def test_parse_ell_encryption():
|
||||
line = (
|
||||
"(telegram) ELL CI=8d CC=20 (slow_resp sync) ACC=91 SN=d37cac21 "
|
||||
|
||||
Reference in New Issue
Block a user