def __init__(self, hass, latitude, longitude, station_id,
                 weather_interval):
        """Initialize the data object."""
        self._hass = hass
        self.forecast = None
        self.station_id = None
        self.latest_update = None

        # Public attributes
        self.latitude = latitude
        self.longitude = longitude
        self.weather_interval = weather_interval
        self.infos = {}

        # Checks if station_id was set by the user
        if station_id != "":
            if dwdforecast.is_valid_station_id(station_id):
                self.station_id = station_id
            else:
                raise ValueError("Not a valid station_id")
        else:
            self.station_id = dwdforecast.get_nearest_station_id(
                latitude, longitude)
        # Holds the current data from DWD
        self.dwd_weather = dwdforecast.Weather(self.station_id)
 def setUp(self):
     self.dwd_weather = dwdforecast.Weather("H889")
     self.dwd_weather.forecast_data = parsed_data
     self.dwd_weather.station_name = "BAD HOMBURG"
 def test_init_with_no_id(self):
     with self.assertRaises(TypeError) as _:
         dwdforecast.Weather()
 def test_init_with_number(self):
     with self.assertRaises(ValueError) as _:
         dwdforecast.Weather(42)
 def test_init_with_wrong_id(self):
     with self.assertRaises(ValueError) as _:
         dwdforecast.Weather("H89")
示例#6
0
            # Append data set, with actual hour as the API sataset starts with t+1h
            if isinstance(dataPrevious, list):
                energyData = energyData.append(energyData.loc[0], ignore_index=True)
                energyData.loc[energyData.index[-1], 'startTime'] = energyData.loc[0, 'startTime'] - dt.timedelta(
                    hours=1)
                energyData.loc[energyData.index[-1], 'endTime'] = energyData.loc[0, 'endTime'] - dt.timedelta(hours=1)
            else:
                energyData = energyData.append(
                    dataPrevious.loc[energyData['startTime'] == dt.datetime(now.year, now.month, now.day, now.hour)],
                    ignore_index=True)
            energyData = energyData.sort_values(by='startTime').reset_index(drop=True)
            
        # get weather data and calculate energy from wind and solar from dwd
        div = np.divide(now.hour, 6)  # new forecasts are issued every 6 hours
        if div.is_integer() or initial:
            dwd_weather = dwdforecast.Weather("10147")  # Flughafen Hamburg
            dwd_weather.update()
            weatherData = pd.DataFrame(dwd_weather.forecast_data).T.reset_index()
            weatherData = weatherData.rename(columns={'index': 'original_time'})

            for hour in range(0, len(weatherData)):
                weatherData.loc[hour, 'start_time'] = dt.datetime.strptime(weatherData.loc[hour, 'original_time'][:13],
                                                                           '%Y-%m-%dT%H') + dt.timedelta(
                    hours=utcoffset)
                weatherData.loc[hour, 'end_time'] = dt.datetime.strptime(weatherData.loc[hour, 'original_time'][:13],
                                                                         '%Y-%m-%dT%H') + dt.timedelta(
                    hours=utcoffset + 1)
                weatherData.loc[hour, 'sun_cov'] = weatherData.loc[hour, 'sun_dur'] / 60 * 100
                weatherData.loc[hour, 'wind_speed'] = float(weatherData.loc[hour, 'wind_speed'])
                weatherData.loc[hour, 'wind_speed_Kmh'] = weatherData.loc[hour, 'wind_speed'] * 3.6
                weatherData.loc[hour, 'cloud_cov'] = float(weatherData.loc[hour, 'cloud_cov'])
示例#7
0
 def setUp(self):
     self.dwd_weather = dwdforecast.Weather("H889")
示例#8
0
from simple_dwd_weatherforecast import dwdforecast

in_file = open("TEST_N4333.kml", "rb")
data = in_file.read()
in_file.close()

dwd_weather = dwdforecast.Weather("N4333")
dwd_weather.parse_kml(data)
f = open('test_data.py', 'w')
f.write('parsed_data = ' + repr(dwd_weather.forecast_data))
f.close()
 def setUp(self):
     self.dwd_weather = dwdforecast.Weather("N4333")