-
-
Notifications
You must be signed in to change notification settings - Fork 55
Description
Would it be possible to validate and convert the current value of a state when changing its type?
Currently, it is possible to change the type of a state (e.g., from string to number) even if the current value is not a valid number. This can lead to confusing log warnings and unexpected behavior.
For example:
- A state is initially created with type string.
- A numerical value (e.g., "25") is stored in the state as a string.
- The state type is changed to number, but the stored value remains a string ("25" instead of 25).
- When trying to use this state in a script, ioBroker throws a warning:
"You are assigning a string to the state 'xyz' which expects a number."
This happens even though the state type is already number. It seems that ioBroker does not automatically convert the stored value when the type is changed.
Possible improvements:
Automatically convert the stored value to the new type if possible (e.g., "25" → 25).
Show an error or warning when the stored value cannot be converted (e.g., "hello" → number).
Provide a tool or function to validate and correct all existing states after a type change.
This issue can cause hard-to-debug problems, as scripts rely on the state type but the underlying value may still be incorrect.