1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-17 19:04:03 +02:00

Add function to sync weather data to the watch, translate weather codes to icons.

This commit is contained in:
Sebastian Kranz 2018-07-04 07:09:50 +02:00
parent 497372f377
commit 6882127bec
3 changed files with 142 additions and 1 deletions

View File

@ -56,6 +56,7 @@ public class ZeTimeConstants {
public static final byte CMD_CALORIES_TYPE = (byte) 0x60;
public static final byte CMD_GET_HEARTRATE_EXDATA = (byte) 0x61;
public static final byte CMD_PUSH_EX_MSG = (byte) 0x76;
public static final byte CMD_PUSH_WEATHER_DATA = (byte) 0x77;
// here are the action commands
public static final byte CMD_REQUEST = (byte) 0x70;
public static final byte CMD_SEND = (byte) 0x71;

View File

@ -599,4 +599,114 @@ public class Weather {
return "";
}
}
public static byte mapToZeTimeCondition(int openWeatherMapCondition) {
/* deducted values:
0 = partly cloudy
1 = cloudy
2 = sunny
3 = windy/gale
4 = heavy rain
5 = snowy
6 = storm
*/
switch (openWeatherMapCondition) {
//Group 2xx: Thunderstorm
case 200: //thunderstorm with light rain: //11d
case 201: //thunderstorm with rain: //11d
case 202: //thunderstorm with heavy rain: //11d
case 210: //light thunderstorm:: //11d
case 211: //thunderstorm: //11d
case 230: //thunderstorm with light drizzle: //11d
case 231: //thunderstorm with drizzle: //11d
case 232: //thunderstorm with heavy drizzle: //11d
case 212: //heavy thunderstorm: //11d
case 221: //ragged thunderstorm: //11d
//Group 7xx: Atmosphere
case 771: //squalls: //[[file:50d.png]]
case 781: //tornado: //[[file:50d.png]]
//Group 90x: Extreme
case 900: //tornado
case 901: //tropical storm
//Group 9xx: Additional
case 960: //storm
case 961: //violent storm
case 902: //hurricane
case 962: //hurricane
return 6;
//Group 3xx: Drizzle
case 300: //light intensity drizzle: //09d
case 301: //drizzle: //09d
case 302: //heavy intensity drizzle: //09d
case 310: //light intensity drizzle rain: //09d
case 311: //drizzle rain: //09d
case 312: //heavy intensity drizzle rain: //09d
case 313: //shower rain and drizzle: //09d
case 314: //heavy shower rain and drizzle: //09d
case 321: //shower drizzle: //09d
//Group 5xx: Rain
case 500: //light rain: //10d
case 501: //moderate rain: //10d
case 502: //heavy intensity rain: //10d
case 503: //very heavy rain: //10d
case 504: //extreme rain: //10d
case 511: //freezing rain: //13d
case 520: //light intensity shower rain: //09d
case 521: //shower rain: //09d
case 522: //heavy intensity shower rain: //09d
case 531: //ragged shower rain: //09d
//Group 90x: Extreme
case 906: //hail
return 4;
//Group 6xx: Snow
case 600: //light snow: //[[file:13d.png]]
case 601: //snow: //[[file:13d.png]]
case 620: //light shower snow: //[[file:13d.png]]
case 602: //heavy snow: //[[file:13d.png]]
case 611: //sleet: //[[file:13d.png]]
case 612: //shower sleet: //[[file:13d.png]]
case 621: //shower snow: //[[file:13d.png]]
case 622: //heavy shower snow: //[[file:13d.png]]
case 615: //light rain and snow: //[[file:13d.png]]
case 616: //rain and snow: //[[file:13d.png]]
//Group 90x: Extreme
case 903: //cold
return 5;
//Group 7xx: Atmosphere
case 701: //mist: //[[file:50d.png]]
case 711: //smoke: //[[file:50d.png]]
case 721: //haze: //[[file:50d.png]]
case 731: //sandcase dust whirls: //[[file:50d.png]]
case 741: //fog: //[[file:50d.png]]
case 751: //sand: //[[file:50d.png]]
case 761: //dust: //[[file:50d.png]]
case 762: //volcanic ash: //[[file:50d.png]]
return 1;
//Group 800: Clear
case 800: //clear sky: //[[file:01d.png]] [[file:01n.png]]
//Group 90x: Extreme
case 904: //hot
return 2;
//Group 80x: Clouds
case 801: //few clouds: //[[file:02d.png]] [[file:02n.png]]
case 802: //scattered clouds: //[[file:03d.png]] [[file:03d.png]]
case 803: //broken clouds: //[[file:04d.png]] [[file:03d.png]]
case 804: //overcast clouds: //[[file:04d.png]] [[file:04d.png]]
default:
return 0;
//Group 9xx: Additional
case 905: //windy
case 951: //calm
case 952: //light breeze
case 953: //gentle breeze
case 954: //moderate breeze
case 955: //fresh breeze
case 956: //strong breeze
case 957: //high windcase near gale
case 958: //gale
case 959: //severe gale
return 3;
}
}
}

View File

@ -35,6 +35,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService;
@ -310,7 +311,36 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
@Override
public void onSendWeather(WeatherSpec weatherSpec) {
byte[] weather = new byte[weatherSpec.location.length() + 26]; // 26 bytes for weatherdata and overhead
weather[0] = ZeTimeConstants.CMD_PREAMBLE;
weather[1] = ZeTimeConstants.CMD_PUSH_WEATHER_DATA;
weather[2] = ZeTimeConstants.CMD_SEND;
weather[3] = (byte)((weatherSpec.location.length() + 20) & 0xff);
weather[4] = (byte)((weatherSpec.location.length() + 20) >> 8);
weather[5] = 0; // celsius
weather[6] = (byte)(weatherSpec.currentTemp - 273);
weather[7] = (byte)(weatherSpec.todayMinTemp - 273);
weather[8] = (byte)(weatherSpec.todayMaxTemp - 273);
weather[9] = Weather.mapToZeTimeCondition(weatherSpec.currentConditionCode);
for(int forecast = 0; forecast < 3; forecast++) {
weather[10+(forecast*5)] = 0; // celsius
weather[11+(forecast*5)] = (byte) 0xff;
weather[12+(forecast*5)] = (byte) (weatherSpec.forecasts.get(forecast).minTemp - 273);
weather[13+(forecast*5)] = (byte) (weatherSpec.forecasts.get(forecast).maxTemp - 273);
weather[14+(forecast*5)] = Weather.mapToZeTimeCondition(weatherSpec.forecasts.get(forecast).conditionCode);
}
System.arraycopy(weatherSpec.location.getBytes(StandardCharsets.UTF_8), 0, weather, 25, weatherSpec.location.length());
weather[weather.length-1] = ZeTimeConstants.CMD_END;
if(weather != null)
{
try {
TransactionBuilder builder = performInitialized("sendWeahter");
sendMsgToWatch(builder, weather);
performConnected(builder.getTransaction());
} catch (IOException e) {
GB.toast(getContext(), "Error sending weather: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
}
}
}
@Override