use of me.retrodaredevil.solarthing.solar.renogy.rover.event.ImmutableRoverChargingStateChangePacket 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);
}
use of me.retrodaredevil.solarthing.solar.renogy.rover.event.ImmutableRoverChargingStateChangePacket 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);
}
}
Aggregations