Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ The configuration loader detects the format from the content and reports invalid
model fields before polling. Each model describes one device; use multiple
`--config` paths for multiple devices. Give each model a unique `title`, which is
the output device name. Existing v1 CSV configurations load through the same
`--config` argument; use `--thing-model` or
`--thing-description`/`--td` to assert the JSON document kind explicitly.
`--config` argument; no separate flags are needed.

Physical RS485 polling has also been verified by the maintainer with an Eastron
meter (2026-10-28). See [validation](docs/validation.rst) for the evidence scope and
Expand Down Expand Up @@ -138,12 +137,12 @@ signing in with either tool signs in both. `MODIOHUB_TOKEN` in the environment r
`MODIOHUB_URL` selects another server, and `login` and `logout` take `--server URL` for the same. `modpoll logout` forgets the login on this computer;
revoke the session in your ModioHub settings to end it on the server.

Once signed in, `--tm modiohub:<id>@<version>` (`-f` works too; the version is a number or `latest`) reads one
Once signed in, `--config modiohub:<id>@<version>` (the version is a number or `latest`) reads one
of your custom Thing Models. A shared one needs no login. A full read of it writes a report that names the
Workspace model, and `--upload` shows the report and, after you confirm (or with `--yes`), uploads it:

```sh
modpoll --tm modiohub:k3x9f2m7q4a8n5bd@latest --tcp 192.168.1.20 --upload
modpoll --config modiohub:k3x9f2m7q4a8n5bd@latest --tcp 192.168.1.20 --upload
```

### MQTT data and write behavior
Expand Down
2 changes: 1 addition & 1 deletion docs/preview-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Modpoll 2.0.0a7 pins modpoll-wot 0.5.0a1 and connects to ModioHub:
verification report (schema 3), which holds no address, Unit ID, serial number or value.
- `modpoll login` signs in with your browser and `modpoll logout` forgets the login. The 7-day tool session
is kept in `~/.config/modiohub/credentials.json` and is shared with modsim 2.0.0a9.
- `--tm modiohub:<id>@<version>` reads a custom Thing Model from your ModioHub Workspace, and `--upload` shows
- `--config modiohub:<id>@<version>` reads a custom Thing Model from your ModioHub Workspace, and `--upload` shows
the report of a full read and uploads it after you confirm.

## Modpoll 2.0.0a6 preview
Expand Down
12 changes: 5 additions & 7 deletions docs/site/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ CSV and WoT TM/TD configuration
===============================

