public Command(string request,Communicator iClient)
 {
     CommandString = request;
     GetAvailableActions();
     Value = -1;
     Request = CommandActions.Unknown;
     IdentifyDevice(request,iClient);
     if (DeviceFound)
     {
         string newrequest = request.ToLower().Replace("the", "");
         if (DeviceIsThermostat)
         {
             newrequest = newrequest.Replace(thermostat.name.ToLower(), "");
         }
         else
         {
             newrequest = newrequest.Replace(device.name.ToLower(), "");
         }
         request = newrequest.Trim();
     }
     SetCommand(request);
     Valid = true;
 }
        static void Main(string[] args)
        {
            Console.WindowWidth = Console.WindowWidth + 5;
            do
            {
                Console.Write("Hi, please enter your name: ");
                name = Console.ReadLine();
                Console.Clear();
            } while (String.IsNullOrEmpty(name));
            string url = InControl_Console_Test_application.Properties.Settings.Default.Server;
            string password = InControl_Console_Test_application.Properties.Settings.Default.Password;
            int port = InControl_Console_Test_application.Properties.Settings.Default.Port;
            client = new Communicator(url, password, port);
            foreach (SceneDTO scene in client.GetScenes())
            {
                Console.WriteLine(scene.sceneName);
            }
            Console.WriteLine("Hello " + name + ", welcome, there are " + client.DeviceCount + " devices that I can control");
            DisplayDeviceState();

            Console.Write("\nSo what can I do for you today? ");
            //client.GetScenes();
            string request = Console.ReadLine();

            while (request != "quit")
            {
                if (request.ToLower() == "status")
                {
                    DisplayDeviceState();
                }
                else if (request.ToLower() == "wizard")
                {
                    RunWizard();
                }
                else if (request.ToLower() == "away mode")
                {
                    foreach (HaDevice d in client.Devices)
                    {
                        Animate("Turning off " + d.name);
                        Animate(client.TurnOff(d.deviceId));
                    }
                    foreach (Thermostat t in client.Thermostats)
                    {
                        Animate("Turning down " + t.name);
                        Animate(client.SetEconMode(t.deviceId.ToString()));
                    }
                    Console.WriteLine("Waiting 5 seconds for devices to update");
                    int per = 0;
                    for (int delay = 5; delay > 0; delay--)
                    {
                        per += 20;
                        RenderConsoleProgress(per, '\u2592', ConsoleColor.Green, per + "%");
                        Thread.Sleep(1000);
                    }
                    DisplayDeviceState();
                }
                else
                {
                    var device = GetDevice(request);
                    WriteLine('*');
                    Console.WriteLine(client.GetDeviceState(device));
                    WriteLine('*');
                    Console.WriteLine("Executing the request");
                    Console.WriteLine(Process_Response(request, device));
                    Console.WriteLine("Waiting 5 seconds for devices to update");
                    int per = 0;
                    for (int delay = 5; delay > 0; delay--)
                    {
                        per += 20;
                        RenderConsoleProgress(per, '\u2592', ConsoleColor.Green, per + "%");
                        Thread.Sleep(1000);
                    }
                    Console.WriteLine("\nRefreshing device statuses");
                    client.GetDevices();
                    if (deviceISThermostat)
                    {
                        Thermostat t = (Thermostat)device;
                        device = client.Thermostats.Find(o => (o.deviceId == t.deviceId));
                    }
                    else
                    {
                        HaDevice d = (HaDevice)device;
                        device = client.Devices.Find(o => (o.deviceId == d.deviceId));
                    }
                    WriteLine('*');
                    Console.WriteLine(client.GetDeviceState(device));
                    WriteLine('*');
                }

                Animate("What would you like me to do next? ");
                request = Console.ReadLine();
                Console.Clear();
            }
            int pe2r = 0;
            for (int q = 10; q > 0; q--)
            {
                pe2r += 10;
                RenderConsoleProgress(pe2r, '\u2592', ConsoleColor.Red, " exiting in " + q + " seconds");
                Thread.Sleep(1000);
            }
        }
 private void IdentifyDevice(string request,Communicator client)
 {
     HaDevice d = null;
     Thermostat t = null;
     DeviceFound = true;
     //InControlCommunicator client = new InControlCommunicator();
     foreach (HaDevice dvc in client.Devices)
     {
         if (request.ToLower().Contains(dvc.name.ToLower()))
         {
             DeviceIsThermostat = false;
             device = dvc;
             return;
         }
     }
     foreach (Thermostat tstat in client.Thermostats)
     {
         if (request.ToLower().Contains(tstat.name.ToLower()))
         {
             DeviceIsThermostat = true;
             thermostat = tstat;
             return;
         }
     }
     foreach (string token in request.Split(' '))
     {
         if (!string.IsNullOrEmpty(token) && token.Length > 5)
         {
             d = client.Devices.Find(o => (o.name.ToLower().StartsWith(token.ToLower())));
             if (d != null)
             {
                 DeviceIsThermostat = false;
                 device = d;
                 return;
             }
             t = client.Thermostats.Find(o => (o.name.ToLower().StartsWith(token.ToLower())));
             if (t != null)
             {
                 DeviceIsThermostat = true;
                 thermostat = t;
                 return;
             }
         }
     }
     if (request.ToLower().Contains("all"))
     {
         device = new HaDevice();
         device.deviceName = "All";
         return;
     }
     if (request.ToLower().Contains("both"))
     {
         device = new HaDevice();
         device.deviceName = "both";
         return;
     }
     DeviceFound = false;
 }