Skip to content

Commit

Permalink
Get Streaming info for group
Browse files Browse the repository at this point in the history
  • Loading branch information
michielpost committed Jan 13, 2018
1 parent 834b3b7 commit 18d7bdc
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 14 deletions.
27 changes: 19 additions & 8 deletions src/Q42.HueApi.Streaming.Sample/HueStreaming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Q42.HueApi.Streaming.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
Expand Down Expand Up @@ -39,8 +40,13 @@ public async Task Start()
StreamingHueClient client = new StreamingHueClient(ip, key, entertainmentKey);

//Get the entertainment group
var all = await client.LocalHueClient.GetBridgeAsync();
var group = all.Groups.Where(x => x.Type == HueApi.Models.Groups.GroupType.Entertainment).FirstOrDefault();
var all = await client.LocalHueClient.GetEntertainmentGroups();
var group = all.FirstOrDefault();

if (group == null)
throw new Exception("No Entertainment Group found. Create one using the Q42.HueApi.UniversalWindows.Sample");
else
Console.WriteLine($"Using Entertainment Group {group.Id}");

//Create a streaming group
var entGroup = new StreamingGroup(group.Locations);
Expand All @@ -55,6 +61,10 @@ public async Task Start()
//Optional: calculated effects that are placed in the room
client.AutoCalculateEffectUpdate(entGroup);

//Optional: Check if streaming is currently active
var bridgeInfo = await client.LocalHueClient.GetBridgeAsync();
Console.WriteLine(bridgeInfo.IsStreamingActive ? "Streaming is active" : "Streaming is not active");

//Order lights based on position in the room
var orderedLeft = entGroup.GetLeft().OrderByDescending(x => x.LightLocation.Y).ThenBy(x => x.LightLocation.X);
var orderedRight = entGroup.GetRight().OrderByDescending(x => x.LightLocation.Y).ThenByDescending(x => x.LightLocation.X);
Expand Down Expand Up @@ -130,21 +140,22 @@ public async Task Start()

Console.WriteLine("A red light that is moving in horizontal direction and is placed on an XY grid, matching your entertainment setup");
var redLightEffect = new RedLightEffect();
redLightEffect.Radius = 0.5;
redLightEffect.Y = -1;
redLightEffect.Radius = 0.3;
redLightEffect.Y = -0.8;
redLightEffect.X = -0.8;
entGroup.PlaceEffect(redLightEffect);
redLightEffect.Start();

Task.Run(async () =>
{
double step = 0.1;
double step = 0.2;
while (true)
{
redLightEffect.X += step;
redLightEffect.Y += step;
await Task.Delay(100);
if (redLightEffect.X >= 1.5)
if (redLightEffect.Y >= 2)
step = -0.1;
if (redLightEffect.X <= -1.5)
if (redLightEffect.Y <= -2)
step = +0.1;
}
}, cst.Token);
Expand Down
2 changes: 0 additions & 2 deletions src/Q42.HueApi.Streaming/Models/Transition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ public void UpdateCurrentState()

var progress = sw.Elapsed.TotalMilliseconds / this.TimeSpan.TotalMilliseconds;

Debug.WriteLine("Progress: " + progress);

if (progress > 1)
{
SetFinalState(TargetRgb, TargetBri);
Expand Down
4 changes: 2 additions & 2 deletions src/Q42.HueApi/HueClient-Groups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ public async Task<IReadOnlyCollection<Group>> GetGroupsAsync()

}

public async Task<Group> GetEntertainmentGroup()
public async Task<IReadOnlyList<Group>> GetEntertainmentGroups()
{
var allGroups = await GetGroupsAsync();
return allGroups.Where(x => x.Type == Models.Groups.GroupType.Entertainment).First();
return allGroups.Where(x => x.Type == Models.Groups.GroupType.Entertainment).ToList();
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Q42.HueApi/Interfaces/ILocalHueClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ public interface ILocalHueClient : IHueClient
/// Returns the entertainment group
/// </summary>
/// <returns></returns>
Task<Group> GetEntertainmentGroup();
Task<IReadOnlyList<Group>> GetEntertainmentGroups();
}
}
13 changes: 12 additions & 1 deletion src/Q42.HueApi/Models/Bridge/Bridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal Bridge(BridgeState bridge)
/// Light info from the bridge
/// </summary>
public IEnumerable<Light> Lights { get; private set; }
public IEnumerable<Group> Groups { get; private set; }
public IEnumerable<Group> Groups { get; private set; } = Enumerable.Empty<Group>();

/// <summary>
/// Bridge config info
Expand All @@ -61,5 +61,16 @@ internal Bridge(BridgeState bridge)
/// </summary>
public IEnumerable<WhiteList> WhiteList { get; private set; }

/// <summary>
/// Is Hue Entertainment API used on a group right now?
/// </summary>
public bool IsStreamingActive
{
get
{
return Groups.Any(x => x.Stream?.Active ?? false);
}
}

}
}
19 changes: 19 additions & 0 deletions src/Q42.HueApi/Models/Groups/Group.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public class Group
[DataMember(Name = "locations")]
public Dictionary<string, LightLocation> Locations { get; set; }

[DataMember(Name = "recycle")]
public bool? Recycle { get; set; }

[DataMember(Name = "stream")]
public Stream Stream { get; set; }

}

public class LightLocation : List<double>
Expand Down Expand Up @@ -164,4 +170,17 @@ public enum RoomClass
TV
}

[DataContract]
public class Stream
{
[DataMember(Name = "proxymode")]
public string ProxyMode { get; set; }
[DataMember(Name = "proxynode")]
public string ProxyNode { get; set; }
[DataMember(Name = "active")]
public bool Active { get; set; }
[DataMember(Name = "owner")]
public string Owner { get; set; }
}

}

0 comments on commit 18d7bdc

Please sign in to comment.