The 2.x development branch accepts both the v1 CSV configuration format and
JSON configurations using WoT TM/TD 1.1. ``-f``/``--config`` (alias ``--tm``)
JSON configurations using WoT TM/TD 1.1. ``-f``/``--config``
takes either format and detects it from the content, not the file name or URL
suffix: a first
non-whitespace byte of ``{`` or ``[`` selects JSON; anything else is parsed as
v1 CSV. The same argument also accepts a ``modiohub:<id>@<version>`` reference
to a custom Thing Model in your ModioHub Workspace (run ``modpoll login``
first unless the version is shared); a reference is always a Thing Model.
``--thing-model`` and ``--thing-description``/``--td`` assert
the JSON document kind explicitly and reject content of the other kind (or a
CSV file) with a configuration error; they take local paths or URLs only.
``--config`` is the only configuration argument; there are no format-specific
flags.

For JSON input, a top-level ``@type`` containing ``tm:ThingModel`` (a string or
an array entry) selects TM validation; otherwise the document is validated as
Expand All @@ -34,9 +33,8 @@ Each file describes one device. Its ``title`` is the output device name;
``--unit-id`` overrides the instance Unit ID (range 1–254). Without it, each file
uses the Unit ID declared consistently in its Forms, falling back to 1. Different files
can therefore address different Unit IDs in one process.
Multiple files may be supplied per flag, and the three flags may be combined;
files load in ``--config``, ``--thing-model``, ``--thing-description`` order.
Device names must be unique across all files.
Multiple files may be supplied to ``--config``; device names must be unique
across all files.
The existing transport CLI arguments explicitly select the connection endpoint.
A concrete TD's form Unit IDs, addresses and quantities must agree with the model.

Expand Down
3 changes: 1 addition & 2 deletions docs/site/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ Configuration File

The configuration file (`--config`) defines the devices, pollers, and points
to be read. It can be a WoT TM/TD JSON file or a v1 CSV file; the format is
detected from the content. Use `--thing-model` or
`--thing-description`/`--td` to assert the JSON document kind explicitly.
detected from the content, no other configuration flag is needed.

For register references (i.e., Holding or Input registers) with a ``dtype`` of ``bool``, you can specify a single bit to be extracted from the 16-bit register. This is done by appending ``:bit`` to the address, where ``bit`` is an integer from 0 to 15.

Expand Down
4 changes: 2 additions & 2 deletions docs/site/v1-compatibility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ v1 compatibility and M3 acceptance
===================================

The v2 change adds the executable TM/TD profile alongside the retained v1 CSV
loader. ``--config`` detects the format from the content;
``--thing-model``/``--thing-description`` assert the JSON document kind. The
loader. ``--config`` is the single configuration argument and detects the
format from the content. The
existing transport, decoder, output and raw write paths remain. This table
compares the pinned v1 baseline ``0b42099`` with the v2 implementation; it is
not a claim that all WoT documents or every operating system has been
Expand Down
12 changes: 6 additions & 6 deletions docs/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ v1 CSV compatibility restoration
--------------------------------

On 2026-11-12 the v1 CSV loader was restored behind content detection:
``-f``/``--config`` (alias ``--tm``) accepts v1 CSV and WoT TM/TD JSON side by
side, and the new
``--thing-model``/``--thing-description`` flags assert the JSON document kind
(``--tm`` had just been taken by the POLL-02b alias for ``--config``, which
also accepts ``modiohub:`` Workspace references, so the asserting flag is the
long ``--thing-model`` only). A full read stays Thing-Model-only: CSV
``-f``/``--config`` accepts v1 CSV and WoT TM/TD JSON side by
side; ``--config`` is the only configuration argument (the ``--tm`` alias and
the ``--thing-model``/``--thing-description`` kind-assertion flags existed
only between the restoration merge and this cleanup, and are rejected as
unrecognized to keep one obvious way to load a configuration). A full read
stays Thing-Model-only: CSV
configurations are rejected with ``--full-read``. After merging the POLL-02a/02b
release into the branch, ``make check`` passed and the offline suite passed 243
tests with 58
Expand Down
25 changes: 0 additions & 25 deletions modpoll/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def get_parser():
parser.add_argument(
"-f",
"--config",
"--tm",
dest="config",
default=None,
help=(
Expand All @@ -37,30 +36,6 @@ def get_parser():
),
nargs="+",
)
parser.add_argument(
"--thing-model",
dest="thing_model",
default=[],
help=(
"Local path or URL of a WoT Thing Model JSON configuration "
"(tm:ThingModel); asserts the document kind instead of detecting it. "
"Not for modiohub: Workspace references; use --config/--tm for those."
),
nargs="+",
metavar="PATH_OR_URL",
)
parser.add_argument(
"--thing-description",
"--td",
dest="thing_description",
default=[],
help=(
"Local path or URL of a WoT Thing Description JSON configuration; "
"asserts the document kind instead of detecting it"
),
nargs="+",
metavar="PATH_OR_URL",
)
parser.add_argument(
"--device",
metavar="MANUFACTURER/MODEL[@COMMIT]",
Expand Down
8 changes: 4 additions & 4 deletions modpoll/config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
``--config`` accepts the v1 CSV format and WoT TM/TD JSON side by side; the
format is detected from the content, not the file name or URL suffix. A first
non-whitespace byte of ``{`` or ``[`` selects JSON; anything else is parsed as
v1 CSV. ``--thing-model`` and ``--thing-description`` assert the JSON document
kind instead of relying on detection.
v1 CSV. ``kind`` lets a caller assert the JSON document kind; the CLI relies
on detection instead.
"""

from modpoll_wot import AcquisitionError, loads_model
Expand Down Expand Up @@ -60,9 +60,9 @@ def load_devices(
)
return create_devices(model), model
if kind is not None:
flag = "--thing-model" if kind == "tm" else "--thing-description"
document = "Thing Model" if kind == "tm" else "Thing Description"
raise ConfigUsageError(
f"{location}: {flag} expects a TM/TD JSON document, "
f"{location}: expected a {document} JSON document, "
"but the content is not JSON"
)
if parameters is not None:
Expand Down
17 changes: 1 addition & 16 deletions modpoll/modbus_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,10 @@ def __init__(
instance_port: Optional[int] = None,
instance_parameters=None,
precision: Optional[int] = None,
config_kind: Optional[str] = None,
model_bytes: Optional[bytes] = None,
):
self.modbus_client = modbus_client
self.config_file = config_file
self.config_kind = config_kind
self.unit_id = unit_id
self.instance_host = instance_host
self.instance_port = instance_port
Expand Down Expand Up @@ -578,7 +576,6 @@ def load_config(self) -> bool:
self.model_bytes = read_payload(self.config_file, timeout=self.timeout)
self.deviceList, self.model = load_devices(
self.config_file,
kind=self.config_kind,
payload=self.model_bytes,
timeout=self.timeout,
unit_id=self.unit_id,
Expand Down Expand Up @@ -878,18 +875,7 @@ def setup_modbus_handlers(args, mqtt_handler: Optional[MqttHandler] = None):
raise ValueError("TM parameters require the profile 0.2 interpreter")
parameters = modpoll_wot.parse_parameters(args.param)
try:
config_specs = (
[(location, None) for location in (args.config or [])]
+ [
(location, "tm")
for location in (getattr(args, "thing_model", None) or [])
]
+ [
(location, "td")
for location in (getattr(args, "thing_description", None) or [])
]
)
for config_file, config_kind in config_specs:
for config_file in args.config or []:
current_handler = ModbusHandler(
None,
config_file,
Expand All @@ -906,7 +892,6 @@ def setup_modbus_handlers(args, mqtt_handler: Optional[MqttHandler] = None):
instance_port=args.tcp_port,
instance_parameters=parameters,
precision=parse_precision(getattr(args, "precision", None)),
config_kind=config_kind,
model_bytes=models.get(config_file),
)
if current_handler.load_config():
Expand Down
8 changes: 1 addition & 7 deletions modpoll/verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,17 @@ def validate_args(args):
"""Reject option combinations a full read cannot honour, before anything is connected."""
args.full_read = args.full_read or bool(args.report) or args.upload
sources = list(args.config or [])
sources += list(getattr(args, "thing_model", None) or [])
sources += list(getattr(args, "thing_description", None) or [])
if args.device and sources:
raise ValueError("Use either --device or a configuration source, not both")
if not args.device and not sources:
raise ValueError(
"One of -f/--tm, --thing-model, --thing-description or --device is required"
)
raise ValueError("One of --config/-f or --device is required")
if args.device:
parse_device(args.device)
if not args.full_read:
for option in ("confirm", "reject", "chassis", "firmware", "configuration"):
if getattr(args, option):
raise ValueError(f"--{option} needs --full-read or --report")
return
if args.thing_description:
raise ValueError("A full read reads a Thing Model, not a Thing Description")
if args.mqtt_host:
raise ValueError("A full read does not publish to MQTT")
if args.udp:
Expand Down
64 changes: 21 additions & 43 deletions tests/test_cli_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,57 +36,35 @@ def test_configuration_errors_exit_2_without_a_traceback(args, message):
def test_missing_configuration_exits_2():
result = run("--once")
assert result.returncode == 2
assert (
"One of -f/--tm, --thing-model, --thing-description or --device is required"
in result.stderr + result.stdout
assert "One of --config/-f or --device is required" in (
result.stderr + result.stdout
)
assert "Traceback" not in result.stderr + result.stdout


@pytest.mark.parametrize(
"flag, config, extra",
[
("--tm", "examples/modsim.tm.json", []),
("--thing-model", "examples/modsim.tm.json", []),
def test_config_accepts_csv_tm_and_td_by_content_detection():
cases = [
(["--config", "examples/modsim.csv"], "No communication method specified"),
(["-f", "examples/modsim.tm.json"], "No communication method specified"),
# A bound TD supplies its own TCP endpoint, so --udp exercises the
# unbound-TM guard instead of opening a connection.
("--td", "examples/modsim.generated.td.json", ["--udp", "127.0.0.1"]),
(
"--thing-description",
"examples/modsim.generated.td.json",
["--udp", "127.0.0.1"],
["--config", "examples/modsim.generated.td.json", "--udp", "127.0.0.1"],
"unbound TM",
),
],
)
def test_thing_model_and_description_flags_accept_json(flag, config, extra):
result = run(flag, config, "--once", *extra)
output = result.stderr + result.stdout
assert result.returncode == 2
assert (
"No communication method specified" in output or "unbound TM" in output
), output


@pytest.mark.parametrize(
"flag, config",
[
# --tm is the --config alias (local path, URL or modiohub reference);
# v1 CSV is detected from the content there.
("--tm", "examples/modsim.csv"),
("-f", "examples/modsim.csv"),
],
)
def test_config_alias_accepts_csv_by_content_detection(flag, config):
result = run(flag, config, "--once")
assert result.returncode == 2
assert "No communication method specified" in result.stderr + result.stdout


def test_thing_model_flag_rejects_csv_content():
result = run("--thing-model", "examples/modsim.csv", "--tcp", "127.0.0.1", "--once")
assert result.returncode == 2
assert "expects a TM/TD JSON document" in result.stderr + result.stdout
assert "Traceback" not in result.stderr + result.stdout
]
for argv, message in cases:
result = run(*argv, "--once")
output = result.stderr + result.stdout
assert result.returncode == 2, output
assert message in output, output


def test_removed_flag_aliases_are_rejected():
for flag in ("--tm", "--thing-model", "--thing-description", "--td"):
result = run(flag, "examples/modsim.tm.json", "--once")
assert result.returncode == 2, flag
assert "unrecognized arguments" in result.stderr + result.stdout


def test_csv_rejects_typed_parameters():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_csv_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ def test_format_is_detected_from_content_not_filename(tmp_path):
assert model is not None


def test_thing_model_and_description_assert_the_document_kind():
def test_document_kind_assertion_at_loader_level():
with pytest.raises(ValueError, match="document kind disagrees"):
load_devices(str(MODSIM_TD), kind="tm", timeout=1)
with pytest.raises(ValueError, match="document kind disagrees"):
load_devices(str(MODSIM_TM), kind="td", timeout=1)
with pytest.raises(ValueError, match="expects a TM/TD JSON document"):
with pytest.raises(ValueError, match="expected a Thing Model JSON document"):
load_devices(str(MODSIM_CSV), kind="tm", timeout=1)
(_,), model = load_devices(str(MODSIM_TM), kind="tm", timeout=1)
assert model is not None
Expand Down
9 changes: 8 additions & 1 deletion tests/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,14 @@ def test_full_read_of_a_workspace_model_names_the_workspace_as_its_source(
with pytest.raises(SystemExit):
run_app(
monkeypatch,
["--tm", f"modiohub:{ID}@2", "--tcp", "x", "--report", str(report_path)],
[
"--config",
f"modiohub:{ID}@2",
"--tcp",
"x",
"--report",
str(report_path),
],
FakeClient(),
)
report = json.loads(report_path.read_text())
Expand Down
2 changes: 1 addition & 1 deletion tests/test_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def test_a_point_that_was_not_read_cannot_be_judged(monkeypatch, tmp_path):
),
(
[],
"One of -f/--tm, --thing-model, --thing-description or --device is required",
"One of --config/-f or --device is required",
),
(["--device", "Bad/Id"], "--device must be"),
(["-f", "x.json", "--report", "r.json", "--tcp", "x"], "needs --product"),
Expand Down
17 changes: 0 additions & 17 deletions tests/test_wot_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,6 @@ def test_csv_content_loads_as_v1_configuration(tmp_path):
assert handler.model is None


def test_thing_model_flag_rejects_wrong_document_kind(tmp_path):
path = tmp_path / "model.td.json"
path.write_text(
json.dumps(
{
"@context": ["https://www.w3.org/2022/wot/td/v1.1"],
"@type": "tm:ThingDescription",
"title": "meter",
}
)
)
handler = ModbusHandler(object(), str(path), config_kind="tm")
with pytest.raises(ValueError, match="document kind disagrees"):
handler.load_config()
assert handler.deviceList == []


def test_url_model_loader_keeps_timeout_and_streams(monkeypatch):
from modpoll import wot_config

Expand Down
Loading