Struggling to get/set API bridge online for new binding

Trying to create a new binding towards an API bridge (Tibber Pulse) containing several datapoints (channels). The binding is intended to perform http requests (GraphQL queries) at regular intervals to update channels, and the API is reached via a GraphQL endpoint. The things-type.xml file is set up with a bridge, representing the API, having datapoints as channels.

Running demo app, the bridge is created as supposed to using PaperUI. Also, following console, the bridge is being initialized (Bridgehandler), but will not become ONLINE. As part of Bridgehandler initialize() I check if this.getBridge == null, and set (updateStatus) bridge OFFLINE if true (which is the actual outcome).

Bridge is set to ONLINE as part of method call, if the first response from the API contains a certain element (have confirmed that the http request works as it should, and that the API response contains the desired element). However, the initialize phase never reach the method call.

Have also tried to skip check if bridge == null, and go directly for method call / update status to ONLINE, but even if all conditions are met, I then end up at a java.lang.NullPointerException

Have been looking at different/similar bindings, but haven’t been able to identify any major differences. Would be highly appreciated if someone could have a look and point me in the right direction:

I think you misunderstood the bridge/thing concept. From the code you could inherit from BaseThingHandler and skip all bridge parts. A bridge is optional (if there are different devices behind it that can be independently managed).

Where do you get the NPE?

Nothing “behind” the bridge besides the datapoints to be retrieved. Defined the API as a bridge from similar bindings, and also as the API has a websocket endpoint for live stream which can be implemented in later version of the binding. But would using ThingHandler (Thing with channels) vs BridgeHandler (Bridge with channels) really matter? Just asking as an untrained programmer/binding creator.

NPE would occur if I skip checking if this.getBridge == null as part of initialize phase, and instead do a method call --> perform first http request towards API --> check if API response contains a certain element (which I have confirmed it does) --> updateStatus(ThingStatus.ONLINE).

So it seems as BridgeHandler is started as supposed to, but no bridge is associated (even though bridge is set up through PaperUI and HandlerFactory is handling the bridge and thus creates a new BridgeHandler with BRIDGE_THING_TYPE as input).

Yes a bridge is used when you have multiple devices that talk you can only talk to via a central device. Like a zwave, zigbee, etc-gateway. or usb stick. Then you have a bridge that takes care of communicating between the external device and the things representing the external devices like light bulbs.

A BaseBridgeHandler extends a BaseThingHandler. The later is the base for all things. And that class has a method getBridge which returns the bridge the thing is related to (if it has a bridge). Calling this method on a bridge would mean to get the bridge the bridge is related to. But bridges are not related to bridges. Although I could see that the BaseBridgeHandler could have overriden that method and return it’s own bridge, but it doesn’t. So to get the bridge of the BridgeHandler you need to call getThing.

As a general guide. Base on what your understanding seems to be on how stuff works you’ll do good to take a good look at the documentation, otherwise this will end up in lots or repeating of the documentation:

Realise it might seem like I am not aware of the Developer Guide, however, have been using the guide. Still, the guide is a bit vague at some points (at least for me). If that is a result of my incompetence only remains unsaid, however:


Combined with “Thing and Channel XML reference”, with actual reference to “bridge only” with channels, in addition to similar API bindings using the bridge approach, the correct choice of action was not obvious to me.

Regardless, changed xml file to thing-type only, changed binding constants to THING_TYPE, and changed from BridgeHandler to ThingHandler (also replacing all bridge references). Still, the same outcome: NPE as part of initialize(). I.e. initialize --> void method call with http request --> check if response contains certain element --> updateStatus(ThingStatus.ONLINE) --> return;

What actually had to be done to get Thing ONLINE:
Initialize --> String method call with http request --> check if response contains certain element --> return element else null --> check if element contains element or null and updateStatus (ONLINE/OFFLINE) inside initialize().