michielpost / Q42.HueApi

C# helper library to talk to the Philips Hue bridge
MIT License
409 stars 114 forks source link

Newtonsoft.Json.JsonSerializationException in GetSensors? #78

Closed niels9001 closed 7 years ago

niels9001 commented 7 years ago

Seems there's a bug in the GetSensors call with the new API changes.

I get the following error:

Exception thrown: 'Newtonsoft.Json.JsonSerializationException' in Newtonsoft.Json.dll

in Sensor Sensor = JsonConvert.DeserializeObject<Sensor>(prop.Value.ToString());

with this JSON:

{ "1": { "state": { "daylight": true, "lastupdated": "2016-09-20T05:55:00" }, "config": { "on": true, "configured": true, "sunriseoffset": 30, "sunsetoffset": -30 }, "name": "Daylight", "type": "Daylight", "modelid": "PHDL00", "manufacturername": "Philips", "swversion": "1.0" }, "2": { "state": { "buttonevent": 34, "lastupdated": "2016-09-20T05:39:27" }, "config": { "on": true }, "name": "Tap", "type": "ZGPSwitch", "modelid": "ZGPSWITCH", "manufacturername": "Philips", "uniqueid": "00:00:00:00:00:00:00:00-00" }, "5": { "state": { "buttonevent": 4002, "lastupdated": "2016-09-20T08:38:42" }, "config": { "on": true, "battery": 100, "reachable": true, "pending": [] }, "name": "Dimmer", "type": "ZLLSwitch", "modelid": "RWL021", "manufacturername": "Philips", "swversion": "5.45.1.17846", "uniqueid": "00:00:00:00:00:00:00:00-01" } }

niels9001 commented 7 years ago

I double-checked with another system, and also the older version of the API. The bug is not occuring with the older version of the API, so I guess it has to do with the deserialization of the Sensor type, which was changed in the newer version. Hope this helps.

michielpost commented 7 years ago

Will have a look at this tomorrow.

michielpost commented 7 years ago

Should be fixed in version 3.2.0 that's now on NuGet

niels9001 commented 7 years ago

Yep, all works now. Thanks! I'm closing this issue

StefanRademakers commented 7 years ago

Seems there's is another bug in the GetSensors call

Sensor scene = JsonConvert.DeserializeObject (prop.Value.ToString ());

The prop.value:

{ "state": { "daylight": null, "lastupdated": "none" }, "config": { "on": true, "configured": false, "sunriseoffset": 30, "sunsetoffset": -30 }, "name": "Daylight", "type": "Daylight", "modelid": "PHDL00", "manufacturername": "Philips", "swversion": "1.0" }

Some extra info

I did not create any sensors myself, only through the philips hue app. But I noticed a motion sensor that was not initialised in the list of sensors..

Some bridge and other info

Bridge ID: 001788FFFE220F12 Model ID: BSB002 API Version: 1.15.0 Software Version: 01035934 Zigbee Channel: 20 Current Device Name: Nexus 5X OS: Android 7.0