Forgot to mention this: I also tried returning a static value so that no calculation is performed and that resulted in the same log messages, so one might assume that something isn’t working as it should while assigning the new value to the item.
although the surprise is complaining about “fits everything” %s
What is the channel type here? Guessing #number or number:power?
Your Item has no state presentation in the file definition ( [ ] field in the label), I wonder if it would help to give it one?
This has a side effect of establishing a default unit.
As an alternative solution that perhaps some people find less error prone:
When it comes to scaling plain numbers from modbus and converting them to UoM (numbers with associated unit), you can use modbus:gainOffset profile. This can be also to write numbers to modbus (with units converted accordingly).
Using the right word when having technical conversations is very important.
Calling parseInt is parsing the String to an integer. This is not casting.
Casting can occur when you have an Object that is more than one type at the same time. For example a Number Item has a state. That one state is:
Object
BigDecimal
Number
State
Command
When you use the as command you are saying “of all the types that this Object can be, I want to use it as X.”
MyNumberItem.state as Number
means I want to use MyNumberItem.state as its type as a Number. From that point onward you can only use it as if it were a Number and not as a State or a Command or a BigDecimal or an Object. You would have to recast it to one of those other types to do that.
Notice how String is not one of its types. You can’t cast it to a String.
MyNumberItem.state as String
would generate an error. You can convert the state to a String by calling toString. Converting it not casting either.