1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 05:16:51 +01:00

Zepp OS: Query calendar service version

This commit is contained in:
José Rebelo 2023-08-14 10:16:40 +01:00
parent 3716d99788
commit 19e7003c95

View File

@ -23,8 +23,10 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences;
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.Huami2021Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.AbstractZeppOsService;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
@ -43,6 +45,10 @@ public class ZeppOsCalendarService extends AbstractZeppOsService {
public static final byte CMD_DELETE_EVENT = 0x09;
public static final byte CMD_DELETE_EVENT_ACK = 0x0a;
public static final String PREF_VERSION = "zepp_os_calendar_version";
private int version = -1;
public ZeppOsCalendarService(final Huami2021Support support) {
super(support);
}
@ -57,9 +63,27 @@ public class ZeppOsCalendarService extends AbstractZeppOsService {
return false;
}
@Override
public void initialize(final TransactionBuilder builder) {
requestCapabilities(builder);
}
public void requestCapabilities(final TransactionBuilder builder) {
write(builder, CMD_CAPABILITIES_REQUEST);
}
@Override
public void handlePayload(final byte[] payload) {
switch (payload[0]) {
case CMD_CAPABILITIES_RESPONSE:
version = payload[1];
getSupport().evaluateGBDeviceEvent(new GBDeviceEventUpdatePreferences(PREF_VERSION, version));
if (version != 1) {
LOG.warn("Unsupported calendar service version {}", version);
return;
}
LOG.info("Calendar service version={}", version);
break;
case CMD_EVENTS_RESPONSE:
LOG.info("Got calendar events from band");
decodeAndUpdateCalendarEvents(payload);