openhab / openhab1-addons

Add-ons for openHAB 1.x
Eclipse Public License 2.0
3.43k stars 1.69k forks source link

Tellstick Binding - Increase / Decrease Nullpoint Exception #1014

Closed EliasGabrielsson closed 10 years ago

EliasGabrielsson commented 10 years ago

Usecase I have an dimmer class device configured in telldus Center which I by the Web GUI wants to increase and decrease lightlevel on.

The dimmer works perfect if it is configured like a normal on / off switch in openHAB. Percentbased tuning in telldusCenter work also as intended.

Error: It looks like the binding cant handle the "increase" and "decrease" commands from openHab. I havent looked in to the architecture of openHAB though so I dont know how its works internally.

But what about "increase" / "decrease from last know openHAB percentage value and translate it to fixed values which will be send to the tellstick API ?

07:13:15.431 DEBUG o.o.b.t.i.TellstickBinding[:113]- internalReceiveCommand() is called! for GF_Living_Floorlamp with INCREASE
07:13:15.431 INFO  o.o.b.t.i.TellstickController[:34]- Send INCREASE to TellstickDevice [deviceId=1, name=LIVINGROOM-floor, status=2, deviceType=1, data=null] time=0 conf TellstickBindingConfig [id=1, valueSelector=DimmingLevel, usageSelector=null, itemName=GF_Living_Floorlamp, resend=1]
07:13:15.447 ERROR o.o.b.t.i.TellstickBinding[:121]- Failed to send msg to TellstickBindingConfig [id=1, valueSelector=DimmingLevel, usageSelector=null, itemName=GF_Living_Floorlamp, resend=1]
java.lang.NullPointerException: null
    at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
    at java.lang.Double.valueOf(Unknown Source)
    at org.openhab.binding.tellstick.internal.TellstickController.increaseDecrease(TellstickController.java:69)
    at org.openhab.binding.tellstick.internal.TellstickController.handleSendEvent(TellstickController.java:56)
    at org.openhab.binding.tellstick.internal.TellstickBinding.internalReceiveCommand(TellstickBinding.java:119)
    at org.openhab.core.binding.AbstractBinding.receiveCommand(AbstractBinding.java:96)
    at org.openhab.core.events.AbstractEventSubscriber.handleEvent(AbstractEventSubscriber.java:42)
    at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197)
    at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
    at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
    at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
    at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
    at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
    at org.openhab.core.internal.events.EventPublisherImpl.sendCommand(EventPublisherImpl.java:56)
    at org.openhab.ui.webapp.internal.servlet.CmdServlet.service(CmdServlet.java:95)
    at org.eclipse.equinox.http.servlet.internal.ServletRegistration.service(ServletRegistration.java:61)
    at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:128)
    at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:60)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:598)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:486)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1065)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:413)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:999)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111)
    at org.eclipse.jetty.server.Server.handle(Server.java:350)
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:454)
    at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:890)
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:944)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:630)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:230)
    at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:606)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:46)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:603)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:538)
    at java.lang.Thread.run(Unknown Source)

Configuration:

sitemap default label="Home"

Frame label="Lights" {
    Switch item=GF_Bedroom_Bed
    Switch item=GF_Bedroom_Window
    Slider item=GF_Living_Floorlamp
    }

Items:

Group    All
Group    gGF    (All)       
Group    gC    (All)       
Group    GF_Living                "Living Room"        <sofa>        (gGF)
Group    GF_Bedroom                "Bedroom"            <sofa>        (gGF)   
Group    GF_Kitchen                "Kitchen"            <kitchen>    (gGF)       
Group    GF_Corridor                "Corridor"            <corridor>    (gGF)   
Group:Switch:OR(ON,OFF)    Lights    "All Lights [(%d)]"    <light>        (All)   

