Search in sources :

Example 1 with PacketGroup

use of me.retrodaredevil.solarthing.packets.collection.PacketGroup in project solarthing by wildmountainfarms.

the class ACModeActionNode method createAction.

@Override
public Action createAction(ActionEnvironment actionEnvironment) {
    LatestPacketGroupEnvironment latestPacketGroupEnvironment = actionEnvironment.getInjectEnvironment().get(LatestPacketGroupEnvironment.class);
    PacketGroupProvider packetGroupProvider = latestPacketGroupEnvironment.getPacketGroupProvider();
    return new SimpleAction(false) {

        @Override
        protected void onUpdate() {
            super.onUpdate();
            PacketGroup packetGroup = packetGroupProvider.getPacketGroup();
            if (packetGroup == null) {
                LOGGER.warn("packetGroup is null!");
                return;
            }
            FXStatusPacket fxStatusPacket = OutbackUtil.getMasterFX(packetGroup);
            if (fxStatusPacket == null) {
                LOGGER.warn("No master FX Status Packet!");
            } else {
                setDone((fxStatusPacket.getACMode() == acMode) == !not);
            }
        }
    };
}
Also used : PacketGroupProvider(me.retrodaredevil.solarthing.PacketGroupProvider) PacketGroup(me.retrodaredevil.solarthing.packets.collection.PacketGroup) FXStatusPacket(me.retrodaredevil.solarthing.solar.outback.fx.FXStatusPacket) LatestPacketGroupEnvironment(me.retrodaredevil.solarthing.actions.environment.LatestPacketGroupEnvironment) SimpleAction(me.retrodaredevil.action.SimpleAction)

Example 2 with PacketGroup

use of me.retrodaredevil.solarthing.packets.collection.PacketGroup in project solarthing by wildmountainfarms.

the class CouchDbMillisDatabase method jsonDataToStoredPacketGroup.

private VersionedPacket<StoredPacketGroup> jsonDataToStoredPacketGroup(JsonData jsonData) throws SolarThingDatabaseException {
    final JsonNode jsonNode;
    try {
        jsonNode = CouchDbJacksonUtil.getNodeFrom(jsonData);
    } catch (JsonProcessingException e) {
        throw new SolarThingDatabaseException("We couldn't parse some of the data into JSON. This should never happen", e);
    }
    if (!jsonNode.isObject()) {
        throw new SolarThingDatabaseException("Something must be wrong with the packet millis view because we got this jsonNode: " + jsonNode);
    }
    ObjectNode objectNode = (ObjectNode) jsonNode;
    final PacketGroup packetGroup;
    try {
        packetGroup = parser.parse(objectNode);
    } catch (PacketParseException e) {
        throw new SolarThingDatabaseException(e);
    }
    String documentId = objectNode.get("_id").asText();
    String documentRevision = objectNode.get("_rev").asText();
    StoredPacketGroup storedPacketGroup = PacketGroups.createStoredPacketGroup(packetGroup, new CouchDbStoredIdentifier(packetGroup.getDateMillis(), documentId, documentRevision));
    return new VersionedPacket<>(storedPacketGroup, new RevisionUpdateToken(documentRevision));
}
Also used : PacketGroup(me.retrodaredevil.solarthing.packets.collection.PacketGroup) StoredPacketGroup(me.retrodaredevil.solarthing.packets.collection.StoredPacketGroup) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) VersionedPacket(me.retrodaredevil.solarthing.database.VersionedPacket) PacketParseException(me.retrodaredevil.solarthing.packets.collection.parsing.PacketParseException) JsonNode(com.fasterxml.jackson.databind.JsonNode) StoredPacketGroup(me.retrodaredevil.solarthing.packets.collection.StoredPacketGroup) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SolarThingDatabaseException(me.retrodaredevil.solarthing.database.exception.SolarThingDatabaseException)

Example 3 with PacketGroup

use of me.retrodaredevil.solarthing.packets.collection.PacketGroup in project solarthing by wildmountainfarms.

the class FXOperationalModeActionNode method createAction.

