openhab / openhab-addons

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

[senechome] `ArrayIndexOutOfBoundsException` after battery module change to LFP (Senec Home V3) #17298

Closed RealDrDom closed 1 month ago

RealDrDom commented 2 months ago

Expected Behavior

Binding is working after battery module change as before

Current Behavior

After battery module change to the new LFP batteries in the Senec Home V3, the Senec addon is no longer working. Status of the Thing remains "initializing", an exception is thrown during intialization:

2024-08-19 18:33:40.120 [WARN ] [mmon.WrappedScheduledExecutorService] - Scheduled runnable ended with an exception: 
java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
    at org.openhab.binding.senechome.internal.SenecHomeHandler.refreshState(SenecHomeHandler.java:205) ~[?:?]
    at org.openhab.core.cache.ExpiringCache.refreshValue(ExpiringCache.java:101) ~[?:?]
    at org.openhab.core.cache.ExpiringCache.getValue(ExpiringCache.java:72) ~[?:?]
    at org.openhab.binding.senechome.internal.SenecHomeHandler.refresh(SenecHomeHandler.java:133) ~[?:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[?:?]
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) ~[?:?]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) ~[?:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) [?:?]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]
    at java.lang.Thread.run(Thread.java:840) [?:?]

Possible Solution

The json response from Senec V3 (lala.cgi) only includes 2 batteries instead of formerly 4. I think, that could be fixed in SenecHomeHandler.java by checking the size auf the array (lines 205 to 256).

Steps to Reproduce (for Bugs)

Context

Your Environment

lsiepel commented 2 months ago

Can you test an updated version? The jar file is available at the linked PR.

  1. uninstall the current binding
  2. drop the jar file in your openHAB addon folder.
  3. check that all your linked items are updated again and no issuses are mentioned in the log file.

Thanks for reporting!

RealDrDom commented 2 months ago

Wow, you were incredibly fast - thank you very much! Unfortunately, I have been on vacation since this morning. I will try it over the weekend when I'm back—unless someone else has already tested it. :)

lsiepel commented 2 months ago

Wow, you were incredibly fast - thank you very much! Unfortunately, I have been on vacation since this morning. I will try it over the weekend when I'm back—unless someone else has already tested it. :)

Already had several test reports, all looks good. Enjoy your vacation.

RealDrDom commented 2 months ago

I tested the updated version. However, there still/again is an exception with the bugfix:

2024-08-24 20:52:13.082 [WARN ] [mmon.WrappedScheduledExecutorService] - Scheduled runnable ended with an exception: 
java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
    at org.openhab.binding.senechome.internal.SenecHomeHandler.updateQtyStateIfAvailable(SenecHomeHandler.java:142) ~[?:?]
    at org.openhab.binding.senechome.internal.SenecHomeHandler.refreshState(SenecHomeHandler.java:214) ~[?:?]
    at org.openhab.core.cache.ExpiringCache.refreshValue(ExpiringCache.java:101) ~[?:?]
    at org.openhab.core.cache.ExpiringCache.getValue(ExpiringCache.java:72) ~[?:?]
    at org.openhab.binding.senechome.internal.SenecHomeHandler.refresh(SenecHomeHandler.java:131) ~[?:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[?:?]
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) ~[?:?]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) ~[?:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) [?:?]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]
    at java.lang.Thread.run(Thread.java:840) [?:?]

Maybe in SenecHomeHandler.java line 141 it should be ">" instead of ">=" (array size vs. position starting with 0)?

if (valueArray != null && valueArray.length **>=** arrayIndex) {
            updateQtyState(channel, valueArray[arrayIndex], scale, unit, divisor);
        }

Best regards and thank you very much!! :)

lsiepel commented 2 months ago

Maybe in SenecHomeHandler.java line 141 it should be ">" instead of ">=" (array size vs. position starting with 0)?

Yes, thanks, updated jar here: https://1drv.ms/u/s!AnMcxmvEeupwjv9z4GKsp4RZxpWAFg?e=FpXAc9

RealDrDom commented 2 months ago

Super, works great - no exceptions, thing is back in "online" state, values are updated... Thanks for the fix!

openhab-bot commented 3 weeks ago

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/senechome-binding/108152/47