Search in sources :

Example 1 with ImmutableRoverErrorModeChangePacket

use of me.retrodaredevil.solarthing.solar.renogy.rover.event.ImmutableRoverErrorModeChangePacket in project solarthing by wildmountainfarms.

the class RenogyTest method testEventPackets.

@Test
void testEventPackets() throws JsonProcessingException {
    PacketTestUtil.testJson(new ImmutableRoverChargingStateChangePacket(RoverIdentifier.getFromNumber(0), ChargingState.MPPT.getValueCode(), null), SolarEventPacket.class);
    PacketTestUtil.testJson(new ImmutableRoverChargingStateChangePacket(RoverIdentifier.getFromNumber(0), ChargingState.BOOST.getValueCode(), ChargingState.MPPT.getValueCode()), SolarEventPacket.class);
    PacketTestUtil.testJson(new ImmutableRoverErrorModeChangePacket(RoverIdentifier.getFromNumber(0), RoverErrorMode.BATTERY_OVER_DISCHARGE.getMaskValue() | RoverErrorMode.AMBIENT_TEMP_HIGH.getMaskValue(), null), SolarEventPacket.class);
    PacketTestUtil.testJson(new ImmutableRoverErrorModeChangePacket(RoverIdentifier.getFromNumber(0), 0, RoverErrorMode.BATTERY_OVER_DISCHARGE.getMaskValue() | RoverErrorMode.AMBIENT_TEMP_HIGH.getMaskValue()), SolarEventPacket.class);
}
Also used : ImmutableRoverErrorModeChangePacket(me.retrodaredevil.solarthing.solar.renogy.rover.event.ImmutableRoverErrorModeChangePacket) ImmutableRoverChargingStateChangePacket(me.retrodaredevil.solarthing.solar.renogy.rover.event.ImmutableRoverChargingStateChangePacket) Test(org.junit.jupiter.api.Test)

Example 2 with ImmutableRoverErrorModeChangePacket

use of me.retrodaredevil.solarthing.solar.renogy.rover.event.ImmutableRoverErrorModeChangePacket in project solarthing by wildmountainfarms.

the class RoverEventUpdaterListReceiver method useData.

private void useData(@NotNull RoverStatusPacket rover, @Nullable RoverStatusPacket previous) {
    final Integer lastChargingStateValue;
    final Integer lastErrorModeValue;
    if (previous == null) {
        lastChargingStateValue = null;
        lastErrorModeValue = null;
    } else {
        lastChargingStateValue = previous.getChargingStateValue();
        lastErrorModeValue = previous.getErrorModeValue();
    }
    int currentChargingStateValue = rover.getChargingStateValue();
    int currentErrorModeValue = rover.getErrorModeValue();
    List<Packet> packets = new ArrayList<>();
    if (lastChargingStateValue == null || lastChargingStateValue != currentChargingStateValue) {
        packets.add(new ImmutableRoverChargingStateChangePacket(rover.getIdentifier(), currentChargingStateValue, lastChargingStateValue));
    }
    if (lastErrorModeValue == null || lastErrorModeValue != currentErrorModeValue) {
        packets.add(new ImmutableRoverErrorModeChangePacket(rover.getIdentifier(), currentErrorModeValue, lastErrorModeValue));
    }
    if (!packets.isEmpty()) {
        eventReceiver.receive(packets);
    }
}
Also used : Packet(me.retrodaredevil.solarthing.packets.Packet) RoverStatusPacket(me.retrodaredevil.solarthing.solar.renogy.rover.RoverStatusPacket) ImmutableRoverErrorModeChangePacket(me.retrodaredevil.solarthing.solar.renogy.rover.event.ImmutableRoverErrorModeChangePacket) ImmutableRoverChargingStateChangePacket(me.retrodaredevil.solarthing.solar.renogy.rover.event.ImmutableRoverChargingStateChangePacket) ImmutableRoverErrorModeChangePacket(me.retrodaredevil.solarthing.solar.renogy.rover.event.ImmutableRoverErrorModeChangePacket) ImmutableRoverChargingStateChangePacket(me.retrodaredevil.solarthing.solar.renogy.rover.event.ImmutableRoverChargingStateChangePacket) ArrayList(java.util.ArrayList)

Aggregations

ImmutableRoverChargingStateChangePacket (me.retrodaredevil.solarthing.solar.renogy.rover.event.ImmutableRoverChargingStateChangePacket)2 ImmutableRoverErrorModeChangePacket (me.retrodaredevil.solarthing.solar.renogy.rover.event.ImmutableRoverErrorModeChangePacket)2 ArrayList (java.util.ArrayList)1 Packet (me.retrodaredevil.solarthing.packets.Packet)1 RoverStatusPacket (me.retrodaredevil.solarthing.solar.renogy.rover.RoverStatusPacket)1 Test (org.junit.jupiter.api.Test)1