Search in sources :

Example 1 with ImmutableTracerChargingEquipmentStatusChangePacket

use of me.retrodaredevil.solarthing.solar.tracer.event.ImmutableTracerChargingEquipmentStatusChangePacket in project solarthing by wildmountainfarms.

the class TracerEventUpdaterListReceiver method useData.

private void useData(@NotNull TracerStatusPacket tracer, @Nullable TracerStatusPacket previous) {
    final Integer lastChargingEquipmentStatusValue;
    if (previous == null) {
        lastChargingEquipmentStatusValue = null;
    } else {
        lastChargingEquipmentStatusValue = previous.getChargingEquipmentStatus();
    }
    int currentChargingEquipmentStatusValue = tracer.getChargingEquipmentStatus();
    List<Packet> packets = new ArrayList<>();
    if (lastChargingEquipmentStatusValue == null || lastChargingEquipmentStatusValue != currentChargingEquipmentStatusValue) {
        packets.add(new ImmutableTracerChargingEquipmentStatusChangePacket(tracer.getIdentifier(), currentChargingEquipmentStatusValue, lastChargingEquipmentStatusValue));
    }
    if (!packets.isEmpty()) {
        eventReceiver.receive(packets);
    }
}
Also used : Packet(me.retrodaredevil.solarthing.packets.Packet) TracerStatusPacket(me.retrodaredevil.solarthing.solar.tracer.TracerStatusPacket) ImmutableTracerChargingEquipmentStatusChangePacket(me.retrodaredevil.solarthing.solar.tracer.event.ImmutableTracerChargingEquipmentStatusChangePacket) ImmutableTracerChargingEquipmentStatusChangePacket(me.retrodaredevil.solarthing.solar.tracer.event.ImmutableTracerChargingEquipmentStatusChangePacket) ArrayList(java.util.ArrayList)

Example 2 with ImmutableTracerChargingEquipmentStatusChangePacket

use of me.retrodaredevil.solarthing.solar.tracer.event.ImmutableTracerChargingEquipmentStatusChangePacket in project solarthing by wildmountainfarms.

the class TracerTest method testTracerEvents.

@Test
void testTracerEvents() throws JsonProcessingException {
    // 1 is off
    // 15 is something that is not off idk what tho
    PacketTestUtil.testJson(new ImmutableTracerChargingEquipmentStatusChangePacket(TracerIdentifier.getFromNumber(0), 1, 15), SolarEventPacket.class);
    PacketTestUtil.testJson(new ImmutableTracerChargingEquipmentStatusChangePacket(TracerIdentifier.getFromNumber(1), 15, null), SolarEventPacket.class);
}
Also used : ImmutableTracerChargingEquipmentStatusChangePacket(me.retrodaredevil.solarthing.solar.tracer.event.ImmutableTracerChargingEquipmentStatusChangePacket) Test(org.junit.jupiter.api.Test)

Aggregations

ImmutableTracerChargingEquipmentStatusChangePacket (me.retrodaredevil.solarthing.solar.tracer.event.ImmutableTracerChargingEquipmentStatusChangePacket)2 ArrayList (java.util.ArrayList)1 Packet (me.retrodaredevil.solarthing.packets.Packet)1 TracerStatusPacket (me.retrodaredevil.solarthing.solar.tracer.TracerStatusPacket)1 Test (org.junit.jupiter.api.Test)1