public BridgeTests() { hueDotNetconfigurationReader = new Implementation.HueDotNetConfigurationReader(); bridgeQuery = new Implementation.BridgeQuery(); bridgeCommand = new Implementation.BridgeCommand(hueDotNetconfigurationReader); lightQuery = new Implementation.LightQuery(hueDotNetconfigurationReader); lightSwitch = new Implementation.LightSwitch(hueDotNetconfigurationReader, lightQuery); colourQuery = new Implementation.ColourQuery(); lightColourSwitch = new Implementation.LightColourSwitch(hueDotNetconfigurationReader, lightQuery, colourQuery); lightDimmerSwitch = new Implementation.LightDimmerSwitch(hueDotNetconfigurationReader, lightQuery); lightFlashSwitch = new Implementation.LightFlashSwitch(hueDotNetconfigurationReader); lightColourLoopSwitch = new Implementation.LightColourLoopSwitch(hueDotNetconfigurationReader); groupQuery = new Implementation.GroupQuery(hueDotNetconfigurationReader); }
public LightSwitch( IHueDotNetConfigurationReader hueConfiguration, ILightQuery lightQuery) { HueConfiguration = hueConfiguration; LightQuery = lightQuery; }
public LightQuery(IHueDotNetConfigurationReader hueConfiguration) { HueConfiguration = hueConfiguration; }
public List<Light> FindNewLightsAsync(IHueDotNetConfigurationReader hueDotNetconfigurationReader) { throw new NotImplementedException(); }
public GroupQuery(IHueDotNetConfigurationReader hueConfiguration) { HueConfiguration = hueConfiguration; }
public async Task<bool> TurnAllOffAsync(IHueDotNetConfigurationReader hueDotNetconfigurationReader) { using (var client = new HttpClient()) { Uri RequestUri = new Uri("http://" + hueDotNetconfigurationReader.BridgeAddress + "/api/" + hueDotNetconfigurationReader.UserName + "/groups/0/action"); StringContent requestContent = new StringContent("{\"on\" : false}"); HttpRequestMessage request = new HttpRequestMessage { Method = HttpMethod.Put, RequestUri = RequestUri, Content = requestContent }; HttpResponseMessage response = await client.SendAsync(request); } return true; }
public Task<bool> RenameLightAsync(IHueDotNetConfigurationReader hueDotNetconfigurationReader, string oldLightName, string newLightName) { throw new NotImplementedException(); }
public async Task<Dictionary<string, Light>> GetLightsAsync(IHueDotNetConfigurationReader hueDotNetconfigurationReader) { Dictionary<string, Light> lights = new Dictionary<string, Light>(); using (var client = new HttpClient()) { client.BaseAddress = new System.Uri("http://" + hueDotNetconfigurationReader.BridgeAddress); HttpResponseMessage response = await client.GetAsync("/api/" + hueDotNetconfigurationReader.UserName + "/lights"); if (response.IsSuccessStatusCode) { string responseString = await response.Content.ReadAsStringAsync(); lights = JsonConvert.DeserializeObject<Dictionary<string, Light>>(responseString); // assign id property to each light foreach (var keyvalue in lights) { ((Light)(keyvalue.Value)).ID = keyvalue.Key; } } } return lights; }
public async Task<bool> TurnOffAsync(IHueDotNetConfigurationReader hueDotNetconfigurationReader, string lightName) { bool isOff = false; Light light = await this.GetLightAsync(hueDotNetconfigurationReader, lightName); if (light != null) { if (!light.State.On) { return true; } using (var client = new HttpClient()) { Uri RequestUri = new Uri("http://" + hueDotNetconfigurationReader.BridgeAddress + "/api/" + hueDotNetconfigurationReader.UserName + "/lights/" + light.ID + "/state"); StringContent requestContent = new StringContent("{\"on\" : false}"); HttpRequestMessage request = new HttpRequestMessage { Method = HttpMethod.Put, RequestUri = RequestUri, Content = requestContent }; HttpResponseMessage response = await client.SendAsync(request); if (response.IsSuccessStatusCode) { light = await this.GetLightAsync(hueDotNetconfigurationReader, lightName); if (light != null) { isOff = !light.State.On; } } } } return isOff; }
public async Task<Light> GetLightAsync(IHueDotNetConfigurationReader hueDotNetconfigurationReader, string lightName) { Light light = new Light(); Dictionary<string, Light> lights = await this.GetLightsAsync(hueDotNetconfigurationReader); foreach (Light candidateLight in lights.Values) { if (candidateLight.Name.Equals(lightName, StringComparison.CurrentCultureIgnoreCase)) { light = candidateLight; break; } } return light; }
public LightColourLoopSwitch(IHueDotNetConfigurationReader hueConfiguration) { HueConfiguration = hueConfiguration; }
public BridgeCommand(IHueDotNetConfigurationReader hueConfiguration) { HueConfiguration = hueConfiguration; }
public LightFlashSwitch(IHueDotNetConfigurationReader hueConfiguration) { HueConfiguration = hueConfiguration; }
public LightColourSwitch(IHueDotNetConfigurationReader hueConfiguration, ILightQuery lightQuery, IColourQuery colourQuery) { HueConfiguration = hueConfiguration; LightQuery = lightQuery; ColourQuery = colourQuery; }