Store the DeviceType in the Device entity

(so that we can later recreate a GBDevice from a Device)
master
cpfeiffer 2016-08-17 00:34:19 +02:00
parent e0c52c7da5
commit 26d490ffd6
3 changed files with 29 additions and 5 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;
}
}