Beispiel #1
0
        public async Task <NetatmoData> Get()
        {
            try
            {
                var auth  = new NetatmoAuth();
                var token = auth.Login(
                    _settings.Value.NETATMO_CLIENT_ID,
                    _settings.Value.NETATMO_CLIENT_SECRET,
                    _settings.Value.NETATMO_USER_NAME,
                    _settings.Value.NETATMO_PASSWORD,
                    new[] { NetatmoAuth.READ_STATION });
                var netatmo = new NetAtmoClient(token.access_token);

                var result = await netatmo.Getthermostatsdata(_settings.Value.NETATMO_DEVICE_ID);

                var indoorData  = result.Body.Devices[0].DashboardData;
                var outdoorData = result.Body.Devices[0].Modules[0].DashboardData;
                var windData    = result.Body.Devices[0].Modules[1].DashboardData;
                var rainData    = result.Body.Devices[0].Modules[2].DashboardData;
                var bedroomData = result.Body.Devices[0].Modules[3].DashboardData;
                var netatmoData = new NetatmoData
                {
                    IndoorTemp      = indoorData?.Temperature,
                    OutdoorTemp     = outdoorData?.Temperature,
                    BedroomTemp     = bedroomData?.Temperature,
                    AbsPressure     = indoorData?.AbsolutePressure,
                    Pressure        = indoorData?.Pressure,
                    CO2             = indoorData?.CO2,
                    BedroomCO2      = bedroomData?.CO2,
                    IndoorHumidity  = indoorData?.Humidity,
                    OutdoorHumidity = outdoorData?.Humidity,
                    BedroomHumidity = bedroomData?.Humidity,
                    Noise           = indoorData?.Noise,
                    Rain            = rainData?.Rain,
                    Rain24          = rainData?.SumRain24,
                    Rain1           = rainData?.SumRain1,
                    WindAngle       = windData?.WindAngle,
                    WindStrength    = windData?.WindStrength,
                    WindGusts       = windData?.GustStrength
                };

                return(netatmoData);
            }
            catch (Exception ex)
            {
                _logService.WriteLog(ex.ToString());
            }

            return(null);
        }
        public void Authorization_Success_With_Correct_User()
        {
            // Fill these with own values for testing purpose
            var clientId     = "5fe6e052c08fbf05e129397c";
            var clientSecret = "mrnFSCPRLi8GuJ0OkAvGOe5TTFt";
            var username     = "******";
            var password     = "******";
            var device_id    = "70:ee:50:3d:02:0a";

            var auth  = new NetatmoAuth();
            var token = auth.Login(clientId, clientSecret, username, password, new[] { NetatmoAuth.READ_STATION });

            var netatmo = new NetAtmoClient(token.access_token);

            var result = netatmo.Getthermostatsdata(device_id).Result;
        }