nibi79 / worxlandroid

openHAB Binding for Worx Landroid
60 stars 20 forks source link

Error when "time_zone" is empty/null - Items not getting updated #43

Closed c--r closed 4 years ago

c--r commented 4 years ago

Hi,

first of all thanks for this very useful binding!

I observed an exception when running it:

2020-06-15 22:35:28.833 [DEBUG] [nternal.webapi.request.WebApiRequest] - Worx Landroid WebApi Response: [{"id":xxxxxx,"product_id":49,"user_id":199915,"serial_number":"xxxxxx","mac_address":"xxxxxx","name":"M","locked":false,"firmware_version":3.08,"firmware_auto_upgrade":false,"push_notifications":true,"sim":null,"push_notifications_level":"notice","test":0,"iot_registered":true,"pin_code":null,"registered_at":"2019-06-01 00:00:00","online":true,"app_settings":null,"accessories":null,"features":{"unrestricted_mowing_time":true,"multi_zone":true,"wifi_connection":"smartlink_tube_display","display_type":"tube","lock":true,"pin":true,"rain_delay":true,"chassis":"m_2019","mqtt":true,"provisionable":true,"wifi_pairing":"smartlink","tracking_firmware":true,"provisoning_replaceable":true,"rain_delay_start":3.08,"one_time_scheduler":3.09},"pending_radio_link_validation":null,"mqtt_topics":{"command_in":"PRM100\/xxxxxxx\/commandIn","command_out":"PRM100\/xxxxxxx\/commandOut"},"warranty_registered":true,"purchased_at":"2019-05-27 00:00:00","warranty_expires_at":"2022-05-27 00:00:00","setup_location":null,"city":null,"time_zone":null,"lawn_size":220,"lawn_perimeter":86,"auto_schedule_settings":null,"auto_schedule":false,"distance_covered":225700,"mower_work_time":12836,"blade_work_time":12050,"blade_work_time_reset":8680,"blade_work_time_reset_at":null,"battery_charge_cycles":165,"battery_charge_cycles_reset":118,"battery_charge_cycles_reset_at":null,"messages_in":421,"messages_out":30610,"raw_messages_in":1423,"raw_messages_out":30610,"created_at":"2019-03-16 05:40:03","updated_at":"2020-06-12 17:01:20"}] 2020-06-15 22:35:28.845 [DEBUG] [core.thing.internal.ThingManagerImpl] - Only updating thing worxlandroid:mower:LandroidBridge1:xxxxxx in the registry because provider org.eclipse.smarthome.model.thing.internal.GenericThingProvider@14714b4 is not managed. 2020-06-15 22:35:28.876 [DEBUG] [nternal.webapi.request.WebApiRequest] - URI: https://api.worxlandroid.com/api/v2/product-items/xxxxxx/status 2020-06-15 22:35:28.968 [DEBUG] [nternal.webapi.request.WebApiRequest] - Worx Landroid WebApi Response: {"cfg":{"id":0,"lg":"it","tm":"22:34:29","dt":"15\/06\/2020","sc":{"m":1,"p":0,"d":[["18:30",0,0],["18:30",120,1],["18:30",120,0],["18:30",120,0],["18:30",120,1],["18:30",120,0],["18:30",0,0]]},"cmd":0,"mz":[0,0,0,0],"mzv":[0,0,0,0,0,0,0,0,0,0],"rd":120,"sn":"xxxxxx"},"dat":{"mac":"xxxxxx","fw":3.08,"bt":{"t":19.4,"v":19.8,"p":100,"nr":166,"c":0,"m":0},"dmp":[0.6,-0.6,17.2],"st":{"b":12136,"d":227235,"wt":12930,"bl":86},"ls":1,"le":5,"lz":0,"rsi":-65,"lk":0,"act":1,"tr":0,"conn":"wifi"}} 2020-06-15 22:35:28.975 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.initialize()' on 'org.openhab.binding.worxlandroid.internal.WorxLandroidMowerHandler@11b7c1e': Invalid ID for ZoneOffset, invalid format: java.time.DateTimeException: Invalid ID for ZoneOffset, invalid format: at java.time.ZoneOffset.of(ZoneOffset.java:241) ~[?:?] at java.time.ZoneId.of(ZoneId.java:405) ~[?:?] at java.time.ZoneId.of(ZoneId.java:359) ~[?:?] at org.openhab.binding.worxlandroid.internal.WorxLandroidMowerHandler.updateStateCfg(WorxLandroidMowerHandler.java:786) ~[?:?] at org.openhab.binding.worxlandroid.internal.WorxLandroidMowerHandler.processStatusMessage(WorxLandroidMowerHandler.java:611) ~[?:?] at org.openhab.binding.worxlandroid.internal.WorxLandroidMowerHandler.initialize(WorxLandroidMowerHandler.java:235) ~[?:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?] at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [102:org.eclipse.smarthome.core:0.10.0.oh240] at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:53) [102:org.eclipse.smarthome.core:0.10.0.oh240] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?] at java.lang.Thread.run(Thread.java:748) [?:?]

This seems to be caused by the"time_zone":null parameter in the API response. I've checked the Landroid registration page, but there does not seem to be a way to set a timezone for my mower.

This code section in WorxLandroidMowerHandler.java does not handle this situation properly:

ZoneId zoneId = ZoneId.of(getThing().getProperties().get("time_zone")); ZonedDateTime zonedDateTime = ZonedDateTime.of(localeDateTime, zoneId); updateState(CHANNELNAME_DATETIME, new DateTimeType(zonedDateTime));

... which throws an exception and causes all Openhab items not getting updated.

nibi79 commented 4 years ago

You are right! There must be a default timezone. I'll check this tomorrow.

Have you set 'location' in the preferences of the landroid app?

c--r commented 4 years ago

Indeed, that seems to be the place where the location gets set and the timezone calculated. I have not set the field in the app (seems not to be mandatory, at least not 1+ year ago when I registered first time :) ).