openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.88k stars 3.59k forks source link

HomeKit extension: NullPointerException when binding is not set in item #1810

Closed lauhub closed 7 years ago

lauhub commented 7 years ago

The problem

I installed OpenHab 2.0.0 (Release Build) on a Debian Jessie installation.

I try to pair from an iOS device using Homekit and get a NullPointerException error:

17:46:30.956 [WARN ] [nhab.io.homekit.internal.HomekitImpl] - Could not find existing MAC in org.eclipse.smarthome.storage.json.JsonStorage. Generating new MAC. This will require re-pairing of iOS devices.
17:47:46.096 [ERROR] [lfe.hap.impl.connections.HttpSession] - Could not handle request
java.lang.NullPointerException
    at com.beowulfe.hap.characteristics.FloatCharacteristic.getValue(FloatCharacteristic.java:72)[211:org.openhab.io.homekit:2.0.0]
    at com.beowulfe.hap.characteristics.BaseCharacteristic.makeBuilder(BaseCharacteristic.java:71)[211:org.openhab.io.homekit:2.0.0]
    at com.beowulfe.hap.characteristics.FloatCharacteristic.makeBuilder(FloatCharacteristic.java:48)[211:org.openhab.io.homekit:2.0.0]
    at com.beowulfe.hap.characteristics.BaseCharacteristic.toJson(BaseCharacteristic.java:61)[211:org.openhab.io.homekit:2.0.0]
    at com.beowulfe.hap.impl.json.AccessoryController.toJson(AccessoryController.java:73)[211:org.openhab.io.homekit:2.0.0]
    at com.beowulfe.hap.impl.json.AccessoryController.listing(AccessoryController.java:39)[211:org.openhab.io.homekit:2.0.0]
    at com.beowulfe.hap.impl.connections.HttpSession.handleAuthenticatedRequest(HttpSession.java:70)[211:org.openhab.io.homekit:2.0.0]
    at com.beowulfe.hap.impl.connections.ConnectionImpl.doHandleRequest(ConnectionImpl.java:51)[211:org.openhab.io.homekit:2.0.0]
    at com.beowulfe.hap.impl.connections.ConnectionImpl.handleRequest(ConnectionImpl.java:46)[211:org.openhab.io.homekit:2.0.0]
    at com.beowulfe.hap.impl.http.impl.AccessoryHandler.channelRead0(AccessoryHandler.java:47)[211:org.openhab.io.homekit:2.0.0]
    at com.beowulfe.hap.impl.http.impl.AccessoryHandler.channelRead0(AccessoryHandler.java:15)[211:org.openhab.io.homekit:2.0.0]
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)[211:org.openhab.io.homekit:2.0.0]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)[211:org.openhab.io.homekit:2.0.0]
    at io.netty.channel.AbstractChannelHandlerContext.access$600(AbstractChannelHandlerContext.java:32)[211:org.openhab.io.homekit:2.0.0]
    at io.netty.channel.AbstractChannelHandlerContext$7.run(AbstractChannelHandlerContext.java:299)[211:org.openhab.io.homekit:2.0.0]
    at io.netty.util.concurrent.DefaultEventExecutor.run(DefaultEventExecutor.java:36)[211:org.openhab.io.homekit:2.0.0]
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)[211:org.openhab.io.homekit:2.0.0]
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)[211:org.openhab.io.homekit:2.0.0]
    at java.lang.Thread.run(Thread.java:745)[:1.8.0_121]

The same configuration was working with openhab2 Beta4. I test with Beta5 and I got the same error.

Re-installing the beta4 after beta5 solved the problem.

What it should do

The problem here is that we should have a comprehensive message instead of that NullPointerException: user should know what happened, why and possibly how to correct it (with a lead to documentation for instance)

lauhub commented 7 years ago

Writing a rule is a possible workaround to this problem.

Here is an example as I wrote it for one of the items:

rule "Initialize Philips Hue"
when 
        System started 
then 
        logInfo( "Initializer", "Started Timer ...")
        createTimer(now.plusSeconds(45)) [|     
                logInfo( "Initializer", "Initializing...")

                sendCommand("Hue_Spot1","0,0,0")
                logInfo( "Initializer", "")
        ]

end

With this item definition:

Color Hue_Spot1      "Hue 1"       [ "Lighting" ]
codefalk commented 7 years ago

Have the same problem and also make use of the workaround defined. Issue #2002 described the problem and has been closed as duplicate.

martinvw commented 7 years ago

@lauhub can you check whether the mentioned PR resolved your problem, it is already merged so the last snapshot should work fine for you. Please reopen if that is not the case.