Search in sources :

Example 6 with Identifiable

use of me.retrodaredevil.solarthing.packets.identification.Identifiable 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);
                }
            }
        }
    }
}
Also used : Packet(me.retrodaredevil.solarthing.packets.Packet) MXStatusPacket(me.retrodaredevil.solarthing.solar.outback.mx.MXStatusPacket) KnownIdentifierFragment(me.retrodaredevil.solarthing.packets.identification.KnownIdentifierFragment) IdentifierFragment(me.retrodaredevil.solarthing.packets.identification.IdentifierFragment) MXStatusPacket(me.retrodaredevil.solarthing.solar.outback.mx.MXStatusPacket) ChargerMode(me.retrodaredevil.solarthing.solar.outback.mx.ChargerMode) OutbackIdentifier(me.retrodaredevil.solarthing.solar.outback.OutbackIdentifier) Identifiable(me.retrodaredevil.solarthing.packets.identification.Identifiable)

Example 7 with Identifiable

use of me.retrodaredevil.solarthing.packets.identification.Identifiable in project solarthing by wildmountainfarms.

the class PointUtil method getTags.

public static Map<String, String> getTags(Packet packet) {
    Map<String, String> r = new HashMap<>();
    if (packet instanceof Identifiable) {
        Identifier identifier = ((Identifiable) packet).getIdentifier();
        r.put("identifier", identifier.getRepresentation());
        if (identifier instanceof SupplementaryIdentifier) {
            SupplementaryIdentifier supplementaryIdentifier = (SupplementaryIdentifier) identifier;
            r.put("identifier_supplementaryTo", supplementaryIdentifier.getSupplementaryTo().getRepresentation());
        }
    }
    if (packet instanceof DocumentedPacket) {
        DocumentedPacket documentedPacket = (DocumentedPacket) packet;
        DocumentedPacketType type = documentedPacket.getPacketType();
        r.put("packetType", type.toString());
    }
    return r;
}
Also used : Identifier(me.retrodaredevil.solarthing.packets.identification.Identifier) SupplementaryIdentifier(me.retrodaredevil.solarthing.packets.identification.SupplementaryIdentifier) DocumentedPacket(me.retrodaredevil.solarthing.packets.DocumentedPacket) SupplementaryIdentifier(me.retrodaredevil.solarthing.packets.identification.SupplementaryIdentifier) DocumentedPacketType(me.retrodaredevil.solarthing.packets.DocumentedPacketType) Identifiable(me.retrodaredevil.solarthing.packets.identification.Identifiable)

Example 8 with Identifiable

use of me.retrodaredevil.solarthing.packets.identification.Identifiable in project solarthing by wildmountainfarms.

the class StatusChatBotHandler method handleMessage.

