Closed ccutrer closed 5 years ago
Oh duh, you have the incoming State from the binding at that point. You could probably infer the type it should be from that.
Transformations and Profiles in OH 2 unfortunately work with Strings only, that is correct. It might be an idea to change that for OH 3 when we can break the APIs
Post closure comment - an example of a desire to use SCALE to match incoming data to a Number type Item. https://community.openhab.org/t/scale-transformation-issues-openhabian-with-2-5-0-m1-1/75601
It would be a useful capability. But perhaps need some extra work - what if SCALE outputs non-numeric, from user file, should it force UNDEF perhaps?
I have a HomeSeer HS-FC200+ Fan Control that exposes the fan speed as a Dimmer item, with a "proper" 0-100%. But it actually only supports 3 or 4 speeds. When I have it set to 4 speeds, the device reports back the speed as 0%, 24%, 49%, 74%, or 100%. No idea why, but the off-by-one causes havoc when I try to build UIs and tell it to only support 4 steps in a slider (or shortly, when I add support for HomeKit for having a certain number of speeds for a fan). SCALE transformation seems perfect for this. Heck, I could be convinced to use MAP, but neither one support DecimalType or PercentType. My expected item configuration:
With fan.scale:
Currently, it just silently ignores any update from the device with that config in place. I'm pretty sure I've got the config right, because if I change the name of the function, I actually get errors in the log that it was unable to transform.
It seems like https://github.com/openhab/openhab2-addons/blob/master/addons/transform/org.openhab.transform.scale/src/main/java/org/openhab/transform/scale/internal/profiles/ScaleTransformationProfile.java#L126 would be the easiest way to "cast" it to the appropriate type of the item, after the transformation, but I'm unsure if you can get at the actual Item type from that point in the code.
Your Environment