예제 #1
0
        static async void Test()
        {
            Console.Write("Enter username: "******"Enter password: ");
            Console.ForegroundColor = ConsoleColor.Black;
            var password = Console.ReadLine();
            Console.ForegroundColor = ConsoleColor.White;

            var nestClient = new NestClient(username, password);
            await nestClient.Authenticate();

            var devices = await nestClient.GetDevices();

            Console.WriteLine(devices);
        }
예제 #2
0
        private DeviceReadings GetReadings(string username, string password)
        {
            var nestClient = new NestClient(username, password);
            nestClient.Authenticate().Wait();

            var devicesTask = nestClient.GetDevices();
            devicesTask.Wait();
            dynamic result = devicesTask.Result;

            var devices = result.device;
            Type devicesType = devices.GetType();
            var devicesFirstProp = devicesType.GetProperties().First(x => x.Name == "First");
            dynamic firstDevice = devicesFirstProp.GetValue(devices).Value;

            var shareds = result.shared;
            Type sharedType = shareds.GetType();
            var sharedFirstProp = sharedType.GetProperties().First(x => x.Name == "First");
            dynamic firstShared = sharedFirstProp.GetValue(shareds).Value;

            double currentHumidity = firstDevice.current_humidity;
            double currentTemp = firstShared.current_temperature;
            double targetTemp = firstShared.target_temperature;

            int autoAway = firstShared.auto_away;
            bool heatState = firstShared.hvac_heater_state == "true";

            Console.WriteLine(heatState);

            var readings = new DeviceReadings()
                         {
                             CurrentHumidity = currentHumidity,
                             CurrentTemp = currentTemp,
                             TargetTemp = targetTemp,
                             AutoAway = autoAway,
                             HeatState = heatState,
                         };

            return readings;
        }