mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
Store the DeviceType in the Device entity
(so that we can later recreate a GBDevice from a Device)
This commit is contained in:
parent
e0c52c7da5
commit
26d490ffd6
@ -112,6 +112,7 @@ public class GBDaoGenerator {
|
||||
device.addStringProperty("name").notNull();
|
||||
device.addStringProperty("manufacturer").notNull();
|
||||
device.addStringProperty("identifier").notNull().unique().javaDocGetterAndSetter("The fixed identifier, i.e. MAC address of the device.");
|
||||
device.addIntProperty("type").notNull().javaDocGetterAndSetter("The DeviceType key, i.e. the GBDevice's type.");
|
||||
Property deviceId = deviceAttributes.addLongProperty("deviceId").notNull().getProperty();
|
||||
// sorted by the from-date, newest first
|
||||
Property deviceAttributesSortProperty = getPropertyByName(deviceAttributes, VALID_FROM_UTC);
|
||||
|
@ -302,6 +302,7 @@ public class DBHelper {
|
||||
device.setName(gbDevice.getName());
|
||||
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(gbDevice);
|
||||
device.setManufacturer(coordinator.getManufacturer());
|
||||
device.setType(gbDevice.getType().getKey());
|
||||
session.getDeviceDao().insert(device);
|
||||
|
||||
return device;
|
||||
|
@ -2,11 +2,33 @@ package nodomain.freeyourgadget.gadgetbridge.model;
|
||||
|
||||
/**
|
||||
* For every supported device, a device type constant must exist.
|
||||
*
|
||||
* Note: they key of every constant is stored in the DB, so it is fixed forever,
|
||||
* and may not be changed.
|
||||
*/
|
||||
public enum DeviceType {
|
||||
UNKNOWN,
|
||||
PEBBLE,
|
||||
TEST,
|
||||
MIBAND,
|
||||
MIBAND2
|
||||
UNKNOWN(-1),
|
||||
PEBBLE(1),
|
||||
MIBAND(10),
|
||||
MIBAND2(11),
|
||||
TEST(1000);
|
||||
|
||||
private final int key;
|
||||
|
||||
DeviceType(int key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public int getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public static DeviceType fromKey(int key) {
|
||||
for (DeviceType type : values()) {
|
||||
if (type.key == key) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return DeviceType.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user