Use configurations in the HandlerFactory???

62 views
Skip to first unread message

JohannesR

unread,
Aug 3, 2015, 4:47:25 PM8/3/15
to openhab2
Hi,

i want to create a Binding for a serial device. I want that it is possible to enter the serial Port in the paper UI for every Thing. But the <BindingName>HandlerFactory just extends the BaseThingHandlerFactory, so it is not possible to get the manually entered Port for the NRSerialPort.connect.

Einmal auf deutsch, da mir die genaue Erklären meines Problems schwer fällt. Ich möchte, dass der Anwender in der Paper UI beim manuellen Erstellen eines Things den Port des Geräts angeben muss. Mit diesem Port soll sich das Thing dann in der <BindingName>HandlerFactory verbinden. Da die Methode getThing dort jedoch nicht zugänglich ist, komme ich nicht an die zuvor eingegeben Informationen ran, wie kann ich das möglich machen? Denke ich falsch?

Mit freundlichen Grüßen
Johannes

Kai Kreuzer

unread,
Aug 3, 2015, 5:10:30 PM8/3/15
to open...@googlegroups.com
Hi Johannes,

I think you are looking at the wrong place. All you need to do is to implement the initialize() method of your ThingHandler (see https://www.eclipse.org/smarthome/documentation/development/bindings/thing-handler.html#lifecycle).
Within this method, you have access to the Thing configuration, which will contain the serial port information that you have provided through the Paper UI. Also note that this could be potentially changed at any time by the user, so you should also handle configuration updates (see https://www.eclipse.org/smarthome/documentation/development/bindings/thing-handler.html#handling-configuration-updates).

Best regards,
Kai

--
You received this message because you are subscribed to the Google Groups "openhab2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab2+u...@googlegroups.com.
To post to this group, send email to open...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openhab2/b131b680-41cb-4f4f-8876-8a472e3d3646%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

JohannesR

unread,
Aug 3, 2015, 6:33:12 PM8/3/15
to openhab2
Hi Kai, 
thanks for the fast answer, after i implement the thinghandler i can use the getThing()!
But now i have a nullpointerexception at:

portName = (String) getThing().getConfiguration().get(uvr2BindingConstants.CONFIG_PARAMETER_SERIAL_PORT); 

Console:

2015-08-04 00:27:20 [INFO ] [ome.event.ThingStatusInfoEvent:43   ] - uvr2:inputs:6b16c0c1' updated: INITIALIZING

2015-08-04 00:27:20 [INFO ] [ome.event.ThingStatusInfoEvent:43   ] - uvr2:inputs:6b16c0c1' updated: UNINITIALIZED (HANDLER_INITIALIZING_ERROR)

2015-08-04 00:27:20 [ERROR] [.c.thing.internal.ThingManager:457  ] - Exception occured while calling thing handler: nulljava.lang.NullPointerException: null

at org.openhab.binding.uvr2.internal.uvr2HandlerFactory.serialConnect(uvr2HandlerFactory.java:95)


I dont understand why i get this now?!

Kai Kreuzer

unread,
Aug 4, 2015, 3:13:34 AM8/4/15
to open...@googlegroups.com
Hi Johannes,

Then best use the debugger to step through the code and see what happens.

Regards,
Kai

--
You received this message because you are subscribed to the Google Groups "openhab2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab2+u...@googlegroups.com.
To post to this group, send email to open...@googlegroups.com.

JohannesR

unread,
Aug 5, 2015, 7:16:29 AM8/5/15
to openhab2
Thank You Kai for the Help, i got it now ;)

The HandlerFactory was the wrong place for what I wanted to do ;)
Now i do the connection in the handler and everything goes well!
Reply all
Reply to author
Forward
0 new messages