mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-25 19:36:50 +01:00
Mijia LYWSD02: Set time in onSetTime()
This commit is contained in:
parent
edce45dcc3
commit
c884c5d075
@ -88,7 +88,11 @@ public class MijiaLywsd02Support extends AbstractBTLEDeviceSupport {
|
|||||||
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
|
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
|
||||||
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext()));
|
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext()));
|
||||||
requestDeviceInfo(builder);
|
requestDeviceInfo(builder);
|
||||||
setTime(builder);
|
|
||||||
|
if (GBApplication.getPrefs().getBoolean("datetime_synconconnect", true)) {
|
||||||
|
setTime(builder);
|
||||||
|
}
|
||||||
|
|
||||||
getBatteryInfo(builder);
|
getBatteryInfo(builder);
|
||||||
setInitialized(builder);
|
setInitialized(builder);
|
||||||
return builder;
|
return builder;
|
||||||
@ -115,7 +119,6 @@ public class MijiaLywsd02Support extends AbstractBTLEDeviceSupport {
|
|||||||
private void setTemperatureScale(TransactionBuilder builder, String scale) {
|
private void setTemperatureScale(TransactionBuilder builder, String scale) {
|
||||||
BluetoothGattCharacteristic scaleCharacteristc = getCharacteristic(MijiaLywsd02Support.UUID_SCALE);
|
BluetoothGattCharacteristic scaleCharacteristc = getCharacteristic(MijiaLywsd02Support.UUID_SCALE);
|
||||||
builder.write(scaleCharacteristc, new byte[]{ (byte) ("f".equals(scale) ? 0x01 : 0xff) });
|
builder.write(scaleCharacteristc, new byte[]{ (byte) ("f".equals(scale) ? 0x01 : 0xff) });
|
||||||
builder.queue(getQueue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleBatteryInfo(byte[] value, int status) {
|
private void handleBatteryInfo(byte[] value, int status) {
|
||||||
@ -148,7 +151,15 @@ public class MijiaLywsd02Support extends AbstractBTLEDeviceSupport {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSetTime() {
|
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
|
@Override
|
||||||
@ -188,9 +199,11 @@ public class MijiaLywsd02Support extends AbstractBTLEDeviceSupport {
|
|||||||
String temperatureScale = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getString(DeviceSettingsPreferenceConst.PREF_TEMPERATURE_SCALE_CF, "");
|
String temperatureScale = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getString(DeviceSettingsPreferenceConst.PREF_TEMPERATURE_SCALE_CF, "");
|
||||||
builder = performInitialized("Sending configuration for option: " + config);
|
builder = performInitialized("Sending configuration for option: " + config);
|
||||||
setTemperatureScale(builder, temperatureScale);
|
setTemperatureScale(builder, temperatureScale);
|
||||||
|
builder.queue(getQueue());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
LOG.error("Error setting configuration on LYWSD02", e);
|
||||||
GB.toast("Error setting configuration", Toast.LENGTH_LONG, GB.ERROR, e);
|
GB.toast("Error setting configuration", Toast.LENGTH_LONG, GB.ERROR, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user