示例#1
0
		public async Task<string> CreateSceneAsync(Scene scene)
		{
			CheckInitialized();

			if (scene == null)
				throw new ArgumentNullException(nameof(scene));
			if (scene.Lights == null)
				throw new ArgumentNullException(nameof(scene.Lights));
			if (scene.Name == null)
				throw new ArgumentNullException(nameof(scene.Name));

			//Filter non updatable properties
			scene.FilterNonUpdatableProperties();

			string jsonString = JsonConvert.SerializeObject(scene, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });

			HttpClient client = HueClient.GetHttpClient();
			var response = await client.PostAsync(new Uri(String.Format("{0}scenes", ApiBase)), new StringContent(jsonString)).ConfigureAwait(false);

			var jsonResult = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

			HueResults sceneResult = DeserializeDefaultHueResult(jsonResult);

			if (sceneResult.Count > 0 && sceneResult[0].Success != null && !string.IsNullOrEmpty(sceneResult[0].Success.Id))
			{
				return sceneResult[0].Success.Id;
			}

			if (sceneResult.HasErrors())
				throw new Exception(sceneResult.Errors.First().Error.Description);

			return null;

		}
示例#2
0
    public async Task Create()
    {
	  Scene test = new Scene();
	  test.Name = "scene1";
	  test.Lights = new List<string> { "2" };

	  var result = await _client.CreateSceneAsync(test);

      Assert.IsNotNull(result);
    }
示例#3
0
		public async Task UpdateScene()
		{
			Scene scene = new Scene()
			{
				 Id = "scene1",
				 Recycle = true,
				  Name = "test"
			};

			var result = await _client.UpdateSceneAsync("scene1", scene);

			Assert.AreNotEqual(0, result.Count);
		}
示例#4
0
		/// <summary>
		/// UpdateSceneAsync
		/// </summary>
		/// <param name="id"></param>
		/// <param name="scene"></param>
		/// <returns></returns>
		public async Task<HueResults> UpdateSceneAsync(string id, Scene scene)
		{
			CheckInitialized();

			if (id == null)
				throw new ArgumentNullException("id");
			if (id.Trim() == String.Empty)
				throw new ArgumentException("id must not be empty", "id");
			if (scene == null)
				throw new ArgumentNullException(nameof(scene));

			//Set these fields to null
			scene.Id = null;
			scene.Recycle = null;
			scene.FilterNonUpdatableProperties();

			string jsonString = JsonConvert.SerializeObject(scene, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });

			HttpClient client = HueClient.GetHttpClient();
			var response = await client.PutAsync(new Uri(String.Format("{0}scenes/{1}", ApiBase, id)), new StringContent(jsonString)).ConfigureAwait(false);

			var jsonResult = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

			return DeserializeDefaultHueResult(jsonResult);

		}