Skip to content
This repository has been archived by the owner on Jul 18, 2020. It is now read-only.

Commit

Permalink
Merge pull request #244 from Hyrules/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Hyrules authored Jun 25, 2019
2 parents 321ec4f + 35c8bc6 commit 9653c21
Show file tree
Hide file tree
Showing 47 changed files with 710 additions and 1,117 deletions.
42 changes: 42 additions & 0 deletions HueLib2Test/Communication/CommunicationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WinHue3.Philips_Hue;
using WinHue3.Philips_Hue.Communication2;

namespace WinHueTest.Communication
{
[TestClass]
public class CommunicationTests
{
private string baseUri;
private string badbaseUri;

[TestInitialize]
public void InitTests()
{
baseUri = "http://192.168.5.30/api/30jodHoH6BvouvzmGR-Y8nJfa0XTN1j8sz2tstYJ/";
badbaseUri = "http://192.168.5.29/api/30jodHoH6BvouvzmGR-Y8nJfa0XTN1j8sz2tstYJ/";
HueHttpClient.Timeout = 3000;
}


[TestMethod]
public void GetTest()
{
HttpResult res = HueHttpClient.SendRequest( new Uri(baseUri + "lights"), WebRequestType.Get);
Assert.IsTrue(res.Success);
}

[TestMethod]
public void GetBadTest()
{
HttpResult res = HueHttpClient.SendRequest(new Uri(badbaseUri + "lights"), WebRequestType.Get);
Assert.IsFalse(res.Success);
}
}
}
4 changes: 1 addition & 3 deletions HueLib2Test/Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Interactivity">
<HintPath>..\packages\System.Windows.Interactivity.WPF.2.0.20525\lib\net40\System.Windows.Interactivity.dll</HintPath>
</Reference>
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
Expand All @@ -91,6 +88,7 @@
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="Communication\CommunicationTests.cs" />
<Compile Include="Groups\GroupSerializationTests.cs" />
<Compile Include="Groups\GroupViewModelTests.cs" />
<Compile Include="Lights\LightSerializationTests.cs" />
Expand Down
54 changes: 2 additions & 52 deletions HueLib2Test/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;
using Newtonsoft.Json;
using Org.BouncyCastle.Crypto.Tls;
using Org.BouncyCastle.Security;
using WinHue3.ExtensionMethods;
using WinHue3.Philips_Hue.BridgeObject.BridgeObjects;
using WinHue3.Philips_Hue.Communication;
using WinHue3.Philips_Hue.HueObjects.NewSensorsObject;
using WinHue3.Utils;
using WinHue3.Functions.Rules.Creator;
using WinHue3.Philips_Hue.HueObjects.LightObject;
using Org.BouncyCastle.Utilities;
using WinHue3.Philips_Hue.BridgeObject.Entertainment_API;
using WinHue3.Functions.Animations2;
using WinHue3.Functions.Converters;
using WinHue3.Functions.Rules;
using WinHue3.Philips_Hue.BridgeObject;
using WinHue3.Philips_Hue.HueObjects.Common;
using System.Net.Http;

