1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-09 03:37:03 +01:00

Add weight measurement support for MiScale

This commit is contained in:
Severin von Wnuck-Lipinski 2024-08-11 11:39:08 +02:00 committed by José Rebelo
parent 9ef8bc0d67
commit 3be6ec0007
6 changed files with 145 additions and 0 deletions

View File

@ -40,6 +40,7 @@ public class GBDaoGenerator {
private static final String SAMPLE_HEART_RATE = "heartRate";
private static final String SAMPLE_TEMPERATURE = "temperature";
private static final String SAMPLE_TEMPERATURE_TYPE = "temperatureType";
private static final String SAMPLE_WEIGHT_KG = "weightKg";
private static final String TIMESTAMP_FROM = "timestampFrom";
private static final String TIMESTAMP_TO = "timestampTo";
@ -125,6 +126,7 @@ public class GBDaoGenerator {
addWena3Vo2Sample(schema, user, device);
addWena3StressSample(schema, user, device);
addFemometerVinca2TemperatureSample(schema, user, device);
addMiScaleWeightSample(schema, user, device);
addHuaweiActivitySample(schema, user, device);
@ -1315,4 +1317,11 @@ public class GBDaoGenerator {
addTemperatureProperties(sample);
return sample;
}
private static Entity addMiScaleWeightSample(Schema schema, Entity user, Entity device) {
Entity sample = addEntity(schema, "MiScaleWeightSample");
addCommonTimeSampleProperties("AbstractWeightSample", sample, user, device);
sample.addFloatProperty(SAMPLE_WEIGHT_KG).notNull().codeBeforeGetter(OVERRIDE);
return sample;
}
}

View File

@ -81,6 +81,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.SleepRespiratoryRateSample;
import nodomain.freeyourgadget.gadgetbridge.model.Spo2Sample;
import nodomain.freeyourgadget.gadgetbridge.model.StressSample;
import nodomain.freeyourgadget.gadgetbridge.model.TemperatureSample;
import nodomain.freeyourgadget.gadgetbridge.model.WeightSample;
import nodomain.freeyourgadget.gadgetbridge.service.ServiceDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
@ -275,6 +276,11 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
return null;
}
@Override
public TimeSampleProvider<? extends WeightSample> getWeightSampleProvider(GBDevice device, DaoSession session) {
return null;
}
@Override
@Nullable
public ActivitySummaryParser getActivitySummaryParser(final GBDevice device) {
@ -522,6 +528,11 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
return false;
}
@Override
public boolean supportsWeightMeasurement() {
return false;
}
@Override
public boolean supportsAlarmSnoozing() {
return false;

View File

@ -61,6 +61,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.Spo2Sample;
import nodomain.freeyourgadget.gadgetbridge.model.StressSample;
import nodomain.freeyourgadget.gadgetbridge.model.TemperatureSample;
import nodomain.freeyourgadget.gadgetbridge.model.TimeSample;
import nodomain.freeyourgadget.gadgetbridge.model.WeightSample;
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.ServiceDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.SleepAsAndroidSender;
@ -268,6 +269,12 @@ public interface DeviceCoordinator {
*/
boolean supportsSleepRespiratoryRate();
/**
* Returns true if measurement and fetching of body weight is supported by the device
* (with this coordinator).
*/
boolean supportsWeightMeasurement();
/**
* Returns true if activity data fetching is supported AND possible at this
* very moment. This will consider the device state (being connected/disconnected/busy...)
@ -350,6 +357,11 @@ public interface DeviceCoordinator {
*/
TimeSampleProvider<? extends SleepRespiratoryRateSample> getSleepRespiratoryRateSampleProvider(GBDevice device, DaoSession session);
/**
* Returns the sample provider for weight data, for the device being supported.
*/
TimeSampleProvider<? extends WeightSample> getWeightSampleProvider(GBDevice device, DaoSession session);
/**
* Returns the {@link ActivitySummaryParser} for the device being supported.
*

View File

@ -0,0 +1,54 @@
/* Copyright (C) 2024 Severin von Wnuck-Lipinski
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 <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.miscale;
import androidx.annotation.NonNull;
import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractTimeSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.MiScaleWeightSample;
import nodomain.freeyourgadget.gadgetbridge.entities.MiScaleWeightSampleDao;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
public class MiScaleSampleProvider extends AbstractTimeSampleProvider<MiScaleWeightSample> {
public MiScaleSampleProvider(GBDevice device, DaoSession session) {
super(device, session);
}
@Override
@NonNull
public AbstractDao<MiScaleWeightSample, ?> getSampleDao() {
return getSession().getMiScaleWeightSampleDao();
}
@NonNull
protected Property getTimestampSampleProperty() {
return MiScaleWeightSampleDao.Properties.Timestamp;
}
@NonNull
protected Property getDeviceIdentifierSampleProperty() {
return MiScaleWeightSampleDao.Properties.DeviceId;
}
@Override
public MiScaleWeightSample createSample() {
return new MiScaleWeightSample();
}
}

View File

@ -0,0 +1,35 @@
/* Copyright (C) 2024 Severin von Wnuck-Lipinski
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 <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.entities;
import androidx.annotation.NonNull;
import nodomain.freeyourgadget.gadgetbridge.model.WeightSample;
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
public abstract class AbstractWeightSample extends AbstractTimeSample implements WeightSample {
@NonNull
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
"timestamp=" + DateTimeUtils.formatDateTime(DateTimeUtils.parseTimestampMillis(getTimestamp())) +
", weightKg=" + getWeightKg() +
", userId=" + getUserId() +
", deviceId=" + getDeviceId() +
"}";
}
}

View File

@ -0,0 +1,24 @@
/* Copyright (C) 2024 Severin von Wnuck-Lipinski
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 <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.model;
public interface WeightSample extends TimeSample {
/**
* Returns the weight value.
*/
float getWeightKg();
}