[SOLVED] UID thats higher than max int32 causes exception

While trying to get my Yeelight Bedside Lamp to work with the miio binding I noticed that the Paper UI was not properly functioning (Using the Color item, changing settings did not go through to the lamp and got “reset” to the initial state of the UI). When looking at the debug log I noticed an exception being thrown, which is that my UID (which is being returned by the bedside lamp on the MII_INFO command) is not an integer, but a long (6267812796). This is a bug that also occured when I first got these lamps and as a solution I had to log in on an Xiaomi owned account to update the firmware of these lamps to support long UIDs. I dont know if this exception is why my Paper UI isnt behaving like it should, but I think its still an interesting bug that is worth mentioning.

The debug log:

 21:31:11.125 [DEBUG] [.internal.handler.MiIoAbstractHandler] - Error while handing message {"result":{"life":182857,"token":"xxxxxxxxxxxxxxxxxxxxxx","mac":"xxxxxxxxxxxxxxxx","fw_ver":"1.6.6_0172","hw_ver":"MTK7697","uid":"6267812796","model":"yeelink.light.bslamp1","wifi_fw_ver":"20190313111057","config_type":"app","ap":{"rssi":-61,"ssid":"xxxxxxx","bssid":"xxxxxxx"},"netif":{"localIp":"xxxxxxxxxx","mask":"255.255.255.0","gw":"192.168.178.1","gw_mac":"xxxxxxxxxxxx"},"mmfree":54512},"id":327}
com.google.gson.JsonSyntaxException: java.lang.NumberFormatException: For input string: "6267812796"
        at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:227) ~[bundleFile:?]
        at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:217) ~[bundleFile:?]
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129) ~[bundleFile:?]
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220) ~[bundleFile:?]
        at com.google.gson.Gson.fromJson(Gson.java:888) ~[bundleFile:?]
        at com.google.gson.Gson.fromJson(Gson.java:953) ~[bundleFile:?]
        at com.google.gson.Gson.fromJson(Gson.java:926) ~[bundleFile:?]
        at org.openhab.binding.miio.internal.handler.MiIoAbstractHandler.updateProperties(MiIoAbstractHandler.java:358) ~[bundleFile:?]
        at org.openhab.binding.miio.internal.handler.MiIoAbstractHandler.defineDeviceType(MiIoAbstractHandler.java:353) ~[bundleFile:?]
        at org.openhab.binding.miio.internal.handler.MiIoAbstractHandler.onMessageReceived(MiIoAbstractHandler.java:462) [bundleFile:?]
        at org.openhab.binding.miio.internal.handler.MiIoBasicHandler.onMessageReceived(MiIoBasicHandler.java:499) [bundleFile:?]
        at org.openhab.binding.miio.internal.transport.MiIoAsyncCommunication$MessageSenderThread.run(MiIoAsyncCommunication.java:236) [bundleFile:?]
Caused by: java.lang.NumberFormatException: For input string: "6267812796"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[?:1.8.0_152]
        at java.lang.Integer.parseInt(Integer.java:583) ~[?:1.8.0_152]
        at java.lang.Integer.parseInt(Integer.java:615) ~[?:1.8.0_152]
        at com.google.gson.JsonPrimitive.getAsInt(JsonPrimitive.java:264) ~[bundleFile:?]
        at com.google.gson.internal.bind.JsonTreeReader.nextInt(JsonTreeReader.java:243) ~[bundleFile:?]
        at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:225) ~[bundleFile:?]
        ... 11 more

Yes, that is definitively a bug that needs to be tacked. I made a quick fix for it, so it won’t crash there.
Note, if you downgrade the binding to 2.5.3 this most likely not error, so maybe workaround until the fix is merged.

it was merged super fast… so most likely in todays snapshot build

Awesome, thanks! i will check somewhere today if the resulting bug(s) are fixed

The error is fixed, but the problem that resulted in me finding this exception isnt. Which might be because I am using 2.4.1 OH in combination with the 2.5.5-SNAPSHOT jar of the Miio binding. When Im able to apt-get the 2.5.5-SNAPSHOT OH build and the problem still isnt fixed I’ll make a separate thread about that problem.