lunar-launcher icon indicating copy to clipboard operation
lunar-launcher copied to clipboard

Open-Meteo weather provider

Open DadiBit opened this issue 2 years ago • 8 comments

Checklist

  • [X] I made sure that there are no existing issues - open or closed - which I could contribute my information to.
  • [X] I have already checked the WIKI pages and made sure that the feature isn't already exist.
  • [X] I have taken the time to fill in all the required details. I understand that the feature request will be dismissed otherwise.
  • [X] This issue contains only one feature request.

Feature description

Hello, I would like to help implement the Open-Meteo API in the launcher, as it requires no API key (hence it's more user-friendly). I'm currently the only contributor to the open-meteo-api-kotlin library, and I haven't finished it, but I feel like to could benefit this project. Some "pseudo-code":

  • Create an Endpoint with GeocodingSearch.context
  • Use the geocoding search endpoint to find one matching place
  • Get the first (and only) result coordinates (should be saved in the settings -> add ability to use coordinates only*)
  • Create an Endpoint with Forecast.context
  • Call the endpoint with Forecast.Query(latitude, longitude, currentWeather = true, /* units */)
  • Get the response current weather:
    • response.currentWeather?.temperature for the temperature
    • response.currentWeather?.weatherCode?.message for the printable message
    • response.currentWeather?.weatherCode?.code for the wmo int code (see at the end of the docs)

If you need the weather forecast, I would recommend to instead:

  • Query using the invoke operator: openMeteo(...)
    • ForecastHourly.Temperature2m
    • ForecastHourly.Weathercode (convertible with WeatherCode.from(it))
      • Get a printable name (message)
      • Get a Short code to map icons (code)
    • ForecastDaily.Sunrise and ForecastDaily.Sunset (convertible with Time(it))
      • To know if it's day or night (please note that I'm still working on TimeZone usage)
  • Cache all the information needed and update every N hours

*Note: if GPS auto-location were to be implemented, it would be easy to update the coordinates (next version will have var coordinates)

Additional information

A nice feature of the API is that it provides hourly/daily values up to a week, easing data caching. I'd like also to receive some inputs on how I could make the library more accessible to other developers (I know that the documentation and tests are completely missing in version 0.2.0-alpha, please have mercy), in order to ease the transaction to it.

DadiBit avatar Sep 21 '22 12:09 DadiBit

What to input as location? Longitude-latitude or city name?

iamrasel avatar Sep 22 '22 06:09 iamrasel

What to input as location? Longitude-latitude or city name?

Currently the client constructor accepts:

  • City names as strings (defaulting to 0,0 coordinates)
  • Coordinates pair (coordinates: Pair<Float, Float>)
  • latitude and longitude (both floats)

DadiBit avatar Sep 22 '22 09:09 DadiBit

Okay, i'll try it. Thanks for the suggestion.

iamrasel avatar Sep 23 '22 13:09 iamrasel

I did some testing and I realized the library is just overkill for the launcher (1+ MB = too heavy): I'll work on a fork without implementing the library, but instead implementing the useful parts (protobuf isn't needed, as only one city name is retrieved).

DadiBit avatar Sep 25 '22 06:09 DadiBit

You can open a pull request for a successful implementation, thanks.

iamrasel avatar Sep 28 '22 09:09 iamrasel

if the app can some how get the Longitude-latitude via location and still be able to be on fdroid aka no play services that would be good then the weather could also auto update location

CreativeCodeCat avatar Jan 05 '23 12:01 CreativeCodeCat

@The-Repo-Club I think, inputting location data manually is more privacy friendly.

iamrasel avatar Jan 05 '23 12:01 iamrasel

ya having the option if wanting to would be nice though doesn't need to be on by default :)

CreativeCodeCat avatar Jan 05 '23 12:01 CreativeCodeCat