Skip to content

Commit

Permalink
Resolve Issue qJake#4 - Correct JSON Parsing based on the Property Na…
Browse files Browse the repository at this point in the history
…me in the JSON instead of guessing @ the Index number
  • Loading branch information
BobDaMann committed Feb 21, 2016
1 parent aca2039 commit f4e68e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
20 changes: 7 additions & 13 deletions SharpHue/Lights/LightCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Net.Http;
using Newtonsoft.Json.Linq;
using System;

namespace SharpHue
{
Expand Down Expand Up @@ -69,20 +70,13 @@ public void Refresh()

JObject lights = JsonClient.RequestSecure(HttpMethod.Get, "/lights") as JObject;

for (int i = 1; i <= Configuration.MAX_LIGHTS; i++)
foreach (KeyValuePair<string, JToken> light in lights)
{
if (lights[i.ToString()] != null)
{
Light l = ((JObject)lights[i.ToString()]).ToObject<Light>();
l.ID = i;
l.RefreshState();
Lights.Add(l);
}
else
{
// Lights are sequential, break if we don't have a light with the specified index.
break;
}
Light l = new Light();
l = light.Value.ToObject<Light>();
l.ID = Convert.ToInt16(light.Key);
Lights.Add(l);
l.RefreshState();
}
}

Expand Down
5 changes: 2 additions & 3 deletions SharpHue/SharpHue.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
<HintPath>..\packages\Newtonsoft.Json.5.0.6\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down

0 comments on commit f4e68e9

Please sign in to comment.