Exemple #1
0
        public ModeResponse SetMode(LoginResponse token, string mode)
        {
            ConsoleOutput.WriteLine(string.Format("- Set Mode: {0}", mode), ConsoleColor.Yellow);

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("X-Auth-Token", token.Authentication_token);

            ModeSet setMode    = new ModeSet(mode);
            string  jsonString = JsonSerializer.Serialize(setMode, JsonOptions);

            var task = Task.Run(async() => await this.MakePOSTRequest(this.baseUrl + this.modeUrl, jsonString, headers));

            task.Wait();

            if (task.Result != null && task.Result.WasSuccessful)
            {
                ModeResponse response = JsonSerializer.Deserialize <ModeResponse>(task.Result.JsonResponse, JsonOptions);
                if (response != null)
                {
                    response.Mode = mode;
                    ConsoleOutput.WriteLine(string.Format("  Mode Set: {0}", mode), ConsoleColor.Cyan);
                    return(response);
                }
            }
            else
            {
                ConsoleOutput.WriteLine(string.Format("  Set Mode Failed ({0})", task.Result?.JsonResponse), ConsoleColor.Red);
            }

            return(null);
        }
Exemple #2
0
        public ModeResponse GetMode(LoginResponse token)
        {
            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("X-Auth-Token", token.Authentication_token);

            var task = Task.Run(async() => await this.MakeGETRequest(this.baseUrl + this.modeUrl, headers));

            task.Wait();

            if (task.Result != null && task.Result.WasSuccessful)
            {
                ModeResponse response = JsonSerializer.Deserialize <ModeResponse>(task.Result.JsonResponse, JsonOptions);
                if (response != null)
                {
                    ConsoleOutput.WriteLine(string.Format("  Lights Mode: ({0})", response.Mode), ConsoleColor.Cyan);
                    return(response);
                }
            }
            else
            {
                ConsoleOutput.WriteLine(string.Format("  Get Mode Failed ({0})", task.Result?.JsonResponse), ConsoleColor.Red);
            }

            return(null);
        }
 public void TestModeResponse()
 {
     ModeResponse response = new ModeResponse();
      ResponseTest(response, ResponseType.Mode, 1, "modemode", new List<string> { "modemode" });
      Assert.AreEqual("modemode", response.Mode);
 }