mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 21:06:50 +01:00
Xiaomi: Remove usage of TransactionBuilders
This commit is contained in:
parent
e2d7798e36
commit
1acd3ac5fd
@ -103,7 +103,7 @@ public class XiaomiAuthService extends AbstractXiaomiService {
|
||||
.setAuth(auth)
|
||||
.build();
|
||||
|
||||
getSupport().sendCommand(builder, command);
|
||||
getSupport().sendCommand("start clear text handshake", command);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -140,7 +140,7 @@ public class XiaomiAuthService extends AbstractXiaomiService {
|
||||
|
||||
final TransactionBuilder builder = getSupport().createTransactionBuilder("phase 2 initialize");
|
||||
builder.add(new SetDeviceStateAction(getSupport().getDevice(), GBDevice.State.INITIALIZED, getSupport().getContext()));
|
||||
getSupport().phase2Initialize(builder);
|
||||
getSupport().phase2Initialize();
|
||||
builder.queue(getSupport().getQueue());
|
||||
} else {
|
||||
LOG.warn("could not authenticate");
|
||||
|
@ -103,7 +103,7 @@ public abstract class XiaomiSupport extends AbstractBTLEDeviceSupport {
|
||||
protected abstract UUID getCharacteristicCommandWrite();
|
||||
protected abstract UUID getCharacteristicActivityData();
|
||||
protected abstract UUID getCharacteristicDataUpload();
|
||||
protected abstract void startAuthentication(TransactionBuilder builder);
|
||||
protected abstract void startAuthentication(final TransactionBuilder builder);
|
||||
|
||||
@Override
|
||||
protected final TransactionBuilder initializeDevice(final TransactionBuilder builder) {
|
||||
@ -234,30 +234,17 @@ public abstract class XiaomiSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
@Override
|
||||
public void onSetTime() {
|
||||
final TransactionBuilder builder;
|
||||
try {
|
||||
builder = performInitialized("set time");
|
||||
} catch (final IOException e) {
|
||||
LOG.error("Failed to initialize transaction builder", e);
|
||||
return;
|
||||
}
|
||||
systemService.setCurrentTime(builder);
|
||||
systemService.setCurrentTime();
|
||||
|
||||
final XiaomiCoordinator coordinator = getCoordinator();
|
||||
|
||||
if (coordinator.supportsCalendarEvents()) {
|
||||
if (getCoordinator().supportsCalendarEvents()) {
|
||||
// TODO this should not be done here
|
||||
calendarService.syncCalendar(builder);
|
||||
calendarService.syncCalendar();
|
||||
}
|
||||
|
||||
builder.queue(getQueue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTestNewFunction() {
|
||||
final TransactionBuilder builder = createTransactionBuilder("test new function");
|
||||
sendCommand(builder, 2, 29);
|
||||
builder.queue(getQueue());
|
||||
sendCommand("test new function", 2, 29);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -404,7 +391,7 @@ public abstract class XiaomiSupport extends AbstractBTLEDeviceSupport {
|
||||
return (XiaomiCoordinator) gbDevice.getDeviceCoordinator();
|
||||
}
|
||||
|
||||
protected void phase2Initialize(final TransactionBuilder builder) {
|
||||
protected void phase2Initialize() {
|
||||
LOG.info("phase2Initialize");
|
||||
|
||||
characteristicCommandRead.reset();
|
||||
@ -413,21 +400,15 @@ public abstract class XiaomiSupport extends AbstractBTLEDeviceSupport {
|
||||
characteristicDataUpload.reset();
|
||||
|
||||
if (GBApplication.getPrefs().getBoolean("datetime_synconconnect", true)) {
|
||||
systemService.setCurrentTime(builder);
|
||||
systemService.setCurrentTime();
|
||||
}
|
||||
|
||||
for (final AbstractXiaomiService service : mServiceMap.values()) {
|
||||
service.initialize(builder);
|
||||
service.initialize();
|
||||
}
|
||||
}
|
||||
|
||||
public void sendCommand(final String taskName, final XiaomiProto.Command command) {
|
||||
final TransactionBuilder builder = createTransactionBuilder(taskName);
|
||||
sendCommand(builder, command);
|
||||
builder.queue(getQueue());
|
||||
}
|
||||
|
||||
public void sendCommand(final TransactionBuilder builder, final XiaomiProto.Command command) {
|
||||
if (this.characteristicCommandWrite == null) {
|
||||
// Can sometimes happen in race conditions when connecting + receiving calendar event or weather updates
|
||||
LOG.warn("characteristicCommandWrite is null!");
|
||||
@ -440,27 +421,6 @@ public abstract class XiaomiSupport extends AbstractBTLEDeviceSupport {
|
||||
this.characteristicCommandWrite.write(commandBytes);
|
||||
}
|
||||
|
||||
public void sendCommand(final TransactionBuilder builder, final byte[] commandBytes) {
|
||||
if (this.characteristicCommandWrite == null) {
|
||||
// Can sometimes happen in race conditions when connecting + receiving calendar event or weather updates
|
||||
LOG.warn("characteristicCommandWrite is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME builder is ignored
|
||||
this.characteristicCommandWrite.write(commandBytes);
|
||||
}
|
||||
|
||||
public void sendCommand(final TransactionBuilder builder, final int type, final int subtype) {
|
||||
sendCommand(
|
||||
builder,
|
||||
XiaomiProto.Command.newBuilder()
|
||||
.setType(type)
|
||||
.setSubtype(subtype)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public void sendCommand(final String taskName, final int type, final int subtype) {
|
||||
sendCommand(
|
||||
taskName,
|
||||
|
@ -38,7 +38,7 @@ public abstract class AbstractXiaomiService {
|
||||
|
||||
public abstract void handleCommand(final XiaomiProto.Command cmd);
|
||||
|
||||
public void initialize(final TransactionBuilder builder) {
|
||||
public void initialize() {
|
||||
|
||||
}
|
||||
|
||||
|
@ -57,8 +57,8 @@ public class XiaomiCalendarService extends AbstractXiaomiService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(final TransactionBuilder builder) {
|
||||
syncCalendar(builder);
|
||||
public void initialize() {
|
||||
syncCalendar();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -83,12 +83,6 @@ public class XiaomiCalendarService extends AbstractXiaomiService {
|
||||
}
|
||||
|
||||
public void syncCalendar() {
|
||||
final TransactionBuilder builder = getSupport().createTransactionBuilder("sync calendar");
|
||||
syncCalendar(builder);
|
||||
builder.queue(getSupport().getQueue());
|
||||
}
|
||||
|
||||
public void syncCalendar(final TransactionBuilder builder) {
|
||||
final boolean syncEnabled = GBApplication.getDeviceSpecificSharedPrefs(getSupport().getDevice().getAddress())
|
||||
.getBoolean(PREF_SYNC_CALENDAR, false);
|
||||
|
||||
@ -138,7 +132,7 @@ public class XiaomiCalendarService extends AbstractXiaomiService {
|
||||
LOG.debug("Syncing {} calendar events", lastSync.size());
|
||||
|
||||
getSupport().sendCommand(
|
||||
builder,
|
||||
"sync calendar",
|
||||
XiaomiProto.Command.newBuilder()
|
||||
.setType(COMMAND_TYPE)
|
||||
.setSubtype(CMD_CALENDAR_SET)
|
||||
|
@ -146,18 +146,16 @@ public class XiaomiHealthService extends AbstractXiaomiService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(final TransactionBuilder builder) {
|
||||
setUserInfo(builder);
|
||||
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_CONFIG_SPO2_GET);
|
||||
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_CONFIG_HEART_RATE_GET);
|
||||
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_CONFIG_STANDING_REMINDER_GET);
|
||||
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_CONFIG_STRESS_GET);
|
||||
public void initialize() {
|
||||
setUserInfo();
|
||||
getSupport().sendCommand("get spo2 config", COMMAND_TYPE, CMD_CONFIG_SPO2_GET);
|
||||
getSupport().sendCommand("get heart rate config", COMMAND_TYPE, CMD_CONFIG_HEART_RATE_GET);
|
||||
getSupport().sendCommand("get standing reminders config", COMMAND_TYPE, CMD_CONFIG_STANDING_REMINDER_GET);
|
||||
getSupport().sendCommand("get stress config", COMMAND_TYPE, CMD_CONFIG_STRESS_GET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSendConfiguration(final String config, final Prefs prefs) {
|
||||
final TransactionBuilder builder = getSupport().createTransactionBuilder("set " + config);
|
||||
|
||||
switch (config) {
|
||||
case ActivityUser.PREF_USER_HEIGHT_CM:
|
||||
case ActivityUser.PREF_USER_WEIGHT_KG:
|
||||
@ -167,8 +165,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
|
||||
case ActivityUser.PREF_USER_STEPS_GOAL:
|
||||
case ActivityUser.PREF_USER_GOAL_STANDING_TIME_HOURS:
|
||||
case ActivityUser.PREF_USER_ACTIVETIME_MINUTES:
|
||||
setUserInfo(builder);
|
||||
builder.queue(getSupport().getQueue());
|
||||
setUserInfo();
|
||||
return true;
|
||||
case DeviceSettingsPreferenceConst.PREF_HEARTRATE_USE_FOR_SLEEP_DETECTION:
|
||||
case DeviceSettingsPreferenceConst.PREF_HEARTRATE_SLEEP_BREATHING_QUALITY_MONITORING:
|
||||
@ -176,11 +173,11 @@ public class XiaomiHealthService extends AbstractXiaomiService {
|
||||
case DeviceSettingsPreferenceConst.PREF_HEARTRATE_ALERT_ENABLED:
|
||||
case DeviceSettingsPreferenceConst.PREF_HEARTRATE_ALERT_HIGH_THRESHOLD:
|
||||
case DeviceSettingsPreferenceConst.PREF_HEARTRATE_ALERT_LOW_THRESHOLD:
|
||||
setHeartRateConfig(builder);
|
||||
setHeartRateConfig();
|
||||
return true;
|
||||
case DeviceSettingsPreferenceConst.PREF_SPO2_ALL_DAY_MONITORING:
|
||||
case DeviceSettingsPreferenceConst.PREF_SPO2_LOW_ALERT_THRESHOLD:
|
||||
setSpo2Config(builder);
|
||||
setSpo2Config();
|
||||
return true;
|
||||
case DeviceSettingsPreferenceConst.PREF_INACTIVITY_ENABLE:
|
||||
case DeviceSettingsPreferenceConst.PREF_INACTIVITY_START:
|
||||
@ -188,18 +185,18 @@ public class XiaomiHealthService extends AbstractXiaomiService {
|
||||
case DeviceSettingsPreferenceConst.PREF_INACTIVITY_DND:
|
||||
case DeviceSettingsPreferenceConst.PREF_INACTIVITY_DND_START:
|
||||
case DeviceSettingsPreferenceConst.PREF_INACTIVITY_DND_END:
|
||||
setStandingReminderConfig(builder);
|
||||
setStandingReminderConfig();
|
||||
return true;
|
||||
case DeviceSettingsPreferenceConst.PREF_HEARTRATE_STRESS_MONITORING:
|
||||
case DeviceSettingsPreferenceConst.PREF_HEARTRATE_STRESS_RELAXATION_REMINDER:
|
||||
setStressConfig(builder);
|
||||
setStressConfig();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setUserInfo(final TransactionBuilder builder) {
|
||||
public void setUserInfo() {
|
||||
LOG.debug("Setting user info");
|
||||
|
||||
final ActivityUser activityUser = new ActivityUser();
|
||||
@ -235,7 +232,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
|
||||
.build();
|
||||
|
||||
getSupport().sendCommand(
|
||||
builder,
|
||||
"set user info",
|
||||
XiaomiProto.Command.newBuilder()
|
||||
.setType(COMMAND_TYPE)
|
||||
.setSubtype(CMD_SET_USER_INFO)
|
||||
@ -257,7 +254,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
|
||||
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
|
||||
}
|
||||
|
||||
private void setSpo2Config(final TransactionBuilder builder) {
|
||||
private void setSpo2Config() {
|
||||
LOG.debug("Set SpO2 config");
|
||||
|
||||
final Prefs prefs = getDevicePrefs();
|
||||
@ -277,7 +274,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
|
||||
.setAlarmLow(spo2alarmLowBuilder);
|
||||
|
||||
getSupport().sendCommand(
|
||||
builder,
|
||||
"set spo2 config",
|
||||
XiaomiProto.Command.newBuilder()
|
||||
.setType(COMMAND_TYPE)
|
||||
.setSubtype(CMD_CONFIG_SPO2_SET)
|
||||
@ -315,7 +312,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
|
||||
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
|
||||
}
|
||||
|
||||
private void setHeartRateConfig(final TransactionBuilder builder) {
|
||||
private void setHeartRateConfig() {
|
||||
final Prefs prefs = getDevicePrefs();
|
||||
|
||||
final boolean sleepDetection = prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_HEARTRATE_USE_FOR_SLEEP_DETECTION, false);
|
||||
@ -338,7 +335,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
|
||||
.setUnknown7(1);
|
||||
|
||||
getSupport().sendCommand(
|
||||
builder,
|
||||
"set heart rate config",
|
||||
XiaomiProto.Command.newBuilder()
|
||||
.setType(COMMAND_TYPE)
|
||||
.setSubtype(CMD_CONFIG_HEART_RATE_SET)
|
||||
@ -366,7 +363,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
|
||||
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
|
||||
}
|
||||
|
||||
private void setStandingReminderConfig(final TransactionBuilder builder) {
|
||||
private void setStandingReminderConfig() {
|
||||
LOG.debug("Set standing reminder config");
|
||||
|
||||
final Prefs prefs = getDevicePrefs();
|
||||
@ -387,7 +384,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
|
||||
.build();
|
||||
|
||||
getSupport().sendCommand(
|
||||
builder,
|
||||
"set standing reminder config",
|
||||
XiaomiProto.Command.newBuilder()
|
||||
.setType(COMMAND_TYPE)
|
||||
.setSubtype(CMD_CONFIG_STANDING_REMINDER_SET)
|
||||
@ -406,7 +403,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
|
||||
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
|
||||
}
|
||||
|
||||
private void setStressConfig(final TransactionBuilder builder) {
|
||||
private void setStressConfig() {
|
||||
LOG.debug("Set stress config");
|
||||
|
||||
final Prefs prefs = getDevicePrefs();
|
||||
@ -418,7 +415,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
|
||||
.setRelaxReminder(XiaomiProto.RelaxReminder.newBuilder().setEnabled(relaxReminder).setUnknown2(0));
|
||||
|
||||
getSupport().sendCommand(
|
||||
builder,
|
||||
"set stress config",
|
||||
XiaomiProto.Command.newBuilder()
|
||||
.setType(COMMAND_TYPE)
|
||||
.setSubtype(CMD_CONFIG_STRESS_SET)
|
||||
|
@ -55,8 +55,8 @@ public class XiaomiNotificationService extends AbstractXiaomiService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(final TransactionBuilder builder) {
|
||||
requestCannedMessages(builder);
|
||||
public void initialize() {
|
||||
requestCannedMessages();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -128,7 +128,7 @@ public class XiaomiNotificationService extends AbstractXiaomiService {
|
||||
.build();
|
||||
|
||||
getSupport().sendCommand(
|
||||
"send notification",
|
||||
"send notification " + notificationSpec.getId(),
|
||||
XiaomiProto.Command.newBuilder()
|
||||
.setType(COMMAND_TYPE)
|
||||
.setSubtype(CMD_NOTIFICATION_SEND)
|
||||
@ -235,9 +235,9 @@ public class XiaomiNotificationService extends AbstractXiaomiService {
|
||||
);
|
||||
}
|
||||
|
||||
public void requestCannedMessages(final TransactionBuilder builder) {
|
||||
public void requestCannedMessages() {
|
||||
getSupport().sendCommand(
|
||||
builder,
|
||||
"get canned messages",
|
||||
XiaomiProto.Command.newBuilder()
|
||||
.setType(COMMAND_TYPE)
|
||||
.setSubtype(CMD_CANNED_MESSAGES_GET)
|
||||
|
@ -109,10 +109,10 @@ public class XiaomiScheduleService extends AbstractXiaomiService {
|
||||
break;
|
||||
case CMD_ALARMS_CREATE:
|
||||
pendingAlarmAcks--;
|
||||
LOG.debug("Got alarms create ack, remaining {}", pendingAlarmAcks);
|
||||
if (pendingAlarmAcks <= 0) {
|
||||
final TransactionBuilder builder = getSupport().createTransactionBuilder("request alarms after all acks");
|
||||
requestAlarms(builder);
|
||||
builder.queue(getSupport().getQueue());
|
||||
LOG.debug("Requesting alarms after all acks");
|
||||
requestAlarms();
|
||||
}
|
||||
break;
|
||||
case CMD_WORLD_CLOCKS_GET:
|
||||
@ -126,10 +126,10 @@ public class XiaomiScheduleService extends AbstractXiaomiService {
|
||||
break;
|
||||
case CMD_REMINDERS_CREATE:
|
||||
pendingReminderAcks--;
|
||||
LOG.debug("Got alarms create ack, remaining {}", pendingReminderAcks);
|
||||
if (pendingReminderAcks <= 0) {
|
||||
final TransactionBuilder builder = getSupport().createTransactionBuilder("request reminders after all acks");
|
||||
requestReminders(builder);
|
||||
builder.queue(getSupport().getQueue());
|
||||
LOG.debug("Requesting reminders after all acks");
|
||||
requestReminders();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -138,30 +138,28 @@ public class XiaomiScheduleService extends AbstractXiaomiService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(final TransactionBuilder builder) {
|
||||
requestAlarms(builder);
|
||||
requestReminders(builder);
|
||||
requestWorldClocks(builder);
|
||||
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_SLEEP_MODE_GET);
|
||||
public void initialize() {
|
||||
requestAlarms();
|
||||
requestReminders();
|
||||
requestWorldClocks();
|
||||
getSupport().sendCommand("get sleep mode", COMMAND_TYPE, CMD_SLEEP_MODE_GET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSendConfiguration(final String config, final Prefs prefs) {
|
||||
final TransactionBuilder builder = getSupport().createTransactionBuilder("set " + config);
|
||||
|
||||
switch (config) {
|
||||
case DeviceSettingsPreferenceConst.PREF_SLEEP_TIME:
|
||||
case DeviceSettingsPreferenceConst.PREF_SLEEP_TIME_START:
|
||||
case DeviceSettingsPreferenceConst.PREF_SLEEP_TIME_END:
|
||||
setSleepModeConfig(builder);
|
||||
setSleepModeConfig();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void requestReminders(final TransactionBuilder builder) {
|
||||
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_REMINDERS_GET);
|
||||
public void requestReminders() {
|
||||
getSupport().sendCommand("request reminders", COMMAND_TYPE, CMD_REMINDERS_GET);
|
||||
}
|
||||
|
||||
public void handleReminders(final XiaomiProto.Reminders reminders) {
|
||||
@ -386,8 +384,8 @@ public class XiaomiScheduleService extends AbstractXiaomiService {
|
||||
);
|
||||
}
|
||||
|
||||
public void requestWorldClocks(final TransactionBuilder builder) {
|
||||
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_WORLD_CLOCKS_GET);
|
||||
public void requestWorldClocks() {
|
||||
getSupport().sendCommand("get world clocks", COMMAND_TYPE, CMD_WORLD_CLOCKS_GET);
|
||||
}
|
||||
|
||||
public void handleWorldClocks(final XiaomiProto.WorldClocks worldClocks) {
|
||||
@ -494,8 +492,8 @@ public class XiaomiScheduleService extends AbstractXiaomiService {
|
||||
}
|
||||
}
|
||||
|
||||
public void requestAlarms(final TransactionBuilder builder) {
|
||||
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_ALARMS_GET);
|
||||
public void requestAlarms() {
|
||||
getSupport().sendCommand("get alarms", COMMAND_TYPE, CMD_ALARMS_GET);
|
||||
}
|
||||
|
||||
public void handleAlarms(final XiaomiProto.Alarms alarms) {
|
||||
@ -589,7 +587,7 @@ public class XiaomiScheduleService extends AbstractXiaomiService {
|
||||
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
|
||||
}
|
||||
|
||||
private void setSleepModeConfig(final TransactionBuilder builder) {
|
||||
private void setSleepModeConfig() {
|
||||
LOG.debug("Set sleep mode config");
|
||||
|
||||
final Prefs prefs = getDevicePrefs();
|
||||
@ -606,7 +604,7 @@ public class XiaomiScheduleService extends AbstractXiaomiService {
|
||||
.build();
|
||||
|
||||
getSupport().sendCommand(
|
||||
builder,
|
||||
"set sleep mode",
|
||||
XiaomiProto.Command.newBuilder()
|
||||
.setType(COMMAND_TYPE)
|
||||
.setSubtype(CMD_SLEEP_MODE_SET)
|
||||
|
@ -68,12 +68,12 @@ public class XiaomiSystemService extends AbstractXiaomiService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(final TransactionBuilder builder) {
|
||||
public void initialize() {
|
||||
// Request device info and configs
|
||||
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_DEVICE_INFO);
|
||||
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_BATTERY);
|
||||
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_PASSWORD_GET);
|
||||
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_DISPLAY_ITEMS_GET);
|
||||
getSupport().sendCommand("get device info", COMMAND_TYPE, CMD_DEVICE_INFO);
|
||||
getSupport().sendCommand("get battery", COMMAND_TYPE, CMD_BATTERY);
|
||||
getSupport().sendCommand("get password", COMMAND_TYPE, CMD_PASSWORD_GET);
|
||||
getSupport().sendCommand("get display items", COMMAND_TYPE, CMD_DISPLAY_ITEMS_GET);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -113,25 +113,22 @@ public class XiaomiSystemService extends AbstractXiaomiService {
|
||||
|
||||
@Override
|
||||
public boolean onSendConfiguration(final String config, final Prefs prefs) {
|
||||
final TransactionBuilder builder = getSupport().createTransactionBuilder("set " + config);
|
||||
|
||||
switch (config) {
|
||||
case DeviceSettingsPreferenceConst.PREF_TIMEFORMAT:
|
||||
setCurrentTime(builder);
|
||||
builder.queue(getSupport().getQueue());
|
||||
setCurrentTime();
|
||||
return true;
|
||||
case PasswordCapabilityImpl.PREF_PASSWORD_ENABLED:
|
||||
case PasswordCapabilityImpl.PREF_PASSWORD:
|
||||
setPassword(builder);
|
||||
setPassword();
|
||||
case HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE:
|
||||
setDisplayItems(builder);
|
||||
setDisplayItems();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onSendConfiguration(config, prefs);
|
||||
}
|
||||
|
||||
public void setCurrentTime(final TransactionBuilder builder) {
|
||||
public void setCurrentTime() {
|
||||
LOG.debug("Setting current time");
|
||||
|
||||
final Calendar now = GregorianCalendar.getInstance();
|
||||
@ -162,7 +159,7 @@ public class XiaomiSystemService extends AbstractXiaomiService {
|
||||
.build();
|
||||
|
||||
getSupport().sendCommand(
|
||||
builder,
|
||||
"set time",
|
||||
XiaomiProto.Command.newBuilder()
|
||||
.setType(COMMAND_TYPE)
|
||||
.setSubtype(CMD_CLOCK)
|
||||
@ -204,7 +201,7 @@ public class XiaomiSystemService extends AbstractXiaomiService {
|
||||
getSupport().evaluateGBDeviceEvent(batteryInfo);
|
||||
}
|
||||
|
||||
private void setPassword(final TransactionBuilder builder) {
|
||||
private void setPassword() {
|
||||
final Prefs prefs = getDevicePrefs();
|
||||
|
||||
final boolean passwordEnabled = prefs.getBoolean(PasswordCapabilityImpl.PREF_PASSWORD_ENABLED, false);
|
||||
@ -222,7 +219,7 @@ public class XiaomiSystemService extends AbstractXiaomiService {
|
||||
.setPassword(password);
|
||||
|
||||
getSupport().sendCommand(
|
||||
builder,
|
||||
"set password",
|
||||
XiaomiProto.Command.newBuilder()
|
||||
.setType(COMMAND_TYPE)
|
||||
.setSubtype(CMD_PASSWORD_SET)
|
||||
@ -246,7 +243,7 @@ public class XiaomiSystemService extends AbstractXiaomiService {
|
||||
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
|
||||
}
|
||||
|
||||
private void setDisplayItems(final TransactionBuilder builder) {
|
||||
private void setDisplayItems() {
|
||||
final Prefs prefs = getDevicePrefs();
|
||||
final List<String> allScreens = new ArrayList<>(prefs.getList(XiaomiPreferences.getPrefPossibleValuesKey(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE), Collections.emptyList()));
|
||||
final List<String> enabledScreens = new ArrayList<>(prefs.getList(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE, Collections.emptyList()));
|
||||
@ -300,7 +297,7 @@ public class XiaomiSystemService extends AbstractXiaomiService {
|
||||
}
|
||||
|
||||
getSupport().sendCommand(
|
||||
builder,
|
||||
"set display items",
|
||||
XiaomiProto.Command.newBuilder()
|
||||
.setType(COMMAND_TYPE)
|
||||
.setSubtype(CMD_DISPLAY_ITEMS_SET)
|
||||
@ -311,6 +308,7 @@ public class XiaomiSystemService extends AbstractXiaomiService {
|
||||
|
||||
private void handleDisplayItems(final XiaomiProto.DisplayItems displayItems) {
|
||||
LOG.debug("Got {} display items", displayItems.getDisplayItemCount());
|
||||
|
||||
final List<String> allScreens = new ArrayList<>();
|
||||
final List<String> mainScreens = new ArrayList<>();
|
||||
final List<String> moreScreens = new ArrayList<>();
|
||||
|
@ -48,7 +48,7 @@ public class XiaomiWeatherService extends AbstractXiaomiService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(final TransactionBuilder builder) {
|
||||
public void initialize() {
|
||||
// TODO setMeasurementSystem();, or request
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user