mirror of
https://github.com/zyphlar/LanternPowerMonitor.git
synced 2024-03-08 14:07:47 +00:00
Allow calibration of all ports on a hub at once in addition to individually.
This commit is contained in:
@@ -2,6 +2,7 @@ package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.NullUtils;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
import com.lanternsoftware.util.dao.annotations.PrimaryKey;
|
||||
|
||||
@@ -102,7 +103,7 @@ public class BreakerConfig {
|
||||
|
||||
public String nextGroupId() {
|
||||
List<Integer> ids = CollectionUtils.transform(getAllBreakerGroupIds(), NullUtils::toInteger);
|
||||
return String.valueOf(CollectionUtils.getLargest(ids) + 1);
|
||||
return String.valueOf(DaoSerializer.toInteger(CollectionUtils.getLargest(ids)) + 1);
|
||||
}
|
||||
|
||||
public void addGroup(BreakerGroup _group) {
|
||||
@@ -116,7 +117,7 @@ public class BreakerConfig {
|
||||
|
||||
public void removeInvalidGroups() {
|
||||
if (breakerGroups != null)
|
||||
breakerGroups.removeIf(_g->!_g.removeInvalidGroups());
|
||||
breakerGroups.removeIf(_g->!_g.removeInvalidGroups(CollectionUtils.transformToSet(panels, BreakerPanel::getIndex)));
|
||||
}
|
||||
|
||||
public String getGroupIdForBreaker(Breaker _breaker) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@DBSerializable()
|
||||
public class BreakerGroup {
|
||||
@@ -169,11 +170,11 @@ public class BreakerGroup {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean removeInvalidGroups() {
|
||||
public boolean removeInvalidGroups(Set<Integer> _validPanels) {
|
||||
if (subGroups != null)
|
||||
subGroups.removeIf(_g->!_g.removeInvalidGroups());
|
||||
subGroups.removeIf(_g->!_g.removeInvalidGroups(_validPanels));
|
||||
if (breakers != null)
|
||||
breakers.removeIf(_b->(_b.getType() == null) || (_b.getType() == BreakerType.EMPTY) || (_b.getPort() < 1));
|
||||
breakers.removeIf(_b->(_b.getType() == null) || (_b.getType() == BreakerType.EMPTY) || (_b.isTandemBreaker() && (_b.getPort() < 1)) || !_validPanels.contains(_b.getPanel()));
|
||||
return CollectionUtils.isNotEmpty(subGroups) || CollectionUtils.isNotEmpty(breakers);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
public class BreakerHub {
|
||||
private int hub;
|
||||
private double voltageCalibrationFactor;
|
||||
private double portCalibrationFactor;
|
||||
private int frequency;
|
||||
private String bluetoothMac;
|
||||
|
||||
@@ -19,13 +20,21 @@ public class BreakerHub {
|
||||
}
|
||||
|
||||
public double getVoltageCalibrationFactor() {
|
||||
return voltageCalibrationFactor;
|
||||
return voltageCalibrationFactor == 0.0?1.0:voltageCalibrationFactor;
|
||||
}
|
||||
|
||||
public void setVoltageCalibrationFactor(double _voltageCalibrationFactor) {
|
||||
voltageCalibrationFactor = _voltageCalibrationFactor;
|
||||
}
|
||||
|
||||
public double getPortCalibrationFactor() {
|
||||
return portCalibrationFactor == 0.0?1.0:portCalibrationFactor;
|
||||
}
|
||||
|
||||
public void setPortCalibrationFactor(double _portCalibrationFactor) {
|
||||
portCalibrationFactor = _portCalibrationFactor;
|
||||
}
|
||||
|
||||
public int getFrequency() {
|
||||
return frequency;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ public class BreakerHubSerializer extends AbstractDaoSerializer<BreakerHub>
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("hub", _o.getHub());
|
||||
d.put("voltage_calibration_factor", _o.getVoltageCalibrationFactor());
|
||||
d.put("port_calibration_factor", _o.getPortCalibrationFactor());
|
||||
d.put("frequency", _o.getFrequency());
|
||||
d.put("bluetooth_mac", _o.getBluetoothMac());
|
||||
return d;
|
||||
@@ -38,6 +39,7 @@ public class BreakerHubSerializer extends AbstractDaoSerializer<BreakerHub>
|
||||
BreakerHub o = new BreakerHub();
|
||||
o.setHub(DaoSerializer.getInteger(_d, "hub"));
|
||||
o.setVoltageCalibrationFactor(DaoSerializer.getDouble(_d, "voltage_calibration_factor"));
|
||||
o.setPortCalibrationFactor(DaoSerializer.getDouble(_d, "port_calibration_factor"));
|
||||
o.setFrequency(DaoSerializer.getInteger(_d, "frequency"));
|
||||
o.setBluetoothMac(DaoSerializer.getString(_d, "bluetooth_mac"));
|
||||
return o;
|
||||
|
||||
Reference in New Issue
Block a user