From 02b052fcaf6c929a383678d4972a19f4e6c5cc3a Mon Sep 17 00:00:00 2001 From: Damien 'Psolyca' Gaignon Date: Fri, 3 May 2024 11:41:40 +0200 Subject: [PATCH] [Huawei] Add Huawei Watch 4 Pro gadget fix --- .../devices/huawei/HuaweiConstants.java | 1 + .../HuaweiWatch4ProCoordinator.java | 51 +++++++++++++++++++ .../gadgetbridge/model/DeviceType.java | 2 + app/src/main/res/values/strings.xml | 1 + 4 files changed, 55 insertions(+) create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/huaweiwatch4pro/HuaweiWatch4ProCoordinator.java diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiConstants.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiConstants.java index 06a9e4a6c..306c89540 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiConstants.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiConstants.java @@ -68,6 +68,7 @@ public final class HuaweiConstants { public static final String HU_WATCHFIT_NAME = "huawei watch fit-"; public static final String HU_WATCHFIT2_NAME = "huawei watch fit 2-"; public static final String HU_WATCHULTIMATE_NAME = "huawei watch ultimate-"; + public static final String HU_WATCH4PRO_NAME = "huawei watch 4 pro-"; public static final String PREF_HUAWEI_ADDRESS = "huawei_address"; public static final String PREF_HUAWEI_WORKMODE = "workmode"; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/huaweiwatch4pro/HuaweiWatch4ProCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/huaweiwatch4pro/HuaweiWatch4ProCoordinator.java new file mode 100644 index 000000000..782d2a331 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/huaweiwatch4pro/HuaweiWatch4ProCoordinator.java @@ -0,0 +1,51 @@ +/* Copyright (C) 2024 Damien Gaignon + + This file is part of Gadgetbridge. + + Gadgetbridge is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Gadgetbridge is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . */ +package nodomain.freeyourgadget.gadgetbridge.devices.huawei.huaweiwatch4pro; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.regex.Pattern; + +import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiBRCoordinator; +import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiConstants; +import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; + +public class HuaweiWatch4ProCoordinator extends HuaweiBRCoordinator { + private static final Logger LOG = LoggerFactory.getLogger(HuaweiWatch4ProCoordinator.class); + + public HuaweiWatch4ProCoordinator() { + super(); + getHuaweiCoordinator().setTransactionCrypted(true); + } + + @Override + public DeviceType getDeviceType() { + return DeviceType.HUAWEIWATCH4PRO; + } + + @Override + protected Pattern getSupportedDeviceName() { + return Pattern.compile("(" + HuaweiConstants.HU_WATCH4PRO_NAME + ").*", Pattern.CASE_INSENSITIVE); + } + + @Override + public int getDeviceNameResource() { + return R.string.devicetype_huawei_watch4pro; + } +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceType.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceType.java index 883dbd015..ecc9365c3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceType.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceType.java @@ -118,6 +118,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.huawei.huaweiband7.HuaweiBan import nodomain.freeyourgadget.gadgetbridge.devices.huawei.huaweiband8.HuaweiBand8Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huawei.huaweibandaw70.HuaweiBandAw70Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huawei.huaweitalkbandb6.HuaweiTalkBandB6Coordinator; +import nodomain.freeyourgadget.gadgetbridge.devices.huawei.huaweiwatch4pro.HuaweiWatch4ProCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huawei.huaweiwatchfit.HuaweiWatchFitCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huawei.huaweiwatchfit2.HuaweiWatchFit2Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.huawei.huaweiwatchgt.HuaweiWatchGTCoordinator; @@ -371,6 +372,7 @@ public enum DeviceType { HUAWEIWATCHFIT(HuaweiWatchFitCoordinator.class), HUAWEIWATCHFIT2(HuaweiWatchFit2Coordinator.class), HUAWEIWATCHULTIMATE(HuaweiWatchUltimateCoordinator.class), + HUAWEIWATCH4PRO(HuaweiWatch4ProCoordinator.class), VESC(VescCoordinator.class), BINARY_SENSOR(BinarySensorCoordinator.class), FLIPPER_ZERO(FlipperZeroCoordinator.class), diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 60b23d8bc..883414852 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1559,6 +1559,7 @@ Huawei Watch Fit Huawei Watch Fit 2 Huawei Watch Ultimate + Huawei Watch 4 Pro Femometer Vinca II Xiaomi Watch Lite Redmi Watch 3 Active