namespace WinHueTest
{
Expand All @@ -50,31 +23,8 @@ public void TestHueObject()
[TestMethod]
public void HttpGetTest()
{
HttpClient client = new HttpClient
{
Timeout = new TimeSpan(0, 0, 0, 3000),
BaseAddress = new Uri("http://banane/api/1234567890/")
};
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response;
try
{
response = client.GetAsync("lights").Result;
if (response.IsSuccessStatusCode)
{
Task<string> task = response.Content.ReadAsStringAsync();
task.RunSynchronously();
string data = task.Result;
}
else
{

}
}
catch(WebException ex)
{
Assert.Fail(ex.Message.ToString());
}




}
Expand Down
19 changes: 5 additions & 14 deletions WinHue3/Build/README_TEMPLATE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,20 @@ You might also need Visual C++ 2010 Redistributable library.
Both are available at Microsoft's website.

Fixed:

- Exporting config from the main menu caused a crash.
- A bug where editing a rule action caused a crash.
- Update manager not pointing to the right address.
- Cloning rule giving an error.
- Cloning scenes giving an error.
- Fixed rule creator behavior when creating rule with hidden or group zero.
- Unable to save rules or edit them.
- No Archetype resulting in an exception while getting the light type.

Added:
- Added the streaming trigger to the context menu. Won't do anything at the moment beside triggering the streaming flag on the entertainment group.
- Entertainement Creator now available. You can create entertainment group. ( Not currently used in WinHue )
- Smaller icon view.

Changed:
- Way the light are displayed. Removed the unreachable light image needed.
- Unreachable will now show as greyed out.
- Simplified Schedule deserialization / serialization.
- Simplified rule deserialization / serialization.
- Replace webclient with Httpclient.

Updated :
-

Removed :
- Delete button of the User management window. Philips has now removed the possibility for the API users to remove users. You need to use philips portal to do so : https://account.meethue.com/apps
-

WIP:
- Animation creator. (Not Available yet)
Expand Down
14 changes: 9 additions & 5 deletions WinHue3/Functions/Advanced Creator/AdvancedCreatorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
using System.Windows.Forms;
using System.Windows.Input;
using Newtonsoft.Json;
using WinHue3.Functions.BridgeManager;
using WinHue3.Philips_Hue;
using WinHue3.Philips_Hue.BridgeObject;
using WinHue3.Utils;
using MessageBox = System.Windows.Forms.MessageBox;
using WebRequestType = WinHue3.Philips_Hue.Communication.WebRequestType;


namespace WinHue3.Functions.Advanced_Creator
{
Expand All @@ -19,13 +19,17 @@ public class AdvancedCreatorViewModel : ValidatableBindableBase
private string _url;
private Bridge _bridge;

public AdvancedCreatorViewModel(Bridge bridge)
public AdvancedCreatorViewModel()
{
_bridge = bridge;
_text = string.Empty;
_type = string.Empty;
_requestType = WebRequestType.Post;
_url = string.Empty;
_requestType = WebRequestType.Post;
}

public void Initialize(Bridge bridge)
{
_bridge = bridge;
}

private void CreateScheduleTemplate()
Expand Down
9 changes: 5 additions & 4 deletions WinHue3/Functions/Advanced Creator/Form_AdvancedCreator.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
xmlns:advancedCreator="clr-namespace:WinHue3.Functions.Advanced_Creator"
xmlns:behaviors="clr-namespace:WinHue3.Functions.Behaviors"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:philipsHue="clr-namespace:WinHue3.Philips_Hue"
mc:Ignorable="d"
Title="{x:Static resx:GUI.MainForm_Tab_Home_Group_Creators_AdvancedCreator}" Height="600" Width="800" ResizeMode="CanResizeWithGrip" MinHeight="600" MinWidth="800" Icon="/WinHue3;component/Resources/advanced.png" WindowStartupLocation="CenterOwner" Name="Window">
<Window.DataContext>
Expand Down Expand Up @@ -59,10 +60,10 @@

<xctk:WatermarkTextBox TextWrapping="Wrap" Height="28" Text="{Binding Url, UpdateSourceTrigger=PropertyChanged}" Margin="30,46,97,0" VerticalAlignment="Top" Watermark="{x:Static resx:GUI.Form_AdvancedCreator_UrlWatermark}"/>
<ComboBox Margin="0,46,0,0" Height="28" VerticalAlignment="Top" HorizontalAlignment="Right" Width="100" SelectedValue="{Binding RequestType}" SelectedValuePath="Content">
<ComboBoxItem Content="POST" Tag="{x:Static comm:WebRequestType.Post}"/>
<ComboBoxItem Content="PUT" Tag="{x:Static comm:WebRequestType.Put}"/>
<ComboBoxItem Content="DELETE" Tag="{x:Static comm:WebRequestType.Delete}"/>
<ComboBoxItem Content="GET" Tag="{x:Static comm:WebRequestType.Get}"/>
<ComboBoxItem Content="POST" Tag="{x:Static philipsHue:WebRequestType.Post}"/>
<ComboBoxItem Content="PUT" Tag="{x:Static philipsHue:WebRequestType.Put}"/>
<ComboBoxItem Content="DELETE" Tag="{x:Static philipsHue:WebRequestType.Delete}"/>
<ComboBoxItem Content="GET" Tag="{x:Static philipsHue:WebRequestType.Get}"/>
</ComboBox>
<avalonedit:TextEditor ShowLineNumbers="True" Margin="0,80,0,20" >
<i:Interaction.Behaviors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ public partial class Form_AdvancedCreator
{
private AdvancedCreatorViewModel _acvm;

public Form_AdvancedCreator(Bridge bridge)
public Form_AdvancedCreator()
{
InitializeComponent();
_acvm = DataContext as AdvancedCreatorViewModel;
_acvm.OnObjectCreated += _acvm_OnObjectCreated;
}

public void Initialize(Bridge bridge)
{
_acvm.Initialize(bridge);
}

private void _acvm_OnObjectCreated(object sender, EventArgs e)
{
OnObjectCreated?.Invoke(this,EventArgs.Empty);
Expand Down
32 changes: 15 additions & 17 deletions WinHue3/Functions/BridgeFinder/BridgeFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
using System.ComponentModel;
using System.Net;
using System.Net.Sockets;
using WinHue3.Functions.Application_Settings.Settings;
using WinHue3.Philips_Hue;
using WinHue3.Philips_Hue.BridgeObject;
using WinHue3.Philips_Hue.Communication;
using WinHue3.Philips_Hue.Communication2;

namespace WinHue3.Functions.BridgeFinder
{
Expand Down Expand Up @@ -88,30 +91,22 @@ private static void _bgw_DoWork(object sender, DoWorkEventArgs e)
ipArray[3] = x;
_bgw.ReportProgress(0, new ProgressReport(new IPAddress(ipArray),x));

Comm.Timeout = 50;
HueHttpClient.Timeout = 50;
if (_bgw.CancellationPending) break;

CommResult comres = Comm.SendRequest(new Uri($@"http://{new IPAddress(ipArray)}/api/config"), WebRequestType.Get);
HttpResult comres = HueHttpClient.SendRequest(new Uri($@"http://{new IPAddress(ipArray)}/api/config"), WebRequestType.Get);
Philips_Hue.BridgeObject.BridgeObjects.BridgeSettings desc = new Philips_Hue.BridgeObject.BridgeObjects.BridgeSettings();

switch (comres.Status)
if (comres.Success)
{
case WebExceptionStatus.Success:
desc = Serializer.DeserializeToObject<Philips_Hue.BridgeObject.BridgeObjects.BridgeSettings>(comres.Data); // try to deserialize the received message.
if (desc == null) continue; // if the deserialisation didn't work it means this is not a bridge continue with next ip.
if (desc.mac == mac)
{
e.Result = new IPAddress(ipArray);
break;
}

break;
case WebExceptionStatus.Timeout:
// IP DOES NOT RESPOND
desc = Serializer.DeserializeToObject<Philips_Hue.BridgeObject.BridgeObjects.BridgeSettings>(comres.Data); // try to deserialize the received message.
if (desc == null) continue; // if the deserialisation didn't work it means this is not a bridge continue with next ip.
if (desc.mac == mac)
{
e.Result = new IPAddress(ipArray);
break;
default:
}

break;
}

if (e.Result != null)
Expand All @@ -121,6 +116,9 @@ private static void _bgw_DoWork(object sender, DoWorkEventArgs e)
}

}

// Restore the timeout to the original value
HueHttpClient.Timeout = WinHueSettings.settings.Timeout;
}

}
Expand Down
41 changes: 0 additions & 41 deletions WinHue3/Functions/BridgeManager/BridgeManager.cs

This file was deleted.

Loading

0 comments on commit 9653c21

Please sign in to comment.