Hello,
I was asking myself if it was possible to create a ComplexType directly from a binding.
I’m asking this because I’ve face a architectural issue rewriting the SmartThings binding, and don’t know how to resolve it properly.
To describe it more precisly, Smarthings API expose for each device a certain number of attributes that are mapped to openHab channel, and that represents the current state of the device.
- They are simple attribute that can map directly to standard openHab type like Number / String / …
- They are some more complex attribute, like light color, but I can map them to HsbType using a conversion inside the bindings.
- They are also complex attribute that have no equivalent in standard Openhab type and contains many properties.
So, I’ve possibly see 3 ways to handle them.
-
Convert this complex type to Json String, and return the value to the channel. In terms of dev it’s the more simple. But it will not be very user friendly. And when the channel is Read/Write, it would make it possible difficult to send a new value to the channel.
-
Expand this complex attribute so there is 1 channel for each embedded properties inside the attributes. This can be another solutions, but it will make the thing as a lot of channels exposed. Also,the handling of read/write channel will be difficult because Smartthings wait for a single command to set an attribute value, not individual commands for each properties of an attributes.
-
The third possibility I can see is to create on the flight new ComplexType for this Channel.
That would be I think the most end user friendly solutions, but I don’t see any binding doing this today, and not sure if it’s can be done.
Some examples of such attribute are:
- audioTrackData: {totalTime=0, audioTrackData= { title=“”, artist=“”, album=“”, … }, elapsedTime=0}
- powerConsumptionReport : {deltaEnergy=0.0999999999994543, energy=6896.9, …}
- synthetic.lightingEffectFade : {duration=5.0, effects=[{capability=switchLevel, start=100.0, end=1.0}, {capability=colorTemperature, start=2500.0, end=2500.0}], fadeType=WindDown, state=Stop, afterAction={afterActionType=KeepCurrent}}