package com.mirkoebert.weather;

import com.mirkoebert.weather.openweather.OpenWeatherService;
import com.mirkoebert.weather.openweather.OpenWeatherWeather;
import com.mirkoebert.weather.tinkerforge.TinkerforgeWeather;
import com.mirkoebert.weather.tinkerforge.TinkerforgeWeatherMonitor;
import com.mirkoebert.weather.tinkerforge.TinkerforgeWeatherService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WeatherService {
    
    @Autowired
    private OpenWeatherService ows;
    @Autowired
    private TinkerforgeWeatherService tfs;
    @Autowired
    private TinkerforgeWeatherMonitor tfwm;
    
    public Weather getWeather(){
        Weather w = new Weather();
        
        OpenWeatherWeather oww = ows.getWeather();
        w.setName(oww.getName());
        w.setDescription(oww.getDescription());
        w.setAirpressure(oww.getPressure());
        w.setTempOut(oww.getTemp());
        w.setFeelsTemp(oww.getFeelsTemp());
        w.setHumidityOut(oww.getHumidity());
        
        TinkerforgeWeather w2 = tfs.getWeather2();
        final double pressure = w2.getAirPressureQFE();
        if (pressure > 0) {
            w.setAirpressure((float)pressure );
        }
        w.setHumidityIn((float) (w2.getHumdidity()));
        w.setTempIn((float) w2.getTempIn());
        
        w.setForecast(tfwm.getForeCast());
        return w;
    }

}

@@ -501,21 +501,17 @@
 rvice %7B%0A
-    
 %0A
+
     @Aut
@@ -670,21 +670,17 @@
 r tfwm;%0A
-    
 %0A
+
     publ
@@ -739,25 +739,17 @@
 ther();%0A
-        
 %0A
+
         
@@ -787,24 +787,54 @@
 tWeather();%0A
+        if(oww != null) %7B%0A    
         w.se
@@ -859,24 +859,28 @@
 ));%0A        
+   
+ 
 w.setDescrip
@@ -907,32 +907,36 @@
 ion());%0A        
+    
 w.setAirpressure
@@ -956,32 +956,36 @@
 ure());%0A        
+ 
+   
 w.setTempOut(oww
@@ -989,32 +989,36 @@
 oww.getTemp());%0A
+    
         w.setFee
@@ -1045,32 +1045,36 @@
 emp());%0A        
+    
 w.setHumidityOut
@@ -1094,32 +1094,34 @@
 ity());%0A        
+%7D%0A
 %0A        Tinkerf
@@ -1397,24 +1397,16 @@
 pIn());%0A
-        
 %0A       

fix npe