Search in sources :

Example 1 with ChargeControllerAccumulationDataCache

use of me.retrodaredevil.solarthing.type.cache.packets.data.ChargeControllerAccumulationDataCache in project solarthing by wildmountainfarms.

the class DataCacheTest method test.

@Test
void test() throws JsonProcessingException {
    ObjectMapper mapper = JacksonUtil.defaultMapper();
    Identifier identifier = new OutbackIdentifier(3);
    ChargeControllerAccumulationDataCache v1 = new ChargeControllerAccumulationDataCache(identifier, 5.5f, 3100L, 7900L, 8.5f, 1000L);
    ChargeControllerAccumulationDataCache v2 = new ChargeControllerAccumulationDataCache(identifier, 6.5f, // even thought this period starts at 8000, we have the last packet's dateMillis from the previous period
    7900L, // even thought this period starts at 8000, we have the last packet's dateMillis from the previous period
    13100L, 0.0f, null);
    ChargeControllerAccumulationDataCache actualResult = v1.combine(v2);
    String resultJson = mapper.writeValueAsString(actualResult);
    // System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(actualResult));
    ChargeControllerAccumulationDataCache parsedResult = mapper.readValue(resultJson, ChargeControllerAccumulationDataCache.class);
    for (ChargeControllerAccumulationDataCache result : new ChargeControllerAccumulationDataCache[] { actualResult, parsedResult }) {
        assertEquals(12.0f, result.getGenerationKWH());
        assertEquals(3100L, result.getFirstDateMillis());
        assertEquals(13100L, result.getLastDateMillis());
        assertEquals(8.5f, result.getUnknownGenerationKWH());
        assertEquals(1000L, result.getUnknownStartDateMillis());
    }
}
Also used : Identifier(me.retrodaredevil.solarthing.packets.identification.Identifier) OutbackIdentifier(me.retrodaredevil.solarthing.solar.outback.OutbackIdentifier) ChargeControllerAccumulationDataCache(me.retrodaredevil.solarthing.type.cache.packets.data.ChargeControllerAccumulationDataCache) OutbackIdentifier(me.retrodaredevil.solarthing.solar.outback.OutbackIdentifier) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Identifier (me.retrodaredevil.solarthing.packets.identification.Identifier)1 OutbackIdentifier (me.retrodaredevil.solarthing.solar.outback.OutbackIdentifier)1 ChargeControllerAccumulationDataCache (me.retrodaredevil.solarthing.type.cache.packets.data.ChargeControllerAccumulationDataCache)1 Test (org.junit.jupiter.api.Test)1