openhab-core
openhab-core copied to clipboard
Support mired units
Mireds are fairly common to describe the color temperature of lightbulbs (slightly less common than Kelvin), but are very useful for various calculations when adjusting the color temperature, as well as being necessary for various integerations that require mired units.
This commit makes them a well-known unit (previously they were still usable, using "MK^-1"), as well as making them easier to work with on QuantityType. The hiccup is that Mireds aren't technically a Temperature dimension, because they're a reciprocal. So add a inverse method that delegates to javax.measure's same method, and then use it as necessary when doing unit conversions and comparisons. Unfortunately, because the dimension changes, the return value of a conversion won't necessarily be the same type, an additional method is added for callers that are willing to handle the change in dimension. This is implemented for all callers that can use it in core.
By implementing this in core, it makes it possible to link a channel that's quantity aware (such as MQTT's number channels with arbitrary units) that expresses it in say mireds, with a Number:Temperature item with a state description in K, seamlessly allowing the UI to display the user-preferred value. Simultaneously it makes it automatic for other add-ons--like Homekit (change incoming to openhab-addons building on this commit), or say the Hue binding--to easily support these conversions, and not need addon-specific metadata to inform it how to do said conversion.