Search in sources :

Example 1 with Nullable

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);
}
Also used : Identifiable(me.retrodaredevil.solarthing.packets.identification.Identifiable) Nullable(me.retrodaredevil.solarthing.annotations.Nullable)

Example 2 with Nullable

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";
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) IOException(java.io.IOException) Nullable(me.retrodaredevil.solarthing.annotations.Nullable)

Example 3 with Nullable

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;
}
Also used : Packet(me.retrodaredevil.solarthing.packets.Packet) FXStatusPacket(me.retrodaredevil.solarthing.solar.outback.fx.FXStatusPacket) FXStatusPacket(me.retrodaredevil.solarthing.solar.outback.fx.FXStatusPacket) Nullable(me.retrodaredevil.solarthing.annotations.Nullable)

Example 4 with Nullable

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);
    }
}
Also used : DocumentData(me.retrodaredevil.couchdbjava.response.DocumentData) VersionedPacket(me.retrodaredevil.solarthing.database.VersionedPacket) RootMetaPacket(me.retrodaredevil.solarthing.type.closed.meta.RootMetaPacket) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonData(me.retrodaredevil.couchdbjava.json.JsonData) SolarThingDatabaseException(me.retrodaredevil.solarthing.database.exception.SolarThingDatabaseException) Nullable(me.retrodaredevil.solarthing.annotations.Nullable)

Example 5 with Nullable

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);
    }
}
Also used : DocumentData(me.retrodaredevil.couchdbjava.response.DocumentData) AuthorizationPacket(me.retrodaredevil.solarthing.type.closed.authorization.AuthorizationPacket) VersionedPacket(me.retrodaredevil.solarthing.database.VersionedPacket) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonData(me.retrodaredevil.couchdbjava.json.JsonData) SolarThingDatabaseException(me.retrodaredevil.solarthing.database.exception.SolarThingDatabaseException) Nullable(me.retrodaredevil.solarthing.annotations.Nullable)

Aggregations

Nullable (me.retrodaredevil.solarthing.annotations.Nullable)11 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 Packet (me.retrodaredevil.solarthing.packets.Packet)3 File (java.io.File)2 IOException (java.io.IOException)2 JsonData (me.retrodaredevil.couchdbjava.json.JsonData)2 DocumentData (me.retrodaredevil.couchdbjava.response.DocumentData)2 VersionedPacket (me.retrodaredevil.solarthing.database.VersionedPacket)2 SolarThingDatabaseException (me.retrodaredevil.solarthing.database.exception.SolarThingDatabaseException)2 FXStatusPacket (me.retrodaredevil.solarthing.solar.outback.fx.FXStatusPacket)2 MetaDatabase (me.retrodaredevil.solarthing.type.closed.meta.MetaDatabase)2 TargetedMetaPacket (me.retrodaredevil.solarthing.type.closed.meta.TargetedMetaPacket)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 GraphQLQuery (io.leangen.graphql.annotations.GraphQLQuery)1 Files (java.nio.file.Files)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 StandardOpenOption (java.nio.file.StandardOpenOption)1