From c884c5d075dd8d2fd1a03426ae1387870a86f84b Mon Sep 17 00:00:00 2001 From: Davis Mosenkovs Date: Thu, 21 Sep 2023 22:48:13 +0300 Subject: [PATCH] Mijia LYWSD02: Set time in onSetTime() --- .../mijia_lywsd02/MijiaLywsd02Support.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/mijia_lywsd02/MijiaLywsd02Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/mijia_lywsd02/MijiaLywsd02Support.java index ce664ca5c..590cd1bd1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/mijia_lywsd02/MijiaLywsd02Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/mijia_lywsd02/MijiaLywsd02Support.java @@ -88,7 +88,11 @@ public class MijiaLywsd02Support extends AbstractBTLEDeviceSupport { protected TransactionBuilder initializeDevice(TransactionBuilder builder) { builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext())); requestDeviceInfo(builder); - setTime(builder); + + if (GBApplication.getPrefs().getBoolean("datetime_synconconnect", true)) { + setTime(builder); + } + getBatteryInfo(builder); setInitialized(builder); return builder; @@ -115,7 +119,6 @@ public class MijiaLywsd02Support extends AbstractBTLEDeviceSupport { private void setTemperatureScale(TransactionBuilder builder, String scale) { BluetoothGattCharacteristic scaleCharacteristc = getCharacteristic(MijiaLywsd02Support.UUID_SCALE); builder.write(scaleCharacteristc, new byte[]{ (byte) ("f".equals(scale) ? 0x01 : 0xff) }); - builder.queue(getQueue()); } private void handleBatteryInfo(byte[] value, int status) { @@ -148,7 +151,15 @@ public class MijiaLywsd02Support extends AbstractBTLEDeviceSupport { @Override public void onSetTime() { - // better only on connect for now + TransactionBuilder builder; + try { + builder = performInitialized("Set time"); + setTime(builder); + builder.queue(getQueue()); + } catch (IOException e) { + LOG.error("Error setting time on LYWSD02", e); + GB.toast("Error setting time on LYWSD02", Toast.LENGTH_LONG, GB.ERROR, e); + } } @Override @@ -188,9 +199,11 @@ public class MijiaLywsd02Support extends AbstractBTLEDeviceSupport { String temperatureScale = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getString(DeviceSettingsPreferenceConst.PREF_TEMPERATURE_SCALE_CF, ""); builder = performInitialized("Sending configuration for option: " + config); setTemperatureScale(builder, temperatureScale); + builder.queue(getQueue()); break; } } catch (IOException e) { + LOG.error("Error setting configuration on LYWSD02", e); GB.toast("Error setting configuration", Toast.LENGTH_LONG, GB.ERROR, e); } }