Search in sources :

Example 1 with KnownIdentifierFragment

use of me.retrodaredevil.solarthing.packets.identification.KnownIdentifierFragment 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)

Aggregations

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 OutbackIdentifier (me.retrodaredevil.solarthing.solar.outback.OutbackIdentifier)1 ChargerMode (me.retrodaredevil.solarthing.solar.outback.mx.ChargerMode)1 MXStatusPacket (me.retrodaredevil.solarthing.solar.outback.mx.MXStatusPacket)1