Example #1
0
        public async Task <List <NetatmoCurrentViewModel> > GetCurrentDataAsync()
        {
            try
            {
                var token = await m_Credentials.GetNetatmoOAuthAsync();

                if (string.IsNullOrEmpty(token.AccessToken) || string.IsNullOrEmpty(token.RefreshToken) || string.IsNullOrEmpty(Options.Value?.Netatmo?.DeviceId))
                {
                    Log.Error($"Failed to get current data from Netatmo API with accesstoken: '{token?.AccessToken}' and deviceid: '{Options.Value?.Netatmo?.DeviceId}'");
                    return(null);
                }

                var response = await m_HttpWrapper.GetAsync(
                    UrlBuilder.Netatmo.BuildStationUrl(token.AccessToken, Options.Value.Netatmo.DeviceId));

                var currentData = JsonConvert.DeserializeObject <NetatmoCurrentData>(response);

                return(NetatmoDtoMapper.MapToCurrent(currentData));
            }
            catch (Exception exception)
            {
                Log.Error(exception, $"Failed to get current data from Netatmo: '{exception.Message}'");
                throw;
            }
        }