use of me.retrodaredevil.solarthing.annotations.Nullable in project solarthing by wildmountainfarms.
the class PacketFinder method findPacket.
@Nullable
public synchronized Identifiable findPacket(IdentifierFragment identifierFragment, long queryStart, long queryEnd) {
Identifiable result = cacheMap.get(identifierFragment);
if (result != null) {
return result;
}
updateWithRange(queryStart, queryEnd);
return cacheMap.get(identifierFragment);
}
use of me.retrodaredevil.solarthing.annotations.Nullable in project solarthing by wildmountainfarms.
the class NetCatUtil method handle.
@Nullable
public static String handle(Object write, Packet packet, String request) {
String[] split = StringUtil.terminalSplit(request);
if (split.length == 0) {
return null;
}
String fieldName = split[0];
if (split.length == 1) {
ObjectNode node = MAPPER.valueToTree(packet);
JsonNode value = node.get(fieldName);
if (value == null) {
return "unknown field";
}
return value.asText();
}
String value = split[1];
ObjectReader reader = MAPPER.readerForUpdating(write);
ObjectNode input = new ObjectNode(JsonNodeFactory.instance);
input.put(fieldName, value);
try {
reader.readValue(input);
} catch (IOException e) {
return "Got error: " + e.getMessage();
}
return "success";
}
use of me.retrodaredevil.solarthing.annotations.Nullable in project solarthing by wildmountainfarms.
the class GeneratorUnusedAlertEvent method createDesiredTrigger.
@Override
@Nullable
protected Runnable createDesiredTrigger(MessageSender sender, FragmentedPacketGroup previous, FragmentedPacketGroup current) {
// on one FX to be greater than another, so we want to check to see if this applied to *any* FXs
for (Packet packet : current.getPackets()) {
if (packet instanceof FXStatusPacket) {
FXStatusPacket fx = (FXStatusPacket) packet;
boolean is230 = fx.is230V();
int lowThreshold = is230 && lowRaw ? 2 * lowThresholdVoltage : lowThresholdVoltage;
int inputVoltage = fx.getInputVoltage();
if (fx.getACMode() == ACMode.AC_DROP) {
return () -> sender.sendMessage("Generator dropping power! (on and not using for " + getPrettyDurationString() + ")");
}
if (inputVoltage >= lowThreshold && fx.getACMode() != ACMode.AC_USE) {
return () -> sender.sendMessage("Low Generator Voltage! " + inputVoltage + "V (on and not using for " + getPrettyDurationString() + ")");
}
}
}
return null;
}
use of me.retrodaredevil.solarthing.annotations.Nullable in project solarthing by wildmountainfarms.
the class CouchDbSolarThingDatabase method queryMetadata.
@Override
@Nullable
public VersionedPacket<RootMetaPacket> queryMetadata(UpdateToken updateToken) throws SolarThingDatabaseException {
DocumentData data = queryDocument(closedDatabase, RootMetaPacket.DOCUMENT_ID, updateToken);
if (data == null) {
return null;
}
JsonData jsonData = data.getJsonData();
try {
RootMetaPacket packet = CouchDbJacksonUtil.readValue(metaObjectMapper, jsonData, RootMetaPacket.class);
return new VersionedPacket<>(packet, new RevisionUpdateToken(data.getRevision()));
} catch (JsonProcessingException e) {
throw new SolarThingDatabaseException("Invalid meta! Failed to parse!", e);
}
}
use of me.retrodaredevil.solarthing.annotations.Nullable in project solarthing by wildmountainfarms.
the class CouchDbSolarThingDatabase method queryAuthorized.
@Override
@Nullable
public VersionedPacket<AuthorizationPacket> queryAuthorized(UpdateToken updateToken) throws SolarThingDatabaseException {
DocumentData data = queryDocument(closedDatabase, AuthorizationPacket.DOCUMENT_ID, updateToken);
if (data == null) {
return null;
}
JsonData jsonData = data.getJsonData();
try {
AuthorizationPacket packet = CouchDbJacksonUtil.readValue(simpleObjectMapper, jsonData, AuthorizationPacket.class);
return new VersionedPacket<>(packet, new RevisionUpdateToken(data.getRevision()));
} catch (JsonProcessingException e) {
throw new SolarThingDatabaseException("Invalid authorization packet! Failed to parse!", e);
}
}
Aggregations