-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #85. Can now configure how temperature and voltage are retrieved
- Loading branch information
1 parent
b8d3205
commit fdec444
Showing
8 changed files
with
127 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
...c/main/java/me/retrodaredevil/solarthing/program/pvoutput/provider/PVVoltageProvider.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...in/java/me/retrodaredevil/solarthing/program/pvoutput/provider/PacketVoltageProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package me.retrodaredevil.solarthing.program.pvoutput.provider; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import me.retrodaredevil.solarthing.annotations.Nullable; | ||
import me.retrodaredevil.solarthing.packets.Packet; | ||
import me.retrodaredevil.solarthing.packets.collection.FragmentedPacketGroup; | ||
import me.retrodaredevil.solarthing.packets.identification.Identifiable; | ||
import me.retrodaredevil.solarthing.packets.identification.IdentifierFragment; | ||
import me.retrodaredevil.solarthing.packets.identification.IdentifierFragmentMatcher; | ||
import me.retrodaredevil.solarthing.packets.identification.IdentifierRepFragment; | ||
import me.retrodaredevil.solarthing.solar.common.BatteryVoltage; | ||
import me.retrodaredevil.solarthing.solar.common.PVCurrentAndVoltage; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
|
||
@JsonTypeName("packet") | ||
public class PacketVoltageProvider implements VoltageProvider { | ||
private final IdentifierFragmentMatcher voltageIdentifierFragmentMatcher; | ||
private final VoltagePacketType voltagePacketType; | ||
|
||
@JsonCreator | ||
public PacketVoltageProvider( | ||
@JsonProperty(value = "identifier", required = true) @JsonDeserialize(as = IdentifierRepFragment.class) IdentifierFragmentMatcher voltageIdentifierFragmentMatcher, | ||
@JsonProperty("from") VoltagePacketType voltagePacketType) { | ||
this.voltageIdentifierFragmentMatcher = requireNonNull(voltageIdentifierFragmentMatcher); | ||
this.voltagePacketType = voltagePacketType == null ? VoltagePacketType.PV : voltagePacketType; | ||
} | ||
|
||
@Override | ||
public @Nullable Result getResult(FragmentedPacketGroup fragmentedPacketGroup) { | ||
for (Packet packet : fragmentedPacketGroup.getPackets()) { | ||
if (!(packet instanceof Identifiable)) { | ||
continue; | ||
} | ||
int fragmentId = fragmentedPacketGroup.getFragmentId(packet); | ||
IdentifierFragment identifierFragment = IdentifierFragment.create(fragmentId, ((Identifiable) packet).getIdentifier()); | ||
if (!voltageIdentifierFragmentMatcher.matches(identifierFragment)) { | ||
continue; | ||
} | ||
long dateMillis = requireNonNull(fragmentedPacketGroup.getDateMillis(packet), "Implementation of FragmentedPacketGroup did not provide individual dateMillis! type: " + fragmentedPacketGroup.getClass().getName()); | ||
if (voltagePacketType == VoltagePacketType.PV) { | ||
if (packet instanceof PVCurrentAndVoltage) { | ||
PVCurrentAndVoltage pvCurrentAndVoltage = (PVCurrentAndVoltage) packet; | ||
float voltage = pvCurrentAndVoltage.getPVVoltage().floatValue(); | ||
return new Result(voltage, identifierFragment, dateMillis, false); | ||
} | ||
} else if (voltagePacketType == VoltagePacketType.BATTERY) { | ||
if (packet instanceof BatteryVoltage) { | ||
BatteryVoltage batteryVoltagePacket = (BatteryVoltage) packet; | ||
float batteryVoltage = batteryVoltagePacket.getBatteryVoltage(); | ||
return new Result(batteryVoltage, identifierFragment, dateMillis, false); | ||
} | ||
} else throw new AssertionError(); | ||
} | ||
|
||
return null; | ||
} | ||
public enum VoltagePacketType { | ||
PV, | ||
BATTERY | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters