Skip to content

Refuse tags with no known size in strict parse_tag - #974

Merged
gijzelaerr merged 5 commits into
masterfrom
fix/parse-tag-unsized
Nov 8, 2026
Merged

gijzelaerr merged 5 commits into
masterfrom
fix/parse-tag-unsized

Conversation

@gijzelaerr

Copy link
Copy Markdown
Owner

Fixes #970. Based on #973, because both change the codec in tags.py; this PR's diff is only its own commits.

parse_tag accepted addresses such as DB1.DBW0:BOGUS and DB1.DBB0:STRING, and the failure only appeared when .size was read. An application that validates addresses with parse_tag therefore accepted ones that fail on every read.

  • With strict=True, the default, parse_tag now raises ValueError for a type with no known size. strict=False and the explicit PLC4XTag.parse / NodeS7Tag.parse behave as before.
  • S5TIME now has a size of 2 and decodes with the existing get_s5time. Writing it still raises ValueError, because there is no set_s5time.

Behaviour change: code calling parse_tag with default arguments on such an address now gets the ValueError at parse time instead of at first use.

Checks: full test suite, mypy, ruff and pre-commit pass locally on Windows. Not tested against a real PLC, and S5TIME decoding only compares against get_s5time.

Moves the codec from snap7.client to snap7.tags as decode_tag and encode_tag.
The private names stay as aliases, because released ha-s7 versions import them.
Also gives S5TIME a size and a decoder. Writing it stays unsupported, since there is no set_s5time.
@gijzelaerr
gijzelaerr changed the base branch from feat/public-tag-codec to master November 8, 2026 05:16
# Conflicts:
#	CHANGES.md
#	tests/test_tags.py
@gijzelaerr
gijzelaerr merged commit 466cd75 into master Nov 8, 2026
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parse_tag accepts types that Tag.size then refuses

1 participant