Search in sources :

Example 1 with DeviceAttributesDao

use of nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributesDao 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)

Aggregations

Calendar (java.util.Calendar)1 DeviceAttributes (nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes)1 DeviceAttributesDao (nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributesDao)1