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);
}
}
}
}
}
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);
}
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());
}
}
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);
}
Aggregations