Xiaomi: Remove usage of TransactionBuilders

This commit is contained in:
José Rebelo 2023-10-22 12:18:26 +01:00
parent e2d7798e36
commit 1acd3ac5fd
9 changed files with 76 additions and 129 deletions

View File

@ -103,7 +103,7 @@ public class XiaomiAuthService extends AbstractXiaomiService {
.setAuth(auth) .setAuth(auth)
.build(); .build();
getSupport().sendCommand(builder, command); getSupport().sendCommand("start clear text handshake", command);
} }
@Override @Override
@ -140,7 +140,7 @@ public class XiaomiAuthService extends AbstractXiaomiService {
final TransactionBuilder builder = getSupport().createTransactionBuilder("phase 2 initialize"); final TransactionBuilder builder = getSupport().createTransactionBuilder("phase 2 initialize");
builder.add(new SetDeviceStateAction(getSupport().getDevice(), GBDevice.State.INITIALIZED, getSupport().getContext())); builder.add(new SetDeviceStateAction(getSupport().getDevice(), GBDevice.State.INITIALIZED, getSupport().getContext()));
getSupport().phase2Initialize(builder); getSupport().phase2Initialize();
builder.queue(getSupport().getQueue()); builder.queue(getSupport().getQueue());
} else { } else {
LOG.warn("could not authenticate"); LOG.warn("could not authenticate");

View File

@ -103,7 +103,7 @@ public abstract class XiaomiSupport extends AbstractBTLEDeviceSupport {
protected abstract UUID getCharacteristicCommandWrite(); protected abstract UUID getCharacteristicCommandWrite();
protected abstract UUID getCharacteristicActivityData(); protected abstract UUID getCharacteristicActivityData();
protected abstract UUID getCharacteristicDataUpload(); protected abstract UUID getCharacteristicDataUpload();
protected abstract void startAuthentication(TransactionBuilder builder); protected abstract void startAuthentication(final TransactionBuilder builder);
@Override @Override
protected final TransactionBuilder initializeDevice(final TransactionBuilder builder) { protected final TransactionBuilder initializeDevice(final TransactionBuilder builder) {
@ -234,30 +234,17 @@ public abstract class XiaomiSupport extends AbstractBTLEDeviceSupport {
@Override @Override
public void onSetTime() { public void onSetTime() {
final TransactionBuilder builder; systemService.setCurrentTime();
try {
builder = performInitialized("set time");
} catch (final IOException e) {
LOG.error("Failed to initialize transaction builder", e);
return;
}
systemService.setCurrentTime(builder);
final XiaomiCoordinator coordinator = getCoordinator(); if (getCoordinator().supportsCalendarEvents()) {
if (coordinator.supportsCalendarEvents()) {
// TODO this should not be done here // TODO this should not be done here
calendarService.syncCalendar(builder); calendarService.syncCalendar();
} }
builder.queue(getQueue());
} }
@Override @Override
public void onTestNewFunction() { public void onTestNewFunction() {
final TransactionBuilder builder = createTransactionBuilder("test new function"); sendCommand("test new function", 2, 29);
sendCommand(builder, 2, 29);
builder.queue(getQueue());
} }
@Override @Override
@ -404,7 +391,7 @@ public abstract class XiaomiSupport extends AbstractBTLEDeviceSupport {
return (XiaomiCoordinator) gbDevice.getDeviceCoordinator(); return (XiaomiCoordinator) gbDevice.getDeviceCoordinator();
} }
protected void phase2Initialize(final TransactionBuilder builder) { protected void phase2Initialize() {
LOG.info("phase2Initialize"); LOG.info("phase2Initialize");
characteristicCommandRead.reset(); characteristicCommandRead.reset();
@ -413,21 +400,15 @@ public abstract class XiaomiSupport extends AbstractBTLEDeviceSupport {
characteristicDataUpload.reset(); characteristicDataUpload.reset();
if (GBApplication.getPrefs().getBoolean("datetime_synconconnect", true)) { if (GBApplication.getPrefs().getBoolean("datetime_synconconnect", true)) {
systemService.setCurrentTime(builder); systemService.setCurrentTime();
} }
for (final AbstractXiaomiService service : mServiceMap.values()) { for (final AbstractXiaomiService service : mServiceMap.values()) {
service.initialize(builder); service.initialize();
} }
} }
public void sendCommand(final String taskName, final XiaomiProto.Command command) { 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) { if (this.characteristicCommandWrite == null) {
// Can sometimes happen in race conditions when connecting + receiving calendar event or weather updates // Can sometimes happen in race conditions when connecting + receiving calendar event or weather updates
LOG.warn("characteristicCommandWrite is null!"); LOG.warn("characteristicCommandWrite is null!");
@ -440,27 +421,6 @@ public abstract class XiaomiSupport extends AbstractBTLEDeviceSupport {
this.characteristicCommandWrite.write(commandBytes); 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) { public void sendCommand(final String taskName, final int type, final int subtype) {
sendCommand( sendCommand(
taskName, taskName,

View File

@ -38,7 +38,7 @@ public abstract class AbstractXiaomiService {
public abstract void handleCommand(final XiaomiProto.Command cmd); public abstract void handleCommand(final XiaomiProto.Command cmd);
public void initialize(final TransactionBuilder builder) { public void initialize() {
} }

View File

@ -57,8 +57,8 @@ public class XiaomiCalendarService extends AbstractXiaomiService {
} }
@Override @Override
public void initialize(final TransactionBuilder builder) { public void initialize() {
syncCalendar(builder); syncCalendar();
} }
@Override @Override
@ -83,12 +83,6 @@ public class XiaomiCalendarService extends AbstractXiaomiService {
} }
public void syncCalendar() { 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()) final boolean syncEnabled = GBApplication.getDeviceSpecificSharedPrefs(getSupport().getDevice().getAddress())
.getBoolean(PREF_SYNC_CALENDAR, false); .getBoolean(PREF_SYNC_CALENDAR, false);
@ -138,7 +132,7 @@ public class XiaomiCalendarService extends AbstractXiaomiService {
LOG.debug("Syncing {} calendar events", lastSync.size()); LOG.debug("Syncing {} calendar events", lastSync.size());
getSupport().sendCommand( getSupport().sendCommand(
builder, "sync calendar",
XiaomiProto.Command.newBuilder() XiaomiProto.Command.newBuilder()
.setType(COMMAND_TYPE) .setType(COMMAND_TYPE)
.setSubtype(CMD_CALENDAR_SET) .setSubtype(CMD_CALENDAR_SET)

View File

@ -146,18 +146,16 @@ public class XiaomiHealthService extends AbstractXiaomiService {
} }
@Override @Override
public void initialize(final TransactionBuilder builder) { public void initialize() {
setUserInfo(builder); setUserInfo();
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_CONFIG_SPO2_GET); getSupport().sendCommand("get spo2 config", COMMAND_TYPE, CMD_CONFIG_SPO2_GET);
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_CONFIG_HEART_RATE_GET); getSupport().sendCommand("get heart rate config", COMMAND_TYPE, CMD_CONFIG_HEART_RATE_GET);
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_CONFIG_STANDING_REMINDER_GET); getSupport().sendCommand("get standing reminders config", COMMAND_TYPE, CMD_CONFIG_STANDING_REMINDER_GET);
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_CONFIG_STRESS_GET); getSupport().sendCommand("get stress config", COMMAND_TYPE, CMD_CONFIG_STRESS_GET);
} }
@Override @Override
public boolean onSendConfiguration(final String config, final Prefs prefs) { public boolean onSendConfiguration(final String config, final Prefs prefs) {
final TransactionBuilder builder = getSupport().createTransactionBuilder("set " + config);
switch (config) { switch (config) {
case ActivityUser.PREF_USER_HEIGHT_CM: case ActivityUser.PREF_USER_HEIGHT_CM:
case ActivityUser.PREF_USER_WEIGHT_KG: 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_STEPS_GOAL:
case ActivityUser.PREF_USER_GOAL_STANDING_TIME_HOURS: case ActivityUser.PREF_USER_GOAL_STANDING_TIME_HOURS:
case ActivityUser.PREF_USER_ACTIVETIME_MINUTES: case ActivityUser.PREF_USER_ACTIVETIME_MINUTES:
setUserInfo(builder); setUserInfo();
builder.queue(getSupport().getQueue());
return true; return true;
case DeviceSettingsPreferenceConst.PREF_HEARTRATE_USE_FOR_SLEEP_DETECTION: case DeviceSettingsPreferenceConst.PREF_HEARTRATE_USE_FOR_SLEEP_DETECTION:
case DeviceSettingsPreferenceConst.PREF_HEARTRATE_SLEEP_BREATHING_QUALITY_MONITORING: 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_ENABLED:
case DeviceSettingsPreferenceConst.PREF_HEARTRATE_ALERT_HIGH_THRESHOLD: case DeviceSettingsPreferenceConst.PREF_HEARTRATE_ALERT_HIGH_THRESHOLD:
case DeviceSettingsPreferenceConst.PREF_HEARTRATE_ALERT_LOW_THRESHOLD: case DeviceSettingsPreferenceConst.PREF_HEARTRATE_ALERT_LOW_THRESHOLD:
setHeartRateConfig(builder); setHeartRateConfig();
return true; return true;
case DeviceSettingsPreferenceConst.PREF_SPO2_ALL_DAY_MONITORING: case DeviceSettingsPreferenceConst.PREF_SPO2_ALL_DAY_MONITORING:
case DeviceSettingsPreferenceConst.PREF_SPO2_LOW_ALERT_THRESHOLD: case DeviceSettingsPreferenceConst.PREF_SPO2_LOW_ALERT_THRESHOLD:
setSpo2Config(builder); setSpo2Config();
return true; return true;
case DeviceSettingsPreferenceConst.PREF_INACTIVITY_ENABLE: case DeviceSettingsPreferenceConst.PREF_INACTIVITY_ENABLE:
case DeviceSettingsPreferenceConst.PREF_INACTIVITY_START: case DeviceSettingsPreferenceConst.PREF_INACTIVITY_START:
@ -188,18 +185,18 @@ public class XiaomiHealthService extends AbstractXiaomiService {
case DeviceSettingsPreferenceConst.PREF_INACTIVITY_DND: case DeviceSettingsPreferenceConst.PREF_INACTIVITY_DND:
case DeviceSettingsPreferenceConst.PREF_INACTIVITY_DND_START: case DeviceSettingsPreferenceConst.PREF_INACTIVITY_DND_START:
case DeviceSettingsPreferenceConst.PREF_INACTIVITY_DND_END: case DeviceSettingsPreferenceConst.PREF_INACTIVITY_DND_END:
setStandingReminderConfig(builder); setStandingReminderConfig();
return true; return true;
case DeviceSettingsPreferenceConst.PREF_HEARTRATE_STRESS_MONITORING: case DeviceSettingsPreferenceConst.PREF_HEARTRATE_STRESS_MONITORING:
case DeviceSettingsPreferenceConst.PREF_HEARTRATE_STRESS_RELAXATION_REMINDER: case DeviceSettingsPreferenceConst.PREF_HEARTRATE_STRESS_RELAXATION_REMINDER:
setStressConfig(builder); setStressConfig();
return true; return true;
} }
return false; return false;
} }
public void setUserInfo(final TransactionBuilder builder) { public void setUserInfo() {
LOG.debug("Setting user info"); LOG.debug("Setting user info");
final ActivityUser activityUser = new ActivityUser(); final ActivityUser activityUser = new ActivityUser();
@ -235,7 +232,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
.build(); .build();
getSupport().sendCommand( getSupport().sendCommand(
builder, "set user info",
XiaomiProto.Command.newBuilder() XiaomiProto.Command.newBuilder()
.setType(COMMAND_TYPE) .setType(COMMAND_TYPE)
.setSubtype(CMD_SET_USER_INFO) .setSubtype(CMD_SET_USER_INFO)
@ -257,7 +254,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences); getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
} }
private void setSpo2Config(final TransactionBuilder builder) { private void setSpo2Config() {
LOG.debug("Set SpO2 config"); LOG.debug("Set SpO2 config");
final Prefs prefs = getDevicePrefs(); final Prefs prefs = getDevicePrefs();
@ -277,7 +274,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
.setAlarmLow(spo2alarmLowBuilder); .setAlarmLow(spo2alarmLowBuilder);
getSupport().sendCommand( getSupport().sendCommand(
builder, "set spo2 config",
XiaomiProto.Command.newBuilder() XiaomiProto.Command.newBuilder()
.setType(COMMAND_TYPE) .setType(COMMAND_TYPE)
.setSubtype(CMD_CONFIG_SPO2_SET) .setSubtype(CMD_CONFIG_SPO2_SET)
@ -315,7 +312,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences); getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
} }
private void setHeartRateConfig(final TransactionBuilder builder) { private void setHeartRateConfig() {
final Prefs prefs = getDevicePrefs(); final Prefs prefs = getDevicePrefs();
final boolean sleepDetection = prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_HEARTRATE_USE_FOR_SLEEP_DETECTION, false); final boolean sleepDetection = prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_HEARTRATE_USE_FOR_SLEEP_DETECTION, false);
@ -338,7 +335,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
.setUnknown7(1); .setUnknown7(1);
getSupport().sendCommand( getSupport().sendCommand(
builder, "set heart rate config",
XiaomiProto.Command.newBuilder() XiaomiProto.Command.newBuilder()
.setType(COMMAND_TYPE) .setType(COMMAND_TYPE)
.setSubtype(CMD_CONFIG_HEART_RATE_SET) .setSubtype(CMD_CONFIG_HEART_RATE_SET)
@ -366,7 +363,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences); getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
} }
private void setStandingReminderConfig(final TransactionBuilder builder) { private void setStandingReminderConfig() {
LOG.debug("Set standing reminder config"); LOG.debug("Set standing reminder config");
final Prefs prefs = getDevicePrefs(); final Prefs prefs = getDevicePrefs();
@ -387,7 +384,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
.build(); .build();
getSupport().sendCommand( getSupport().sendCommand(
builder, "set standing reminder config",
XiaomiProto.Command.newBuilder() XiaomiProto.Command.newBuilder()
.setType(COMMAND_TYPE) .setType(COMMAND_TYPE)
.setSubtype(CMD_CONFIG_STANDING_REMINDER_SET) .setSubtype(CMD_CONFIG_STANDING_REMINDER_SET)
@ -406,7 +403,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences); getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
} }
private void setStressConfig(final TransactionBuilder builder) { private void setStressConfig() {
LOG.debug("Set stress config"); LOG.debug("Set stress config");
final Prefs prefs = getDevicePrefs(); final Prefs prefs = getDevicePrefs();
@ -418,7 +415,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
.setRelaxReminder(XiaomiProto.RelaxReminder.newBuilder().setEnabled(relaxReminder).setUnknown2(0)); .setRelaxReminder(XiaomiProto.RelaxReminder.newBuilder().setEnabled(relaxReminder).setUnknown2(0));
getSupport().sendCommand( getSupport().sendCommand(
builder, "set stress config",
XiaomiProto.Command.newBuilder() XiaomiProto.Command.newBuilder()
.setType(COMMAND_TYPE) .setType(COMMAND_TYPE)
.setSubtype(CMD_CONFIG_STRESS_SET) .setSubtype(CMD_CONFIG_STRESS_SET)

View File

@ -55,8 +55,8 @@ public class XiaomiNotificationService extends AbstractXiaomiService {
} }
@Override @Override
public void initialize(final TransactionBuilder builder) { public void initialize() {
requestCannedMessages(builder); requestCannedMessages();
} }
@Override @Override
@ -128,7 +128,7 @@ public class XiaomiNotificationService extends AbstractXiaomiService {
.build(); .build();
getSupport().sendCommand( getSupport().sendCommand(
"send notification", "send notification " + notificationSpec.getId(),
XiaomiProto.Command.newBuilder() XiaomiProto.Command.newBuilder()
.setType(COMMAND_TYPE) .setType(COMMAND_TYPE)
.setSubtype(CMD_NOTIFICATION_SEND) .setSubtype(CMD_NOTIFICATION_SEND)
@ -235,9 +235,9 @@ public class XiaomiNotificationService extends AbstractXiaomiService {
); );
} }
public void requestCannedMessages(final TransactionBuilder builder) { public void requestCannedMessages() {
getSupport().sendCommand( getSupport().sendCommand(
builder, "get canned messages",
XiaomiProto.Command.newBuilder() XiaomiProto.Command.newBuilder()
.setType(COMMAND_TYPE) .setType(COMMAND_TYPE)
.setSubtype(CMD_CANNED_MESSAGES_GET) .setSubtype(CMD_CANNED_MESSAGES_GET)

View File

@ -109,10 +109,10 @@ public class XiaomiScheduleService extends AbstractXiaomiService {
break; break;
case CMD_ALARMS_CREATE: case CMD_ALARMS_CREATE:
pendingAlarmAcks--; pendingAlarmAcks--;
LOG.debug("Got alarms create ack, remaining {}", pendingAlarmAcks);
if (pendingAlarmAcks <= 0) { if (pendingAlarmAcks <= 0) {
final TransactionBuilder builder = getSupport().createTransactionBuilder("request alarms after all acks"); LOG.debug("Requesting alarms after all acks");
requestAlarms(builder); requestAlarms();
builder.queue(getSupport().getQueue());
} }
break; break;
case CMD_WORLD_CLOCKS_GET: case CMD_WORLD_CLOCKS_GET:
@ -126,10 +126,10 @@ public class XiaomiScheduleService extends AbstractXiaomiService {
break; break;
case CMD_REMINDERS_CREATE: case CMD_REMINDERS_CREATE:
pendingReminderAcks--; pendingReminderAcks--;
LOG.debug("Got alarms create ack, remaining {}", pendingReminderAcks);
if (pendingReminderAcks <= 0) { if (pendingReminderAcks <= 0) {
final TransactionBuilder builder = getSupport().createTransactionBuilder("request reminders after all acks"); LOG.debug("Requesting reminders after all acks");
requestReminders(builder); requestReminders();
builder.queue(getSupport().getQueue());
} }
break; break;
} }
@ -138,30 +138,28 @@ public class XiaomiScheduleService extends AbstractXiaomiService {
} }
@Override @Override
public void initialize(final TransactionBuilder builder) { public void initialize() {
requestAlarms(builder); requestAlarms();
requestReminders(builder); requestReminders();
requestWorldClocks(builder); requestWorldClocks();
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_SLEEP_MODE_GET); getSupport().sendCommand("get sleep mode", COMMAND_TYPE, CMD_SLEEP_MODE_GET);
} }
@Override @Override
public boolean onSendConfiguration(final String config, final Prefs prefs) { public boolean onSendConfiguration(final String config, final Prefs prefs) {
final TransactionBuilder builder = getSupport().createTransactionBuilder("set " + config);
switch (config) { switch (config) {
case DeviceSettingsPreferenceConst.PREF_SLEEP_TIME: case DeviceSettingsPreferenceConst.PREF_SLEEP_TIME:
case DeviceSettingsPreferenceConst.PREF_SLEEP_TIME_START: case DeviceSettingsPreferenceConst.PREF_SLEEP_TIME_START:
case DeviceSettingsPreferenceConst.PREF_SLEEP_TIME_END: case DeviceSettingsPreferenceConst.PREF_SLEEP_TIME_END:
setSleepModeConfig(builder); setSleepModeConfig();
return true; return true;
} }
return false; return false;
} }
public void requestReminders(final TransactionBuilder builder) { public void requestReminders() {
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_REMINDERS_GET); getSupport().sendCommand("request reminders", COMMAND_TYPE, CMD_REMINDERS_GET);
} }
public void handleReminders(final XiaomiProto.Reminders reminders) { public void handleReminders(final XiaomiProto.Reminders reminders) {
@ -386,8 +384,8 @@ public class XiaomiScheduleService extends AbstractXiaomiService {
); );
} }
public void requestWorldClocks(final TransactionBuilder builder) { public void requestWorldClocks() {
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_WORLD_CLOCKS_GET); getSupport().sendCommand("get world clocks", COMMAND_TYPE, CMD_WORLD_CLOCKS_GET);
} }
public void handleWorldClocks(final XiaomiProto.WorldClocks worldClocks) { public void handleWorldClocks(final XiaomiProto.WorldClocks worldClocks) {
@ -494,8 +492,8 @@ public class XiaomiScheduleService extends AbstractXiaomiService {
} }
} }
public void requestAlarms(final TransactionBuilder builder) { public void requestAlarms() {
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_ALARMS_GET); getSupport().sendCommand("get alarms", COMMAND_TYPE, CMD_ALARMS_GET);
} }
public void handleAlarms(final XiaomiProto.Alarms alarms) { public void handleAlarms(final XiaomiProto.Alarms alarms) {
@ -589,7 +587,7 @@ public class XiaomiScheduleService extends AbstractXiaomiService {
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences); getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
} }
private void setSleepModeConfig(final TransactionBuilder builder) { private void setSleepModeConfig() {
LOG.debug("Set sleep mode config"); LOG.debug("Set sleep mode config");
final Prefs prefs = getDevicePrefs(); final Prefs prefs = getDevicePrefs();
@ -606,7 +604,7 @@ public class XiaomiScheduleService extends AbstractXiaomiService {
.build(); .build();
getSupport().sendCommand( getSupport().sendCommand(
builder, "set sleep mode",
XiaomiProto.Command.newBuilder() XiaomiProto.Command.newBuilder()
.setType(COMMAND_TYPE) .setType(COMMAND_TYPE)
.setSubtype(CMD_SLEEP_MODE_SET) .setSubtype(CMD_SLEEP_MODE_SET)

View File

@ -68,12 +68,12 @@ public class XiaomiSystemService extends AbstractXiaomiService {
} }
@Override @Override
public void initialize(final TransactionBuilder builder) { public void initialize() {
// Request device info and configs // Request device info and configs
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_DEVICE_INFO); getSupport().sendCommand("get device info", COMMAND_TYPE, CMD_DEVICE_INFO);
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_BATTERY); getSupport().sendCommand("get battery", COMMAND_TYPE, CMD_BATTERY);
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_PASSWORD_GET); getSupport().sendCommand("get password", COMMAND_TYPE, CMD_PASSWORD_GET);
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_DISPLAY_ITEMS_GET); getSupport().sendCommand("get display items", COMMAND_TYPE, CMD_DISPLAY_ITEMS_GET);
} }
@Override @Override
@ -113,25 +113,22 @@ public class XiaomiSystemService extends AbstractXiaomiService {
@Override @Override
public boolean onSendConfiguration(final String config, final Prefs prefs) { public boolean onSendConfiguration(final String config, final Prefs prefs) {
final TransactionBuilder builder = getSupport().createTransactionBuilder("set " + config);
switch (config) { switch (config) {
case DeviceSettingsPreferenceConst.PREF_TIMEFORMAT: case DeviceSettingsPreferenceConst.PREF_TIMEFORMAT:
setCurrentTime(builder); setCurrentTime();
builder.queue(getSupport().getQueue());
return true; return true;
case PasswordCapabilityImpl.PREF_PASSWORD_ENABLED: case PasswordCapabilityImpl.PREF_PASSWORD_ENABLED:
case PasswordCapabilityImpl.PREF_PASSWORD: case PasswordCapabilityImpl.PREF_PASSWORD:
setPassword(builder); setPassword();
case HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE: case HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE:
setDisplayItems(builder); setDisplayItems();
return true; return true;
} }
return super.onSendConfiguration(config, prefs); return super.onSendConfiguration(config, prefs);
} }
public void setCurrentTime(final TransactionBuilder builder) { public void setCurrentTime() {
LOG.debug("Setting current time"); LOG.debug("Setting current time");
final Calendar now = GregorianCalendar.getInstance(); final Calendar now = GregorianCalendar.getInstance();
@ -162,7 +159,7 @@ public class XiaomiSystemService extends AbstractXiaomiService {
.build(); .build();
getSupport().sendCommand( getSupport().sendCommand(
builder, "set time",
XiaomiProto.Command.newBuilder() XiaomiProto.Command.newBuilder()
.setType(COMMAND_TYPE) .setType(COMMAND_TYPE)
.setSubtype(CMD_CLOCK) .setSubtype(CMD_CLOCK)
@ -204,7 +201,7 @@ public class XiaomiSystemService extends AbstractXiaomiService {
getSupport().evaluateGBDeviceEvent(batteryInfo); getSupport().evaluateGBDeviceEvent(batteryInfo);
} }
private void setPassword(final TransactionBuilder builder) { private void setPassword() {
final Prefs prefs = getDevicePrefs(); final Prefs prefs = getDevicePrefs();
final boolean passwordEnabled = prefs.getBoolean(PasswordCapabilityImpl.PREF_PASSWORD_ENABLED, false); final boolean passwordEnabled = prefs.getBoolean(PasswordCapabilityImpl.PREF_PASSWORD_ENABLED, false);
@ -222,7 +219,7 @@ public class XiaomiSystemService extends AbstractXiaomiService {
.setPassword(password); .setPassword(password);
getSupport().sendCommand( getSupport().sendCommand(
builder, "set password",
XiaomiProto.Command.newBuilder() XiaomiProto.Command.newBuilder()
.setType(COMMAND_TYPE) .setType(COMMAND_TYPE)
.setSubtype(CMD_PASSWORD_SET) .setSubtype(CMD_PASSWORD_SET)
@ -246,7 +243,7 @@ public class XiaomiSystemService extends AbstractXiaomiService {
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences); getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
} }
private void setDisplayItems(final TransactionBuilder builder) { private void setDisplayItems() {
final Prefs prefs = getDevicePrefs(); final Prefs prefs = getDevicePrefs();
final List<String> allScreens = new ArrayList<>(prefs.getList(XiaomiPreferences.getPrefPossibleValuesKey(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE), Collections.emptyList())); 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())); 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( getSupport().sendCommand(
builder, "set display items",
XiaomiProto.Command.newBuilder() XiaomiProto.Command.newBuilder()
.setType(COMMAND_TYPE) .setType(COMMAND_TYPE)
.setSubtype(CMD_DISPLAY_ITEMS_SET) .setSubtype(CMD_DISPLAY_ITEMS_SET)
@ -311,6 +308,7 @@ public class XiaomiSystemService extends AbstractXiaomiService {
private void handleDisplayItems(final XiaomiProto.DisplayItems displayItems) { private void handleDisplayItems(final XiaomiProto.DisplayItems displayItems) {
LOG.debug("Got {} display items", displayItems.getDisplayItemCount()); LOG.debug("Got {} display items", displayItems.getDisplayItemCount());
final List<String> allScreens = new ArrayList<>(); final List<String> allScreens = new ArrayList<>();
final List<String> mainScreens = new ArrayList<>(); final List<String> mainScreens = new ArrayList<>();
final List<String> moreScreens = new ArrayList<>(); final List<String> moreScreens = new ArrayList<>();

View File

@ -48,7 +48,7 @@ public class XiaomiWeatherService extends AbstractXiaomiService {
} }
@Override @Override
public void initialize(final TransactionBuilder builder) { public void initialize() {
// TODO setMeasurementSystem();, or request // TODO setMeasurementSystem();, or request
} }