Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse SmartHome » How to access getAcceptedDataTypes for a channel
How to access getAcceptedDataTypes for a channel [message #1719072] Mon, 04 January 2016 22:55 Go to next message
Marcel Verpaalen is currently offline Marcel VerpaalenFriend
Messages: 59
Registered: September 2014
Member

I'm trying to update dynamic created channels.
when I receive data and send it to the channel it needs to be casted to the right state data type for the specific channel.

When accessing the channel I do have access to the itemtype, with the getAcceptedItemType function, however, I don't see how I can properly go from there to the list of getAcceptedDataTypes
(e.g. a dimmer itemtype It's status could be 0%, 10%, 50%, 100%, but also OFF or ON and maybe UNDEFINED. So the accepted data types would be in this case PercentType, OnOffType and UnDefType)

As the Channnel.getLinkedItems() is depreciated I can't go from there to the getAcceptedDataTypes anymore.

any hint?
Re: How to access getAcceptedDataTypes for a channel [message #1719233 is a reply to message #1719072] Wed, 06 January 2016 11:48 Go to previous messageGo to next message
John Cocula is currently offline John CoculaFriend
Messages: 20
Registered: June 2015
Junior Member
I'm pretty sure there must have been a reason to make getAcceptedDataTypes and getAcceptedCommandTypes instance methods and not static methods, but I agree it can be inconvenient. One option is to instantiate a newInstance of the class returned from getAcceptedItemType and call its getAcceptedDataTypes method. Not ideal, but should work. Another option that worked in OH1 was to copy the lists of accepted data and command types when parsing binding config strings and save the copied lists in the binding config objects for use when posting updates, but I'm not sure this approach can be applied in an OH2 binding.
Re: How to access getAcceptedDataTypes for a channel [message #1719980 is a reply to message #1719233] Wed, 13 January 2016 14:31 Go to previous messageGo to next message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 657
Registered: December 2011
Senior Member
Yes, what John suggests might work, but it is indeed an ugly workaround.

Afair, the reason that the getAcceptedDataTypes method is not static was a technical one: You cannot define static methods on an interface (Item).
We might e.g. add a helper method to the BaseThingHandler: Something like getAcceptedDataTypes(String channelId) - internally, this could do the trick that John described.
Re: How to access getAcceptedDataTypes for a channel [message #1731531 is a reply to message #1719980] Fri, 06 May 2016 14:35 Go to previous messageGo to next message
Ben Suffolk is currently offline Ben SuffolkFriend
Messages: 2
Registered: April 2016
Junior Member
I find myself in a similar situation right now. I Have a string that I need to convert into a state. I have the channel and from the getAcceptedItemType() method on the channel I can get a string which tells me what type the channel is, e.g. "Number" or "Switch" etc, but I can't see how to convert y state as a String into a state that can be passed to updateState() in the thingHandler.

Re: How to access getAcceptedDataTypes for a channel [message #1731672 is a reply to message #1731531] Mon, 09 May 2016 07:15 Go to previous messageGo to next message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 657
Registered: December 2011
Senior Member
> I can't see how to convert y state as a String into a state that can be passed to updateState() in the thingHandler

Since you know what types your channel supports, converting the string to a certain type should be easily possible through TypeParser.parseState().
Re: How to access getAcceptedDataTypes for a channel [message #1731673 is a reply to message #1731672] Mon, 09 May 2016 07:17 Go to previous messageGo to next message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 657
Registered: December 2011
Senior Member
> We might e.g. add a helper method to the BaseThingHandler: Something like getAcceptedDataTypes(String channelId)

If this would be helpful as a convenience method, feel free to create a PR for it.
Re: How to access getAcceptedDataTypes for a channel [message #1732606 is a reply to message #1731673] Wed, 18 May 2016 13:20 Go to previous message
Marcel Verpaalen is currently offline Marcel VerpaalenFriend
Messages: 59
Registered: September 2014
Member
It's probably my still limited understanding of the framework, but have not managed yet to get the suggested way of John to succeed.
It seems instantiating is not directly possible, and createitem can't easily be called either.

Any hints / suggestions?
Previous Topic:MapDB corruption
Next Topic:Allow channels without item type
Goto Forum:
  


Current Time: Thu Sep 20 00:19:59 GMT 2018

Powered by FUDForum. Page generated in 0.01850 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top