fix: cast typed writes to int for integer OPC UA channels - #8
Merged
Conversation
- write_channel_typed converts to the channel's unit, which yields a float - asyncua does not coerce it: encoding a float into an Int32 variant raises "required argument is not an integer" - cast when the channel declares an integer type; float channels untouched
OpcUaDataType mirrors ua.VariantType, whose numbering is fixed by the OPC UA specification, so SByte (2) through UInt64 (9) identifies the integer types without a hard-coded name list.
get_channel_by_osw_id moved to DataToolMixin, where the surrounding channel traversal helpers already live.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Three commits:
write_channel_typedcasts the converted magnitude tointwhen thechannel's
data_typeis an integer type. A unit conversion alwaysyields a float, so writing to an Int16/Int32/UInt32 node raised
TypeError: an integer is required.asyncua.ua.VariantType(2..9)rather than a hand-written list of names, since the channel schema's
data_typeenum matches that numbering.get_channel_by_osw_idin favour of the shared onenow in
DataToolMixin.Depends on OpenSemanticWorld-Packages/opensemantic.base-python#8 for
commit 3.
Why
Process parameters are stored in their own units (minutes, seconds,
Celsius) and converted on write. Every integer-typed parameter channel
was unwritable through the typed path.
Test
Adds
tests/test_controller.pycoverage for the integer cast, includinga rounding case and a float channel that must stay a float. Full suite
green locally. Exercised in
vac-station-opcua-clientagainst 35parameter channels, byte-identical to the previous manual conversion.