コード例 #1
0
        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);
        }
コード例 #2
0
 public LightSwitch( IHueDotNetConfigurationReader hueConfiguration, ILightQuery lightQuery)
 {
     HueConfiguration = hueConfiguration;
     LightQuery = lightQuery;
 }
コード例 #3
0
 public LightQuery(IHueDotNetConfigurationReader hueConfiguration)
 {
     HueConfiguration = hueConfiguration;
 }
コード例 #4
0
ファイル: Bridge.cs プロジェクト: ChrisBrooksbank/hue.csharp
 public List<Light> FindNewLightsAsync(IHueDotNetConfigurationReader hueDotNetconfigurationReader)
 {
     throw new NotImplementedException();
 }
コード例 #5
0
 public GroupQuery(IHueDotNetConfigurationReader hueConfiguration)
 {
     HueConfiguration = hueConfiguration;
 }
コード例 #6
0
ファイル: Bridge.cs プロジェクト: ChrisBrooksbank/hue.csharp
        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;
        }
コード例 #7
0
ファイル: Bridge.cs プロジェクト: ChrisBrooksbank/hue.csharp
 public Task<bool> RenameLightAsync(IHueDotNetConfigurationReader hueDotNetconfigurationReader, string oldLightName, string newLightName)
 {
     throw new NotImplementedException();
 }
コード例 #8
0
ファイル: Bridge.cs プロジェクト: ChrisBrooksbank/hue.csharp
        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;
        }
コード例 #9
0
ファイル: Bridge.cs プロジェクト: ChrisBrooksbank/hue.csharp
        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;
        }
コード例 #10
0
ファイル: Bridge.cs プロジェクト: ChrisBrooksbank/hue.csharp
        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;
        }
コード例 #11
0
 public LightColourLoopSwitch(IHueDotNetConfigurationReader hueConfiguration)
 {
     HueConfiguration = hueConfiguration;
 }
コード例 #12
0
 public BridgeCommand(IHueDotNetConfigurationReader hueConfiguration)
 {
     HueConfiguration = hueConfiguration;
 }
コード例 #13
0
 public LightFlashSwitch(IHueDotNetConfigurationReader hueConfiguration)
 {
     HueConfiguration = hueConfiguration;
 }
コード例 #14
0
 public LightColourSwitch(IHueDotNetConfigurationReader hueConfiguration, ILightQuery lightQuery, IColourQuery colourQuery)
 {
     HueConfiguration = hueConfiguration;
     LightQuery = lightQuery;
     ColourQuery = colourQuery;
 }