Huawei: Fix SmartAlarm for Huawei Watch GT

Linked to #4308.
This commit is contained in:
Martin.JM 2024-11-09 18:27:14 +01:00 committed by Arjan Schrijver
parent b6f9b9e9db
commit cf308c93ad
3 changed files with 30 additions and 5 deletions

View File

@ -223,10 +223,26 @@ public class HuaweiTLV {
return getBytes(tag)[0];
}
public Byte getByte(int tag, Byte defaultValue) {
try {
return getByte(tag);
} catch (HuaweiPacket.MissingTagException e) {
return defaultValue;
}
}
public Boolean getBoolean(int tag) throws HuaweiPacket.MissingTagException {
return getBytes(tag)[0] == 1;
}
public Boolean getBoolean(int tag, Boolean defaultValue) {
try {
return getBoolean(tag);
} catch (HuaweiPacket.MissingTagException e) {
return defaultValue;
}
}
public Integer getInteger(int tag) throws HuaweiPacket.MissingTagException {
return ByteBuffer.wrap(getBytes(tag)).getInt();
}
@ -243,6 +259,14 @@ public class HuaweiTLV {
return ByteBuffer.wrap(getBytes(tag)).getShort();
}
public Short getShort(int tag, Short defaultValue) {
try {
return getShort(tag);
} catch (HuaweiPacket.MissingTagException e) {
return defaultValue;
}
}
public Integer getAsInteger(int tag) throws HuaweiPacket.MissingTagException {
byte[] bytes = getBytes(tag);
if(bytes.length == 1) {

View File

@ -92,11 +92,11 @@ public class Alarms {
public SmartAlarm(HuaweiTLV tlv) throws ParseException {
this.index = tlv.getByte(0x03);
this.status = tlv.getBoolean(0x04);
this.startHour = (byte) ((tlv.getShort(0x05) >> 8) & 0xFF);
this.startMinute = (byte) (tlv.getShort(0x05) & 0xFF);
this.repeat = tlv.getByte(0x06);
this.aheadTime = tlv.getByte(0x07);
this.status = tlv.getBoolean(0x04, false);
this.startHour = (byte) ((tlv.getShort(0x05, (short) 0) >> 8) & 0xFF);
this.startMinute = (byte) (tlv.getShort(0x05, (short) 0) & 0xFF);
this.repeat = tlv.getByte(0x06, (byte) 0);
this.aheadTime = tlv.getByte(0x07, (byte) 0);
}
public SmartAlarm(boolean status, byte startHour, byte startMinute, byte repeat, byte aheadTime) {

View File

@ -277,6 +277,7 @@ public class HuaweiWeatherManager {
if (response.getTlv().getInteger(0x7f, -1) == 0x000186AA) {
// Send weather
final ArrayList<WeatherSpec> specs = new ArrayList<>(nodomain.freeyourgadget.gadgetbridge.model.Weather.getInstance().getWeatherSpecs());
// TODO: could be empty, not really an issue but we need to check what to send back in that case
this.sendWeather(specs.get(0));
return;
}