From b81124770458116c95a75d3973afaf17a255eabf Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Sat, 31 Dec 2016 19:27:21 +0100 Subject: [PATCH] Pebble: Adapt MarioTime logic --- .../pebble/AppMessageHandlerMarioTime.java | 46 ++++++------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMarioTime.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMarioTime.java index 8ef9d762..be4e9a97 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMarioTime.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerMarioTime.java @@ -12,13 +12,12 @@ import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes; import nodomain.freeyourgadget.gadgetbridge.model.Weather; -import ru.gelin.android.weather.notification.ParcelableWeather2; +import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec; class AppMessageHandlerMarioTime extends AppMessageHandler { private static final int KEY_WEATHER_ICON_ID = 10; private static final int KEY_WEATHER_TEMPERATURE = 11; - private static final int KEY_WEATHER_REQUEST = 12; private static final Logger LOG = LoggerFactory.getLogger(AppMessageHandlerMarioTime.class); @@ -26,10 +25,10 @@ class AppMessageHandlerMarioTime extends AppMessageHandler { super(uuid, pebbleProtocol); } - private byte[] encodeWeatherMessage(int temperature, int condition) { + private byte[] encodeMarioWeatherMessage(WeatherSpec weatherSpec) { ArrayList> pairs = new ArrayList<>(2); - pairs.add(new Pair<>(KEY_WEATHER_ICON_ID, (Object) (byte) condition)); - pairs.add(new Pair<>(KEY_WEATHER_TEMPERATURE, (Object) (byte) temperature)); + pairs.add(new Pair<>(KEY_WEATHER_ICON_ID, (Object) (byte) 1)); + pairs.add(new Pair<>(KEY_WEATHER_TEMPERATURE, (Object) (byte) (weatherSpec.currentTemp - 273))); byte[] weatherMessage = mPebbleProtocol.encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, mUUID, pairs); ByteBuffer buf = ByteBuffer.allocate(weatherMessage.length); @@ -41,37 +40,22 @@ class AppMessageHandlerMarioTime extends AppMessageHandler { @Override public GBDeviceEvent[] handleMessage(ArrayList> pairs) { - boolean weatherRequested = false; - for (Pair pair : pairs) { - switch (pair.first) { - case KEY_WEATHER_REQUEST: - LOG.info("got weather request"); - weatherRequested = true; - break; - default: - LOG.info("unknown key " + pair.first); - } - } - if (!weatherRequested) { - return new GBDeviceEvent[]{null}; - } - return onAppStart(); + // Just ACK + GBDeviceEventSendBytes sendBytesAck = new GBDeviceEventSendBytes(); + sendBytesAck.encodedBytes = mPebbleProtocol.encodeApplicationMessageAck(mUUID, mPebbleProtocol.last_id); + return new GBDeviceEvent[]{sendBytesAck}; } @Override public GBDeviceEvent[] onAppStart() { - ParcelableWeather2 weather = Weather.getInstance().getWeather2(); - - if (weather == null) { - return new GBDeviceEvent[]{null}; - } + WeatherSpec weatherSpec = Weather.getInstance().getWeatherSpec(); GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes(); - sendBytes.encodedBytes = encodeWeatherMessage(weather.currentTemp - 273, 1); // FIXME: condition code - - GBDeviceEventSendBytes sendBytesAck = new GBDeviceEventSendBytes(); - sendBytesAck.encodedBytes = mPebbleProtocol.encodeApplicationMessageAck(mUUID, mPebbleProtocol.last_id); - - return new GBDeviceEvent[]{sendBytesAck, sendBytes}; + sendBytes.encodedBytes = encodeMarioWeatherMessage(weatherSpec); + return new GBDeviceEvent[]{sendBytes}; + } + @Override + public byte[] encodeUpdateWeather(WeatherSpec weatherSpec) { + return encodeMarioWeatherMessage(weatherSpec); } }