@Override
public Action createAction(ActionEnvironment actionEnvironment) {
    LatestPacketGroupEnvironment latestPacketGroupEnvironment = actionEnvironment.getInjectEnvironment().get(LatestPacketGroupEnvironment.class);
    PacketGroupProvider packetGroupProvider = latestPacketGroupEnvironment.getPacketGroupProvider();
    return new SimpleAction(false) {

        @Override
        protected void onUpdate() {
            super.onUpdate();
            PacketGroup packetGroup = packetGroupProvider.getPacketGroup();
            if (packetGroup == null) {
                // packetGroup will only be null in the automation program if a query fails or something. This should never happen in the mate program
                LOGGER.warn("packetGroup is null!");
                return;
            }
            FXStatusPacket fxStatusPacket = OutbackUtil.getMasterFX(packetGroup);
            if (fxStatusPacket == null) {
                LOGGER.warn("No master FX Status Packet!");
            } else {
                setDone((fxStatusPacket.getOperationalMode() == operationalMode) == !not);
            }
        }
    };
}
Also used : PacketGroupProvider(me.retrodaredevil.solarthing.PacketGroupProvider) PacketGroup(me.retrodaredevil.solarthing.packets.collection.PacketGroup) FXStatusPacket(me.retrodaredevil.solarthing.solar.outback.fx.FXStatusPacket) LatestPacketGroupEnvironment(me.retrodaredevil.solarthing.actions.environment.LatestPacketGroupEnvironment) SimpleAction(me.retrodaredevil.action.SimpleAction)

Example 4 with PacketGroup

use of me.retrodaredevil.solarthing.packets.collection.PacketGroup in project solarthing by wildmountainfarms.

the class AuxStateActionNode method createAction.

@Override
public Action createAction(ActionEnvironment actionEnvironment) {
    LatestPacketGroupEnvironment latestPacketGroupEnvironment = actionEnvironment.getInjectEnvironment().get(LatestPacketGroupEnvironment.class);
    PacketGroupProvider packetGroupProvider = latestPacketGroupEnvironment.getPacketGroupProvider();
    return new SimpleAction(false) {

        /**
         * A simple variable to prevent spamming of the log file
         */
        private boolean hadFX = true;

        @Override
        protected void onUpdate() {
            super.onUpdate();
            PacketGroup packetGroup = packetGroupProvider.getPacketGroup();
            if (packetGroup == null) {
                LOGGER.warn("packetGroup is null!");
                return;
            }
            FXStatusPacket fxStatusPacket = OutbackUtil.getMasterFX(packetGroup);
            if (fxStatusPacket == null) {
                if (hadFX) {
                    LOGGER.warn("No master FX Status Packet!");
                }
                hadFX = false;
            } else {
                setDone(fxStatusPacket.isAuxOn() == on);
                if (!hadFX) {
                    LOGGER.info("We now have a master FX Status Packet");
                }
                hadFX = true;
            }
        }
    };
}
Also used : PacketGroupProvider(me.retrodaredevil.solarthing.PacketGroupProvider) PacketGroup(me.retrodaredevil.solarthing.packets.collection.PacketGroup) FXStatusPacket(me.retrodaredevil.solarthing.solar.outback.fx.FXStatusPacket) LatestPacketGroupEnvironment(me.retrodaredevil.solarthing.actions.environment.LatestPacketGroupEnvironment) SimpleAction(me.retrodaredevil.action.SimpleAction)

Aggregations

PacketGroup (me.retrodaredevil.solarthing.packets.collection.PacketGroup)4 SimpleAction (me.retrodaredevil.action.SimpleAction)3 PacketGroupProvider (me.retrodaredevil.solarthing.PacketGroupProvider)3 LatestPacketGroupEnvironment (me.retrodaredevil.solarthing.actions.environment.LatestPacketGroupEnvironment)3 FXStatusPacket (me.retrodaredevil.solarthing.solar.outback.fx.FXStatusPacket)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 VersionedPacket (me.retrodaredevil.solarthing.database.VersionedPacket)1 SolarThingDatabaseException (me.retrodaredevil.solarthing.database.exception.SolarThingDatabaseException)1 StoredPacketGroup (me.retrodaredevil.solarthing.packets.collection.StoredPacketGroup)1 PacketParseException (me.retrodaredevil.solarthing.packets.collection.parsing.PacketParseException)1