Search in sources :

Example 1 with DeviceAttributes

use of nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes in project Gadgetbridge by Freeyourgadget.

the class EntitiesTest method testDBHelper.

@Test
public void testDBHelper() {
    GBDevice dummyGBDevice = createDummyGDevice("00:00:00:00:01");
    Device device = DBHelper.getDevice(dummyGBDevice, daoSession);
    assertNotNull(device);
    assertEquals("00:00:00:00:01", device.getIdentifier());
    assertEquals("Testie", device.getName());
    assertEquals("4.0", device.getModel());
    assertEquals(DeviceType.TEST.getKey(), device.getType());
    DeviceAttributes attributes = device.getDeviceAttributesList().get(0);
    assertNotNull(attributes);
    assertEquals("1.2.3", attributes.getFirmwareVersion1());
}
Also used : GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) DeviceAttributes(nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) Test(org.junit.Test)

Example 2 with DeviceAttributes

use of nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes in project Gadgetbridge by Freeyourgadget.

the class DeviceHelper method toGBDevice.

/**
     * Converts a known device from the database to a GBDevice.
     * Note: The device might not be supported anymore, so callers should verify that.
     * @param dbDevice
     * @return
     */
public GBDevice toGBDevice(Device dbDevice) {
    DeviceType deviceType = DeviceType.fromKey(dbDevice.getType());
    GBDevice gbDevice = new GBDevice(dbDevice.getIdentifier(), dbDevice.getName(), deviceType);
    List<DeviceAttributes> deviceAttributesList = dbDevice.getDeviceAttributesList();
    if (deviceAttributesList.size() > 0) {
        gbDevice.setModel(dbDevice.getModel());
        DeviceAttributes attrs = deviceAttributesList.get(0);
        gbDevice.setFirmwareVersion(attrs.getFirmwareVersion1());
        gbDevice.setFirmwareVersion2(attrs.getFirmwareVersion2());
        gbDevice.setVolatileAddress(attrs.getVolatileIdentifier());
    }
    return gbDevice;
}
Also used : DeviceType(nodomain.freeyourgadget.gadgetbridge.model.DeviceType) DeviceAttributes(nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)

Example 3 with DeviceAttributes

use of nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes in project Gadgetbridge by Freeyourgadget.

the class DBHelper method ensureDeviceAttributes.

private static void ensureDeviceAttributes(Device device, GBDevice gbDevice, DaoSession session) {
    List<DeviceAttributes> deviceAttributes = device.getDeviceAttributesList();
    DeviceAttributes[] previousDeviceAttributes = new DeviceAttributes[1];
    if (hasUpToDateDeviceAttributes(deviceAttributes, gbDevice, previousDeviceAttributes)) {
        return;
    }
    Calendar now = DateTimeUtils.getCalendarUTC();
    invalidateDeviceAttributes(previousDeviceAttributes[0], now, session);
    DeviceAttributes attributes = new DeviceAttributes();
    attributes.setDeviceId(device.getId());
    attributes.setValidFromUTC(now.getTime());
    attributes.setFirmwareVersion1(gbDevice.getFirmwareVersion());
    attributes.setFirmwareVersion2(gbDevice.getFirmwareVersion2());
    attributes.setVolatileIdentifier(gbDevice.getVolatileAddress());
    DeviceAttributesDao attributesDao = session.getDeviceAttributesDao();
    attributesDao.insert(attributes);
    // sort order is important, so we re-fetch from the db
    //        deviceAttributes.add(attributes);
    device.resetDeviceAttributesList();
}
Also used : Calendar(java.util.Calendar) DeviceAttributes(nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes) DeviceAttributesDao(nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributesDao)

Example 4 with DeviceAttributes

use of nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes in project Gadgetbridge by Freeyourgadget.

the class EntitiesTest method testDeviceAttributes.

@Test
public void testDeviceAttributes() throws Exception {
    GBDevice dummyGBDevice = createDummyGDevice("00:00:00:00:02");
    dummyGBDevice.setFirmwareVersion("1.0");
    Device deviceOld = DBHelper.getDevice(dummyGBDevice, daoSession);
    assertNotNull(deviceOld);
    List<DeviceAttributes> attrListOld = deviceOld.getDeviceAttributesList();
    assertEquals(1, attrListOld.size());
    assertEquals("1.0", attrListOld.get(0).getFirmwareVersion1());
    assertEquals("1.0", DBHelper.getDeviceAttributes(deviceOld).getFirmwareVersion1());
    // some time passes, firmware update occurs
    Thread.sleep(2 * 1000);
    dummyGBDevice.setFirmwareVersion("2.0");
    Device deviceNew = DBHelper.getDevice(dummyGBDevice, daoSession);
    assertNotNull(deviceNew);
    List<DeviceAttributes> attrListNew = deviceNew.getDeviceAttributesList();
    assertEquals(2, attrListNew.size());
    assertEquals("2.0", attrListNew.get(0).getFirmwareVersion1());
    assertEquals("1.0", attrListNew.get(1).getFirmwareVersion1());
    assertEquals("2.0", DBHelper.getDeviceAttributes(deviceNew).getFirmwareVersion1());
}
Also used : GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) DeviceAttributes(nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) Test(org.junit.Test)

Aggregations

DeviceAttributes (nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes)4 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)3 Device (nodomain.freeyourgadget.gadgetbridge.entities.Device)2 Test (org.junit.Test)2 Calendar (java.util.Calendar)1 DeviceAttributesDao (nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributesDao)1 DeviceType (nodomain.freeyourgadget.gadgetbridge.model.DeviceType)1