Skip to content

Commit

Permalink
Implement MET Norway weather provider
Browse files Browse the repository at this point in the history
  • Loading branch information
papjul committed Jan 29, 2023
1 parent 71ab03c commit 09c5d13
Show file tree
Hide file tree
Showing 31 changed files with 1,104 additions and 37 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ There are 3 build variants now. Specifically, the `fdroid` variant dose not cont

AccuWeather is the most complete provider, however you may sometimes find other providers to be more accurate for your location.

| Providers | AccuWeather | OpenWeatherMap | Météo-France |
| --- | --- | --- | --- |
| Status | Maintained | Not maintained anymore (version 3.0 requires credit card information) | Maintained |
| API key | Optional | Required (must be compatible with version 2.5) | Optional |
| Country supported | Worldwide, some features not available everywhere | Worldwide, some features not available everywhere | Mostly France, including DROM-COM. AQI restricted to Auvergne-Rhône-Alpes |
| Current | Weather, Temperature, Precipitation, Wind, UV, Air Quality, Humidity, Pressure, Visibility, Dew point, Cloud Cover, Ceiling | Weather, Temperature, Precipitation, Wind, UV, Air Quality, Humidity, Pressure, Visibility, Dew point, Cloud Cover | Weather, Temperature, Wind, UV, Air Quality |
| Yesterday | Temperature | Not available | May be available in the future |
| Daily | Weather, Temperature, Precipitation (Rain, Snow, Ice), Precipitation Probability (Thunderstorm, Rain, Snow, Ice), Precipitation Duration (Rain, Snow, Ice), Wind, Cloud Clover, Sunrise/Sunset, Moonrise/Moonset, Moon phase, Air Quality, Pollen, UV, Hours of sun | Weather, Temperature, Precipitation (Rain, Snow), Precipitation Probability, Wind, Cloud Clover, Sunrise/Sunset, Air Quality, UV | Weather, Temperature, Precipitation (Rain, Snow), Precipitation Probability (Rain, Snow, Ice), Wind, Cloud Clover, Sunrise/Sunset, Moonrise/Moonset (may be available in the future), Moon phase, Air Quality, UV, Hours of sun |
| Hourly | Weather, Temperature, Precipitation (Rain, Snow, Ice), Precipitation Probability (Thunderstorm, Rain, Snow, Ice), Wind, UV | Weather, Temperature, Precipitation (Rain, Snow), Precipitation Probability, Wind, UV | Weather, Temperature, Precipitation (Rain, Snow), Precipitation Probability (Rain, Snow, Ice), Wind |
| Realtime | Weather, Rain, Cloud Cover | Not available | Rain (intensity estimated, not available everywhere) |
| Alerts | Yes (duplicate alerts issue) | Yes | Yes (incorrect phenomen time to be fixed) |
| Providers | AccuWeather | MET Norway | OpenWeatherMap | Météo-France |
| --- | --- | --- | --- | --- |
| Status | Maintained | Alpha test | Not maintained anymore (version 3.0 requires credit card information) | Maintained |
| API key | Optional | None | Required (must be compatible with version 2.5) | Optional |
| Country supported | Worldwide, some features not available everywhere | Worldwide, some features restricted to Nordic area | Worldwide, some features not available everywhere | Mostly France, including DROM-COM. AQI restricted to Auvergne-Rhône-Alpes |
| Current | Weather, Temperature, Precipitation, Wind, UV, Air Quality, Humidity, Pressure, Visibility, Dew point, Cloud Cover, Ceiling | Weather, Temperature, Precipitation, Precipitation Probability (Thunder, Rain), Wind, UV (may be available in the future), Humidity, Pressure | Weather, Temperature, Precipitation, Wind, UV, Air Quality, Humidity, Pressure, Visibility, Dew point, Cloud Cover | Weather, Temperature, Wind, UV, Air Quality |
| Yesterday | Temperature | Not available | Not available | May be available in the future |
| Daily | Weather, Temperature, Precipitation (Rain, Snow, Ice), Precipitation Probability (Thunderstorm, Rain, Snow, Ice), Precipitation Duration (Rain, Snow, Ice), Wind, Cloud Clover, Sunrise/Sunset, Moonrise/Moonset, Moon phase, Air Quality, Pollen, UV, Hours of sun | Weather, Temperature, Precipitation (Rain), Precipitation Probability (Thunderstorm, Rain), Wind, UV (may be implemented in the future), Hours of sun | Weather, Temperature, Precipitation (Rain, Snow), Precipitation Probability, Wind, Cloud Clover, Sunrise/Sunset, Air Quality, UV | Weather, Temperature, Precipitation (Rain, Snow), Precipitation Probability (Rain, Snow, Ice), Wind, Cloud Clover, Sunrise/Sunset, Moonrise/Moonset (may be available in the future), Moon phase, Air Quality, UV, Hours of sun |
| Hourly | Weather, Temperature, Precipitation (Rain, Snow, Ice), Precipitation Probability (Thunderstorm, Rain, Snow, Ice), Wind, UV | Weather, Temperature, Precipitation, Precipitation Probability (Thunder, Rain), Wind, UV (may be implemented in the future) | Weather, Temperature, Precipitation (Rain, Snow), Precipitation Probability, Wind, UV | Weather, Temperature, Precipitation (Rain, Snow), Precipitation Probability (Rain, Snow, Ice), Wind |
| Realtime | Weather, Rain, Cloud Cover | May be available in the future for Norway, Sweden, Finland and Denmark only | Not available | Rain (intensity estimated, not available everywhere) |
| Alerts | Yes (duplicate alerts issue) | May be available in the future for Norway only | Yes | Yes (incorrect phenomen time to be fixed) |

