Search in sources :

Example 1 with OutbackIdentifier

use of me.retrodaredevil.solarthing.solar.outback.OutbackIdentifier in project solarthing by wildmountainfarms.

the class MXFloatModeStuckEvent method run.

@Override
public void run(MessageSender sender, FragmentedPacketGroup previous, FragmentedPacketGroup current) {
    for (Packet previousPacket : previous.getPackets()) {
        if (previousPacket instanceof MXStatusPacket) {
            MXStatusPacket previousMX = (MXStatusPacket) previousPacket;
            KnownIdentifierFragment<OutbackIdentifier> identifierFragment = IdentifierFragment.create(previous.getFragmentId(previousPacket), previousMX.getIdentifier());
            MXStatusPacket currentMX = null;
            for (Packet currentPacket : current.getPackets()) {
                if (currentPacket instanceof Identifiable) {
                    IdentifierFragment currentIdentifierFragment = IdentifierFragment.create(current.getFragmentId(currentPacket), ((Identifiable) currentPacket).getIdentifier());
                    if (identifierFragment.equals(currentIdentifierFragment)) {
                        currentMX = (MXStatusPacket) currentPacket;
                    }
                }
            }
            if (currentMX == null) {
                continue;
            }
            if (currentMX.isNewDay(previousMX)) {
                enabledMap.put(identifierFragment, true);
            }
            if (enabledMap.getOrDefault(identifierFragment, false)) {
                ChargerMode mode = currentMX.getChargingMode();
                if (mode == ChargerMode.FLOAT) {
                    doAlert(sender, identifierFragment);
                } else if (mode != ChargerMode.SILENT) {
                    enabledMap.put(identifierFragment, false);
                    LOGGER.debug("Disabling " + identifierFragment + " because mode is " + mode);
                }
            }
        }
    }
}
Also used : Packet(me.retrodaredevil.solarthing.packets.Packet) MXStatusPacket(me.retrodaredevil.solarthing.solar.outback.mx.MXStatusPacket) KnownIdentifierFragment(me.retrodaredevil.solarthing.packets.identification.KnownIdentifierFragment) IdentifierFragment(me.retrodaredevil.solarthing.packets.identification.IdentifierFragment) MXStatusPacket(me.retrodaredevil.solarthing.solar.outback.mx.MXStatusPacket) ChargerMode(me.retrodaredevil.solarthing.solar.outback.mx.ChargerMode) OutbackIdentifier(me.retrodaredevil.solarthing.solar.outback.OutbackIdentifier) Identifiable(me.retrodaredevil.solarthing.packets.identification.Identifiable)

Example 2 with OutbackIdentifier

use of me.retrodaredevil.solarthing.solar.outback.OutbackIdentifier in project solarthing by wildmountainfarms.

the class BatteryRecordDataCacheTest method testDeserialize.

@Test
void testDeserialize() throws JsonProcessingException {
    BatteryRecordDataCache cache = new BatteryRecordDataCache(new OutbackIdentifier(1), Instant.parse("2022-02-16T00:29:55Z").toEpochMilli(), Instant.parse("2022-02-16T00:44:52Z").toEpochMilli(), null, new BatteryRecordDataCache.Record(23.9f, Instant.parse("2022-02-16T00:37:34Z").toEpochMilli(), 24.4f, Instant.parse("2022-02-16T00:39:31Z").toEpochMilli(), 0.0, 0, 24.1 * 0.25, Instant.parse("2022-02-16T00:44:52Z").toEpochMilli() - Instant.parse("2022-02-16T00:29:55Z").toEpochMilli(), 0.0, 0L));
    PacketTestUtil.testJson(cache, BatteryRecordDataCache.class);
}
Also used : OutbackIdentifier(me.retrodaredevil.solarthing.solar.outback.OutbackIdentifier) Test(org.junit.jupiter.api.Test)

Example 3 with OutbackIdentifier

use of me.retrodaredevil.solarthing.solar.outback.OutbackIdentifier 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)

Example 4 with OutbackIdentifier

use of me.retrodaredevil.solarthing.solar.outback.OutbackIdentifier in project solarthing by wildmountainfarms.

the class FXAccumulationDataCache method createFromIdentifier.

public static FXAccumulationDataCache createFromIdentifier(Identifier supplementaryIdentifier, Data mainData, Long firstDateMillis, Long lastDateMillis, Data unknownData, Long unknownStartDateMillis) {
    if (!(supplementaryIdentifier instanceof SupplementaryIdentifier)) {
        throw new IllegalArgumentException("The passed identifier is not a SupplementaryIdentifier! It is: " + supplementaryIdentifier.getClass() + " and its value is: " + supplementaryIdentifier.getRepresentation());
    }
    Identifier identifier = ((SupplementaryIdentifier) supplementaryIdentifier).getSupplementaryTo();
    if (!(identifier instanceof OutbackIdentifier)) {
        throw new IllegalArgumentException("identifier should be an OutbackIdentifier! It is: " + identifier.getClass() + " and its value is: " + identifier.getRepresentation());
    }
    OutbackIdentifier outbackIdentifier = (OutbackIdentifier) identifier;
    return new FXAccumulationDataCache(outbackIdentifier.getAddress(), mainData, firstDateMillis, lastDateMillis, unknownData, unknownStartDateMillis);
}
Also used : OutbackIdentifier(me.retrodaredevil.solarthing.solar.outback.OutbackIdentifier) Identifier(me.retrodaredevil.solarthing.packets.identification.Identifier) SupplementaryIdentifier(me.retrodaredevil.solarthing.packets.identification.SupplementaryIdentifier) OutbackIdentifier(me.retrodaredevil.solarthing.solar.outback.OutbackIdentifier) SupplementaryIdentifier(me.retrodaredevil.solarthing.packets.identification.SupplementaryIdentifier)

Aggregations

OutbackIdentifier (me.retrodaredevil.solarthing.solar.outback.OutbackIdentifier)4 Identifier (me.retrodaredevil.solarthing.packets.identification.Identifier)2 Test (org.junit.jupiter.api.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Packet (me.retrodaredevil.solarthing.packets.Packet)1 Identifiable (me.retrodaredevil.solarthing.packets.identification.Identifiable)1 IdentifierFragment (me.retrodaredevil.solarthing.packets.identification.IdentifierFragment)1 KnownIdentifierFragment (me.retrodaredevil.solarthing.packets.identification.KnownIdentifierFragment)1 SupplementaryIdentifier (me.retrodaredevil.solarthing.packets.identification.SupplementaryIdentifier)1 ChargerMode (me.retrodaredevil.solarthing.solar.outback.mx.ChargerMode)1 MXStatusPacket (me.retrodaredevil.solarthing.solar.outback.mx.MXStatusPacket)1 ChargeControllerAccumulationDataCache (me.retrodaredevil.solarthing.type.cache.packets.data.ChargeControllerAccumulationDataCache)1