ZeroOne3010 / yetanotherhueapi

A Java library for controlling Philips Hue lights. Available from the Maven Central.
MIT License
68 stars 21 forks source link

TemperatureSensor#getDegreesCelsius NPE #51

Closed NathanSweet closed 2 years ago

NathanSweet commented 2 years ago
for (TemperatureSensor sensor : bridge.getTemperatureSensors())
    System.out.println(sensor.getDegreesCelsius());

Gives me:

java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because the return value of "io.github.zeroone3010.yahueapi.TemperatureSensorImpl.readStateValue(String, java.lang.Class)" is null
    at io.github.zeroone3010.yahueapi.TemperatureSensorImpl.getDegreesCelsius(TemperatureSensorImpl.java:30)
ZeroOne3010 commented 2 years ago

Interesting. I cannot reproduce this with my setup, where the only temperature sensors are in two Hue motion sensors. Could you provide the JSON that your Bridge returns on sensors? Temperature sensors are supposed to be the ones where "type" is either "zlltemperature" or "cliptemperature".

NathanSweet commented 2 years ago

I have two Hue motion sensors. How do I see the JSON with your library?

ZeroOne3010 commented 2 years ago

Technically you can't do that, but calling hue.getRaw().getSensors() would be the next best thing. :)

NathanSweet commented 2 years ago

Here you go!

4={"name":"Hue temperature sensor 1","type":"ZLLTemperature","state":{"temperature":null,"lastupdated":"none"},"swupdate":{"state":"noupdates","lastinstall":"2022-02-05T19:57:32"},"config":{"on":false,"battery":100,"reachable":true,"alert":"none","ledindication":false,"usertest":false,"pending":[]},"modelid":"SML001","manufacturername":"Signify Netherlands B.V.","swversion":"6.1.1.27575","uniqueid":"00:17:88:01:09:19:76:4a-02-0402","recycle":null,"productname":"Hue temperature sensor","capabilities":{"certified":true,"primary":false,"inputs":null}}
9={"name":"Hue temperature sensor 2","type":"ZLLTemperature","state":{"temperature":null,"lastupdated":"none"},"swupdate":{"state":"noupdates","lastinstall":"2022-02-05T19:57:25"},"config":{"on":false,"battery":100,"reachable":true,"alert":"none","ledindication":false,"usertest":false,"pending":[]},"modelid":"SML001","manufacturername":"Signify Netherlands B.V.","swversion":"6.1.1.27575","uniqueid":"00:17:88:01:09:19:78:9b-02-0402","recycle":null,"productname":"Hue temperature sensor","capabilities":{"certified":true,"primary":false,"inputs":null}}

Maybe the sensors have never reported a temperature to the lib? I haven't been running the lib much, and not for long periods of time.

ZeroOne3010 commented 2 years ago

Thanks! This reminds me of #34 where a daylight sensor was throwing an NPE for someone who was using the Apple Home Kit instead of the official app. Would you happen to be using that (or some other special software)?

NathanSweet commented 2 years ago

I'm just using Java and 2 Hue motion sensors. It's the first thing I've tried to do with the library.

ZeroOne3010 commented 2 years ago

Right, I don't think this library can confuse the Bridge. Have you taken those motion sensors into use in the app in any way, like are they supposed to be controlling some lights in your house?

Anyway, I should certainly fix the library so that it doesn't throw if the temperature is null.

NathanSweet commented 2 years ago

Figured it out: the motion sensors were disabled in the Hue app. Once enabled I get temperature values.

ZeroOne3010 commented 2 years ago

Excellent, thank you for the information!

ZeroOne3010 commented 2 years ago

This has now been fixed in version 2.6.0.