Class: Converter
Converts values between types. Never throws: impossible conversions yield the target's default (see ValueDefaults). Wires rely on this so a bad value from a plugin cannot stall the bus.
Wires and actuators use it to turn what they receive into the type a signal declares
(accepts, valueType), so a plugin can call it too to predict the result. The rules, by
target type:
- boolean: a number is true when non-zero; a string is true for "on"-like words ("on", "true", "open", "active", ...); a structured value is true when anything is lit or pressed
- number: a boolean is 0 or 1; a string is parsed leniently ("20%" gives 0.2, "1.234,5" gives 1234.5, unparseable gives 0); single channel gives its channel, tunable white its brightness, RGBW its colour packed as 0xRRGGBBWW (kept from the old converter), t5 its button mask
- string: a readable rendering ("42", "true", "50% 0.2s", "#ff000000 0.2s")
- singleChannel, rgbw, tunableWhite: a number is a percentage (0-100) of the light's brightness or white channel; a boolean is 0 or 100; fade times default to 0.2 s
- t5: only whole numbers 0-31 convert; everything else means "no button"
- null: always null
Constructors
Constructor
new Converter():
Converter
Returns
Converter
Methods
convert()
staticconvert<T>(value,to):ValueOf<T>
Converts value to the type to.
Type Parameters
T
T extends "string" | "number" | "boolean" | "null" | "singleChannel" | "rgbw" | "tunableWhite" | "t5"
Parameters
value
to
T
Returns
ValueOf<T>
the converted value; one that already has the target type is returned as is (same object), without validation