### Weather icon extensions
If you want to build your own weather icon-pack, please read this document:
Expand Down
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ android {
it.buildConfigField "String", "IQA_ATMO_AURA_KEY", IQA_ATMO_AURA_KEY
it.buildConfigField "String", "IQA_ATMO_AURA_URL", IQA_ATMO_AURA_URL
it.buildConfigField "String", "IQA_ATMO_SUD_URL", IQA_ATMO_SUD_URL
it.buildConfigField "String", "METNO_BASE_URL", METNO_BASE_URL
it.buildConfigField "String", "NOMINATIM_BASE_URL", NOMINATIM_BASE_URL
}
lintOptions {
checkReleaseBuilds false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum class WeatherSource(

ACCU("accu", -0x10a7dd, "accuweather.com"),
OWM("owm", -0x1491b5, "openweathermap.org"),
METNO("metno", -0xdba791, "met.no / nominatim.org"),
MF("mf", -0xffa76e, "meteofrance.com"),
CAIYUN("caiyun", -0xa14472, " caiyunapp.com");

Expand All @@ -23,6 +24,9 @@ enum class WeatherSource(
fun getInstance(
value: String
): WeatherSource {
if (value.lowercase().contains("metno")) {
return METNO
}
if (value.lowercase().contains("owm")) {
return OWM
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Integer getStatusCode() {
}

public Boolean isApiLimitReached() {
return code == 429;
return code != null && code == 429;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import wangdaye.com.geometricweather.common.basic.models.options.provider.WeatherSource;
import wangdaye.com.geometricweather.weather.services.AccuWeatherService;
import wangdaye.com.geometricweather.weather.services.CaiYunWeatherService;
import wangdaye.com.geometricweather.weather.services.MetNoWeatherService;
import wangdaye.com.geometricweather.weather.services.MfWeatherService;
import wangdaye.com.geometricweather.weather.services.OwmWeatherService;
import wangdaye.com.geometricweather.weather.services.WeatherService;
Expand All @@ -19,18 +20,23 @@ public class WeatherServiceSet {
public WeatherServiceSet(AccuWeatherService accuWeatherService,
CaiYunWeatherService caiYunWeatherService,
MfWeatherService mfWeatherService,
OwmWeatherService owmWeatherService) {
OwmWeatherService owmWeatherService,
MetNoWeatherService metNoWeatherService) {
mWeatherServices = new WeatherService[] {
accuWeatherService,
caiYunWeatherService,
mfWeatherService,
owmWeatherService
owmWeatherService,
metNoWeatherService
};
}

@NonNull
public WeatherService get(WeatherSource source) {
switch (source) {
case METNO:
return mWeatherServices[4];

case OWM:
return mWeatherServices[3];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package wangdaye.com.geometricweather.weather.apis;

import java.util.Date;

import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Query;
import wangdaye.com.geometricweather.weather.json.metno.MetNoLocationForecastResult;
import wangdaye.com.geometricweather.weather.json.metno.MetNoSunsetResult;

/**
* MET Weather API.
*/

public interface MetNoApi {

@GET("locationforecast/2.0/compact.json")
Observable<MetNoLocationForecastResult> getLocationForecast(@Header("User-Agent") String userAgent,
@Query("lat") Float lat,
@Query("lon") Float lon);

@GET("sunrise/2.0/.json")
Observable<MetNoSunsetResult> getSunset(@Header("User-Agent") String userAgent,
@Query("date") String date,
@Query("days") int days,
@Query("lat") Float lat,
@Query("lon") Float lon,
@Query("offset") String offset);

// Only available in Nordic area
/*@GET("nowcast/2.0/complete.json")
Observable<MetNoLocationForecastResult> getMinutely(@Header("User-Agent") String userAgent,
@Query("lat") Float lat,
@Query("lon") Float lon);*/

/*@GET("airqualityforecast/0.1/")
Observable<MetNoAqiResult> getAirQuality(@Header("User-Agent") String userAgent,
@Query("lat") Float lat,
@Query("lon") Float lon);*/

/*@GET("metalerts/1.1/")
Observable<List<MetNoAlertResult>> getAlerts(@Header("User-Agent") String userAgent,
@Query("lat") Float lat,
@Query("lon") Float lon);*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package wangdaye.com.geometricweather.weather.apis;

import java.util.List;

import io.reactivex.Observable;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Query;
import wangdaye.com.geometricweather.weather.json.nominatim.NominatimLocationResult;

/**
* Nominatim API.
*/

public interface NominatimApi {

@GET("search")
Call<List<NominatimLocationResult>> callWeatherLocation(@Header("User-Agent") String userAgent,
@Query("q") String q,
@Query("featuretype") String featureType,
@Query("addressdetails") Boolean addressDetails,
@Query("accept-language") String acceptLanguage,
@Query("format") String format);

@GET("search")
Observable<List<NominatimLocationResult>> getWeatherLocation(@Header("User-Agent") String userAgent,
@Query("q") String q,
@Query("featuretype") String featureType,
@Query("addressdetails") Boolean addressDetails,
@Query("accept-language") String acceptLanguage,
@Query("format") String format);

@GET("search")
Observable<NominatimLocationResult> getWeatherLocationByGeoPosition(@Header("User-Agent") String userAgent,
@Query("lat") Float lat,
@Query("lon") Float lon,
@Query("featuretype") String featureType,
@Query("addressdetails") Boolean addressDetails,
@Query("accept-language") String acceptLanguage,
@Query("format") String format);

}
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,13 @@ public static UV getCurrentUV(int dayMaxUV, Date currentDate, Date sunriseDate,

return new UV(Math.toIntExact(Math.round(currentUV)), null, null);
}

public static float getHoursOfDay(Date sunrise, Date sunset) {
return (float) (
(sunset.getTime() - sunrise.getTime()) // get delta millisecond.
/ 1000 // second.
/ 60 // minutes.
/ 60.0 // hours.
);
}
}

0 comments on commit 09c5d13

Please sign in to comment.