Dimmer    GF_Living_Floorlamp        "Dimmer [%d %%]"     <slider>     (GF_Living, Lights) { tellstick="LIVINGROOM-floor:DimmingLevel" }
Switch    GF_Bedroom_Bed            "Bed"                            (GF_Bedroom,Lights)    { tellstick="BEDROOM-bed:Command" }
Switch    GF_Bedroom_Window        "Window"                        (GF_Bedroom,Lights)    { tellstick="BEDROOM-window:Command" }
jarlebh commented 10 years ago

I will look at this

jarlebh commented 10 years ago

Pull request 1019 for this issue

teichsta commented 10 years ago

could you please retest (with tomorrows build) and confirm?

EliasGabrielsson commented 10 years ago

I have tested the new binding from build #598. So far I stumble upon two minor issues.

First sub-issue

Usecase The dimmed light according to config above is set to 93%. I want to INCREASE further to 100% by clicking the "up" arrow in the webgui which will send a INCREASE command. Error The set value goes out of scope (0-100) and throws an exception. The big question is how the tellstickbinding follow the "Binding" framework or if its wrong implemented. Should the binding automatic adjust the value to 100% or should the eventbus resend a new 100% command? @teichsta Any comment?

An identical problem exist on the lower half. Eg. I have the lamp set to 4% and try to decrease it which will throw the same error.

20:21:20.850 INFO  o.o.b.t.i.TellstickController[:36]- Send INCREASE to TellstickDevice [deviceId=9, name=LIVINGROOM-floor, status=16, deviceType=1, data=242] time=0 conf TellstickBindingConfig [id=9, valueSelector=DimmingLevel, usageSelector=null, itemName=GF_Living_Floorlamp, resend=1]
20:21:20.850 ERROR o.o.b.t.i.TellstickBinding[:121]- Failed to send msg to TellstickBindingConfig [id=9, valueSelector=DimmingLevel, usageSelector=null, itemName=GF_Living_Floorlamp, resend=1]
java.lang.IllegalArgumentException: Value must be between 0 and 100
    at org.openhab.core.library.types.PercentType.validateValue(PercentType.java:48)
    at org.openhab.core.library.types.PercentType.<init>(PercentType.java:33)
    at org.openhab.binding.tellstick.internal.TellstickController.increaseDecrease(TellstickController.java:87)
    at org.openhab.binding.tellstick.internal.TellstickController.handleSendEvent(TellstickController.java:58)
    at org.openhab.binding.tellstick.internal.TellstickBinding.internalReceiveCommand(TellstickBinding.java:119)
    at org.openhab.core.binding.AbstractBinding.receiveCommand(AbstractBinding.java:96)
    at org.openhab.core.events.AbstractEventSubscriber.handleEvent(AbstractEventSubscriber.java:42)
    at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197)
...

Second sub-issue

Usecase I want to configure the light level with the down and up buttons in the web GUI. I have a dimmed device which got an "ON" state change to the eventbus. openHAB dosent know which level the device is on for sure due the wide nature of dimmer type to tellstick. BUT probably the dimmed device have a high dim level rather then a low.

Today's implementation When pushing the down button the value goes to 0. When pushing the up button values goes to 9. (0 + 9). The values start on zero in other word.

My new proposal To me its more natural to start on max and modify it from there due many dimmers will be on max when state is ON. Down button will start on 100 - 9 = 91. Up button will start on 100.

@teichsta, what is the best practise and design principles for openHAB?

jarlebh commented 10 years ago

Actually there should be a limit to avoid going above 100 or below 0, but I can see that the code expect increments of 10 (it only checks current level is below 100 before adding 10). I will fix the limit so it handles any increment and goes to 100 instead of 106.

The second issue would be nice with a comment on, I actually only use the dimmer on a phone where i have a slider instead of these increments.

jarlebh commented 10 years ago

I fixed the problem with 0-100 for PrecentType, but not sure if I can do anything with the other issue. The only thing I can see is to go to 100% if current dim value is 0, is this how it should behave ? I also find it weird that there is no shortcut to go to max.