I am finding type conversions and casts in OH2 rather “complex” to put it in a delicate way. Having read the very useful section in Rules documentation, then a number of posts, notably by always-helpful @rlkoshak I am still lost as to the error I am seeing about sending a simple HSBType command to a Color item—something I assumed was not only possible, but the recommended way of doing things:
val HSBType nightBedroomLightColour = new HSBType("0,100,1") // Dark red
hue_Bedroom_Wall_Color.sendCommand(nightBedroomLightColour)
while this functions, it throws this warning in VSCode:
Ambiguous feature call.
The extension methods
sendCommand(Item, Number) in BusEvent and
sendCommand(Item, Command) in BusEvent
both match.(org.eclipse.xtext.xbase.validation.IssueCodes.ambiguous_feature_call)
Why is that—I am not asking about the nature of multiple inheritance here, but the error I am seeing? Is it really necessary to cast the HSBType to something like a string to make it work without warnings?
On a similar note, I get more warnings about comparing PercentType against an int etc. I realise the Rules DSL is more strongly typed than it seems, therefore the support one gets from VSCode addins is very helpful. But I am also asking myself if its strong typing is a help or a hindrance…I spent a good few hours yesterday and today just trying to understand it—and I have written a good number of lines of code in very strongly typed languages in my life.
On a practical note of matters of documentation. I also wanted to figure out how to get brightness (and other) components of a Color item. The official Rules page and many forum posts link to this as a source of that information: https://www.eclipse.org/projects/archives.php?org/eclipse/smarthome/core/library/types/HSBType.html . Unfortunately, that page just shows a generic “Eclipse archived project” page and so it is not possible to examine the underlying Java doc. Is there a live link to that?
In any case, I ended up casting the state like this:
(hue_Bedroom_Wall_Color.state as HSBType).brightness
(hue_Bedroom_Wall_Color.state as HSBType).hue
but is that the way to go?
All of that (odd) type mangling, or having to torture date/times through strings to make them work in rules, it all makes me wonder if I should just throw in the Rules DSL towel in and see if the Jython grass is greener.