From ee6bbb9f54c275872e4de8f2a24594c491a9b025 Mon Sep 17 00:00:00 2001 From: Gavin Ying Date: Tue, 10 Nov 2026 21:59:13 +0800 Subject: [PATCH] feat!: remove --audit and pin modpoll-wot 0.3.0a3 for 2.0.0a5 (WOT-03) Thing Models are fully open and a full read executes the whole modpoll:acquisition plan, so the bounded audit sample is redundant. Remove --audit, its module, retry overrides and tests, mark the vocab term as removed, and adopt modpoll-wot 0.3.0a3, which drops the plan. Co-Authored-By: Claude Opus 5.5 --- docs/preview-notes.md | 16 ++++++- modpoll/arg_parser.py | 5 --- modpoll/audit.py | 86 ------------------------------------- modpoll/main.py | 12 ------ modpoll/modbus_task.py | 4 -- pyproject.toml | 4 +- tests/test_audit.py | 61 -------------------------- uv.lock | 10 ++--- vocab/wot-modbus/index.html | 2 +- 9 files changed, 23 insertions(+), 177 deletions(-) delete mode 100644 modpoll/audit.py delete mode 100644 tests/test_audit.py diff --git a/docs/preview-notes.md b/docs/preview-notes.md index 34f3090..bd7d262 100644 --- a/docs/preview-notes.md +++ b/docs/preview-notes.md @@ -1,4 +1,18 @@ -# Modpoll 2.0.0a4 preview +# Modpoll 2.0.0a5 preview + +Modpoll 2.0.0a5 removes `--audit` and pins modpoll-wot 0.3.0a3, which removes +the `modpoll:audit` plan. Thing Models are fully open, and a full read executes +the whole `modpoll:acquisition` plan, so TM authors only write acquisition +groups. A TM that still declares `modpoll:audit` is rejected as an unsupported +root project extension; delete the key. Read a device once with: + +```sh +modpoll --once --config device.tm.json --tcp DEVICE_HOST --unit-id 1 +``` + +Verification report generation over a full read is planned separately. + +## Modpoll 2.0.0a4 preview Modpoll 2.0.0a4 follows the ModioHub glossary: a decoded value is a point. The terminal table's first column header changes from `Reference` to `Point`, diff --git a/modpoll/arg_parser.py b/modpoll/arg_parser.py index ac877d4..f026ed2 100644 --- a/modpoll/arg_parser.py +++ b/modpoll/arg_parser.py @@ -208,9 +208,4 @@ def get_parser(): choices=["default", "ascii", "rtu", "socket"], help="The type of framer for Modbus messages. Serial supports ascii/rtu; TCP/UDP use socket.", ) - parser.add_argument( - "--audit", - action="store_true", - help="Read the bounded TM identity and status sample once", - ) return parser diff --git a/modpoll/audit.py b/modpoll/audit.py deleted file mode 100644 index d5267b6..0000000 --- a/modpoll/audit.py +++ /dev/null @@ -1,86 +0,0 @@ -"""Bounded, read-only identity and status sampling.""" - -from copy import copy -from dataclasses import replace -import json - -from modpoll_wot import parse_parameters - -from .modbus_task import _create_modbus_client -from .wot_config import create_devices, read_model - -MAX_SAMPLES = 16 -MAX_TIMEOUT = 5 - - -def run_audit(args): - if len(args.config) != 1 or args.mqtt_host or args.export or args.daemon: - raise ValueError( - "--audit requires one configuration and no MQTT, export or daemon" - ) - if args.udp or args.framer not in ("default", "rtu" if args.serial else "socket"): - raise ValueError("--audit supports Modbus TCP and serial RTU") - if not 0 < args.timeout <= MAX_TIMEOUT: - raise ValueError("--audit timeout must be between 0 and 5 seconds") - if args.serial and args.serial_baud <= 0: - raise ValueError("--audit serial baud rate must be positive") - model = read_model( - args.config[0], - timeout=args.timeout, - unit_id=args.unit_id, - host=args.tcp, - port=args.tcp_port, - parameters=parse_parameters(args.param), - ) - plan = getattr(model, "audit", None) - if plan is None: - raise ValueError("--audit requires a modpoll:audit plan") - names = plan.identity + plan.status - if len(names) > MAX_SAMPLES: - raise ValueError(f"--audit supports at most {MAX_SAMPLES} points") - - selected = {} - for group in model.groups: - for member in group.members: - if member.property in names: - selected[member.property] = replace( - group, - start=group.start + member.offset, - quantity=member.bit_count if member.physical_bits else member.width, - members=(replace(member, offset=0, writable=False),), - ) - (device,) = create_devices(replace(model, groups=tuple(selected[n] for n in names))) - connection = copy(args) - if model.endpoint: - if args.serial: - raise ValueError("--audit requires an unbound TM for serial RTU") - connection.tcp, connection.tcp_port = model.endpoint - - client = _create_modbus_client(connection) - result = {"identity": [], "status": []} - success = True - try: - connected = client.connect() - for index, poller in enumerate(device.pollerList): - (point,) = poller.readablePoints - ok = connected and poller.poll(client) and point.valid_this_poll - success = success and ok - section = "identity" if index < len(plan.identity) else "status" - result[section].append( - { - "property": point.name, - "result": "read" if ok else "failed" if connected else "not-tested", - "value": point.val if ok else None, - "unit": point.unit, - } - ) - finally: - client.close() - if not plan.identity: - result["identity_result"] = "not-provided" - elif all(row["result"] == "read" for row in result["identity"]): - result["identity_result"] = "sampled" - else: - result["identity_result"] = "incomplete" - print(json.dumps(result, ensure_ascii=False, allow_nan=False)) - return 0 if success else 1 diff --git a/modpoll/main.py b/modpoll/main.py index a45f937..7795e29 100644 --- a/modpoll/main.py +++ b/modpoll/main.py @@ -142,18 +142,6 @@ def app(name="modpoll"): # parse args args = get_parser().parse_args() - if args.audit: - from pymodbus.exceptions import ModbusException - - from .audit import run_audit - - try: - status = run_audit(args) - except (ValueError, OSError, ModbusException) as exc: - print(f"Audit failed: {exc}", file=sys.stderr) - status = 1 - raise SystemExit(status) - print( f"\nModpoll v{__version__} - A New Command-line Tool for Modbus and MQTT\n", flush=True, diff --git a/modpoll/modbus_task.py b/modpoll/modbus_task.py index e4d7dd4..4d03713 100644 --- a/modpoll/modbus_task.py +++ b/modpoll/modbus_task.py @@ -849,8 +849,6 @@ def _create_serial_client(args, port, framer): "stopbits": 1, "timeout": args.timeout, } - if getattr(args, "audit", False): - client_args["retries"] = 0 if framer: client_args["framer"] = framer return ModbusSerialClient(**client_args) @@ -862,8 +860,6 @@ def _create_tcp_client(args, framer): "port": 502 if args.tcp_port is None else args.tcp_port, "timeout": args.timeout, } - if getattr(args, "audit", False): - client_args["retries"] = 0 if framer: client_args["framer"] = framer return ModbusTcpClient(**client_args) diff --git a/pyproject.toml b/pyproject.toml index f34adf9..fe6c3c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "modpoll" -version = "2.0.0a4" +version = "2.0.0a5" description = "A New Command-line Tool for Modbus and MQTT" authors = [{ name = "Ying Shaodong", email = "helloysd@gmail.com" }] readme = "README.md" @@ -10,7 +10,7 @@ dependencies = [ "paho-mqtt>=2.1.0,<3.0.0", "prettytable>=3.9.0,<4.0.0", "requests>=2.32.5,<3.0.0", - "modpoll-wot==0.3.0a2", + "modpoll-wot==0.3.0a3", ] [project.optional-dependencies] diff --git a/tests/test_audit.py b/tests/test_audit.py deleted file mode 100644 index 6c19418..0000000 --- a/tests/test_audit.py +++ /dev/null @@ -1,61 +0,0 @@ -"""Audit uses precise read spans and reports each sample.""" - -import json -from pathlib import Path -from types import SimpleNamespace - -import pytest -import modpoll_wot - -from modpoll import audit -from modpoll.arg_parser import get_parser - -pytestmark = pytest.mark.skipif( - not hasattr(modpoll_wot, "AuditPlan"), - reason="requires the audit producer candidate or release", -) -FIXTURE = Path(__file__).resolve().parent / "fixtures/numeric.tm.json" - - -@pytest.mark.parametrize("failed", [False, True]) -def test_audit_reads_selected_points_over_serial(tmp_path, monkeypatch, capsys, failed): - source = json.loads(FIXTURE.read_bytes()) - source["modpoll:audit"] = {"status": ["measurement", "counter"]} - file = tmp_path / "audit.tm.json" - file.write_text(json.dumps(source)) - args = get_parser().parse_args( - ["--audit", "-f", str(file), "--serial", "test-port", "--unit-id", "9"] - ) - reads = [] - - def read(address, *, count, device_id): - reads.append((address, count, device_id)) - return SimpleNamespace( - isError=lambda: failed and address == 40004, - registers=[0x3FC0, 0] if count == 2 else [287], - ) - - def connect(options): - assert options.serial == "test-port" and options.audit - return SimpleNamespace( - connect=lambda: True, close=lambda: None, read_holding_registers=read - ) - - monkeypatch.setattr(audit, "_create_modbus_client", connect) - assert audit.run_audit(args) == int(failed) - report = json.loads(capsys.readouterr().out) - assert report["identity_result"] == "not-provided" - assert [row["value"] for row in report["status"]] == [ - None if failed else 1.5, - 287, - ] - assert reads == [(40004, 2, 9), (40000, 1, 9)] - - -def test_audit_rejects_missing_plan_before_connecting(monkeypatch): - args = get_parser().parse_args(["--audit", "-f", str(FIXTURE), "--tcp", "test"]) - monkeypatch.setattr( - audit, "_create_modbus_client", lambda _: pytest.fail("connected") - ) - with pytest.raises(ValueError, match="requires a modpoll:audit plan"): - audit.run_audit(args) diff --git a/uv.lock b/uv.lock index 9ee189f..b6cece2 100644 --- a/uv.lock +++ b/uv.lock @@ -418,7 +418,7 @@ wheels = [ [[package]] name = "modpoll" -version = "2.0.0a4" +version = "2.0.0a5" source = { editable = "." } dependencies = [ { name = "modpoll-wot", marker = "python_full_version < '3.15'" }, @@ -451,7 +451,7 @@ docs = [ [package.metadata] requires-dist = [ - { name = "modpoll-wot", specifier = "==0.3.0a2" }, + { name = "modpoll-wot", specifier = "==0.3.0a3" }, { name = "paho-mqtt", specifier = ">=2.1.0,<3.0.0" }, { name = "prettytable", specifier = ">=3.9.0,<4.0.0" }, { name = "pymodbus", specifier = "~=3.16.1" }, @@ -478,15 +478,15 @@ docs = [ [[package]] name = "modpoll-wot" -version = "0.3.0a2" +version = "0.3.0a3" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "jsonschema", marker = "python_full_version < '3.15'" }, { name = "referencing", marker = "python_full_version < '3.15'" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/27/46/672134632e850d127a53db78f57a2ed836f5b35401bb3e423485a4124279/modpoll_wot-0.3.0a2.tar.gz", hash = "sha256:8a89c5e2cfcff8601274a6c178bce018267be2e3c140e8fb4758193a5385892e", size = 50965, upload-time = "2026-11-09T17:44:30.705Z" } +sdist = { url = "https://files.pythonhosted.org/packages/ec/c3/aec90bc5a9b1eac294e49e6f0d5ad85846da505f9ee12639ac57d2ba74c7/modpoll_wot-0.3.0a3.tar.gz", hash = "sha256:e2f61c65540d8487eb1f91adbff812d29580c3195632a4a2377374134ee84305", size = 50388, upload-time = "2026-11-10T13:56:03.147Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/d4/21/f5142ffd1bbf77bad4b46007cb9ccf4d13142a4d5a2646c6eae50b129543/modpoll_wot-0.3.0a2-py3-none-any.whl", hash = "sha256:49697acb9985016b9a140cd9762a1d792486e40ac09767bb3d1441dbece0a237", size = 42847, upload-time = "2026-11-09T17:44:29.477Z" }, + { url = "https://files.pythonhosted.org/packages/09/80/cf5e0a63ff469cda8818116e5f8e3bdc8a293aa83a8ba788566f7903198f/modpoll_wot-0.3.0a3-py3-none-any.whl", hash = "sha256:1fb4a27a5a4503512303155881ec8b13c0543d086d39767d613434782d46161e", size = 42463, upload-time = "2026-11-10T13:56:02.184Z" }, ] [[package]] diff --git a/vocab/wot-modbus/index.html b/vocab/wot-modbus/index.html index d8ee72b..9a44437 100644 --- a/vocab/wot-modbus/index.html +++ b/vocab/wot-modbus/index.html @@ -31,7 +31,7 @@

Contract 0.2

explicit. Bit-table offsets count physical bits in 0.2. Above definitions remain unchanged for 0.1 input.

-
modpoll:audit
Optional identity and status lists of readable property names for a local audit.
+
modpoll:audit
Removed in modpoll 2.0.0a5 and modpoll-wot 0.3.0a3. A full read executes the whole modpoll:acquisition plan.
modpoll:codec
Form float16 or historical register boolean array codec, raw xsd:hexBinary.
modpoll:byteLength
Exact UTF-8 byte capacity when different from the full register span.
modpoll:bitPacking
Explicit legacy-msb packed numeric/string bit-table interpretation.