@Override
public boolean handleMessage(Message message, MessageSender messageSender) {
    if (ChatBotUtil.isSimilar("battery voltage", message.getText())) {
        FragmentedPacketGroup packetGroup = packetGroupProvider.getPacketGroup();
        Float batteryVoltageAverage = BatteryUtil.getBatteryVoltageAverage(packetGroup);
        if (batteryVoltageAverage == null) {
            messageSender.sendMessage("Battery voltage unavailable from latest data. Sorry!");
        } else {
            messageSender.sendMessage("Battery voltage: " + Formatting.HUNDREDTHS_FORMAT.format(batteryVoltageAverage));
        }
        return true;
    } else if (ChatBotUtil.isSimilar("battery temperature", message.getText()) || ChatBotUtil.isSimilar("battery temp", message.getText())) {
        FragmentedPacketGroup packetGroup = packetGroupProvider.getPacketGroup();
        List<String> lines = new ArrayList<>();
        for (Packet packet : packetGroup.getPackets()) {
            int fragmentId = packetGroup.getFragmentId(packet);
            if (packet instanceof BatteryTemperature && packet instanceof Identifiable) {
                float temperature = ((BatteryTemperature) packet).getBatteryTemperatureFahrenheit();
                IdentityInfo identityInfo = ((Identifiable) packet).getIdentityInfo();
                lines.add(identityInfo.getDisplayName() + " (" + fragmentId + "): " + temperature + "F");
            }
        }
        if (lines.isEmpty()) {
            messageSender.sendMessage("No devices to read temperature!");
        } else {
            messageSender.sendMessage(String.join("\n", lines));
        }
        return true;
    } else if (ChatBotUtil.isSimilar("alter", message.getText())) {
        List<VersionedPacket<StoredAlterPacket>> alterPackets = alterPacketsProvider.getPackets();
        if (alterPackets == null) {
            messageSender.sendMessage("Error - Must have failed to query alter database");
        } else {
            List<String> scheduledCommandLines = new ArrayList<>();
            for (VersionedPacket<StoredAlterPacket> versionedPacket : alterPackets) {
                StoredAlterPacket storedAlterPacket = versionedPacket.getPacket();
                AlterPacket alterPacket = storedAlterPacket.getPacket();
                if (alterPacket instanceof ScheduledCommandPacket) {
                    ScheduledCommandData data = ((ScheduledCommandPacket) alterPacket).getData();
                    // ExecutionReason executionReason = ((ScheduledCommandPacket) alterPacket).getExecutionReason();
                    String timeString = TimeUtil.instantToSlackDateSeconds(Instant.ofEpochMilli(data.getScheduledTimeMillis()));
                    scheduledCommandLines.add(data.getCommandName() + " - " + timeString);
                }
            }
            if (scheduledCommandLines.isEmpty()) {
                messageSender.sendMessage("No scheduled commands (from " + alterPackets.size() + " alter packets)");
            } else {
                messageSender.sendMessage("Scheduled commands:\n\t" + String.join("\n\t", scheduledCommandLines));
            }
        }
        return true;
    }
    return false;
}
Also used : FragmentedPacketGroup(me.retrodaredevil.solarthing.packets.collection.FragmentedPacketGroup) Packet(me.retrodaredevil.solarthing.packets.Packet) VersionedPacket(me.retrodaredevil.solarthing.database.VersionedPacket) StoredAlterPacket(me.retrodaredevil.solarthing.type.alter.StoredAlterPacket) AlterPacket(me.retrodaredevil.solarthing.type.alter.AlterPacket) ScheduledCommandPacket(me.retrodaredevil.solarthing.type.alter.packets.ScheduledCommandPacket) BatteryTemperature(me.retrodaredevil.solarthing.solar.common.BatteryTemperature) StoredAlterPacket(me.retrodaredevil.solarthing.type.alter.StoredAlterPacket) VersionedPacket(me.retrodaredevil.solarthing.database.VersionedPacket) ArrayList(java.util.ArrayList) StoredAlterPacket(me.retrodaredevil.solarthing.type.alter.StoredAlterPacket) AlterPacket(me.retrodaredevil.solarthing.type.alter.AlterPacket) Identifiable(me.retrodaredevil.solarthing.packets.identification.Identifiable) ScheduledCommandPacket(me.retrodaredevil.solarthing.type.alter.packets.ScheduledCommandPacket) IdentityInfo(me.retrodaredevil.solarthing.packets.identification.IdentityInfo) ArrayList(java.util.ArrayList) List(java.util.List) ScheduledCommandData(me.retrodaredevil.solarthing.type.alter.packets.ScheduledCommandData)

Aggregations

Identifiable (me.retrodaredevil.solarthing.packets.identification.Identifiable)8 Packet (me.retrodaredevil.solarthing.packets.Packet)6 Identifier (me.retrodaredevil.solarthing.packets.identification.Identifier)3 IdentifierFragment (me.retrodaredevil.solarthing.packets.identification.IdentifierFragment)3 List (java.util.List)2 Map (java.util.Map)2 FragmentedPacketGroup (me.retrodaredevil.solarthing.packets.collection.FragmentedPacketGroup)2 InstancePacketGroup (me.retrodaredevil.solarthing.packets.collection.InstancePacketGroup)2 ChargerMode (me.retrodaredevil.solarthing.solar.outback.mx.ChargerMode)2 MXStatusPacket (me.retrodaredevil.solarthing.solar.outback.mx.MXStatusPacket)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ValueNode (com.fasterxml.jackson.databind.node.ValueNode)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Nullable (me.retrodaredevil.solarthing.annotations.Nullable)1 VersionedPacket (me.retrodaredevil.solarthing.database.VersionedPacket)1