mirror of
https://github.com/zyphlar/LanternPowerMonitor.git
synced 2024-03-08 14:07:47 +00:00
Improve 3A+ case, making it easier to take the pi out. Improve the fit of the Z2 case.
Make it possible for a hub to reload a config automatically when it changes without being restarted. Prevent the auto-calibration on first install from being stomped by the app. Allow updating the hub software via the app.
This commit is contained in:
@@ -209,7 +209,7 @@ public class BreakerConfig implements IIdentical<BreakerConfig> {
|
||||
@Override
|
||||
public boolean isIdentical(BreakerConfig _o) {
|
||||
if (this == _o) return true;
|
||||
return accountId == _o.accountId && CollectionUtils.isIdentical(meters, _o.meters) && CollectionUtils.isIdentical(panels, _o.panels) && CollectionUtils.isIdentical(breakerHubs, _o.breakerHubs) && CollectionUtils.isIdentical(breakerGroups, _o.breakerGroups) && CollectionUtils.isEqual(billingPlans, _o.billingPlans);
|
||||
return accountId == _o.accountId && CollectionUtils.isIdentical(meters, _o.meters) && CollectionUtils.isIdentical(panels, _o.panels) && CollectionUtils.isIdentical(breakerHubs, _o.breakerHubs) && CollectionUtils.isIdentical(breakerGroups, _o.breakerGroups) && CollectionUtils.isIdentical(billingPlans, _o.billingPlans);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@DBSerializable
|
||||
@DBSerializable(autogen = false)
|
||||
public class BreakerHub implements IIdentical<BreakerHub> {
|
||||
private int hub;
|
||||
private double voltageCalibrationFactor;
|
||||
@@ -22,16 +22,24 @@ public class BreakerHub implements IIdentical<BreakerHub> {
|
||||
hub = _hub;
|
||||
}
|
||||
|
||||
public double getRawVoltageCalibrationFactor() {
|
||||
return voltageCalibrationFactor;
|
||||
}
|
||||
|
||||
public double getVoltageCalibrationFactor() {
|
||||
return voltageCalibrationFactor == 0.0?1.0:voltageCalibrationFactor;
|
||||
return voltageCalibrationFactor == 0.0?0.3445:voltageCalibrationFactor;
|
||||
}
|
||||
|
||||
public void setVoltageCalibrationFactor(double _voltageCalibrationFactor) {
|
||||
voltageCalibrationFactor = _voltageCalibrationFactor;
|
||||
}
|
||||
|
||||
public double getRawPortCalibrationFactor() {
|
||||
return portCalibrationFactor;
|
||||
}
|
||||
|
||||
public double getPortCalibrationFactor() {
|
||||
return portCalibrationFactor == 0.0?1.0:portCalibrationFactor;
|
||||
return portCalibrationFactor == 0.0?1.25:portCalibrationFactor;
|
||||
}
|
||||
|
||||
public void setPortCalibrationFactor(double _portCalibrationFactor) {
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
import com.lanternsoftware.util.dao.annotations.PrimaryKey;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@DBSerializable
|
||||
public class HubCommand {
|
||||
@PrimaryKey private String id;
|
||||
private int accountId;
|
||||
private int hub;
|
||||
private Date created;
|
||||
private HubConfigCharacteristic characteristic;
|
||||
private byte[] data;
|
||||
|
||||
public HubCommand() {
|
||||
}
|
||||
|
||||
public HubCommand(int _accountId, HubConfigCharacteristic _characteristic, byte[] _data) {
|
||||
accountId = _accountId;
|
||||
created = new Date();
|
||||
characteristic = _characteristic;
|
||||
data = _data;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String _id) {
|
||||
id = _id;
|
||||
}
|
||||
|
||||
public int getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(int _accountId) {
|
||||
accountId = _accountId;
|
||||
}
|
||||
|
||||
public int getHub() {
|
||||
return hub;
|
||||
}
|
||||
|
||||
public void setHub(int _hub) {
|
||||
hub = _hub;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(Date _created) {
|
||||
created = _created;
|
||||
}
|
||||
|
||||
public HubConfigCharacteristic getCharacteristic() {
|
||||
return characteristic;
|
||||
}
|
||||
|
||||
public void setCharacteristic(HubConfigCharacteristic _characteristic) {
|
||||
characteristic = _characteristic;
|
||||
}
|
||||
|
||||
public byte[] getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(byte[] _data) {
|
||||
data = _data;
|
||||
}
|
||||
|
||||
public List<HubCommand> forAllHubs(BreakerConfig _config) {
|
||||
return CollectionUtils.transform(_config.getBreakerHubs(), _h->forHub(_h.getHub()));
|
||||
}
|
||||
|
||||
public HubCommand forHub(int _hub) {
|
||||
HubCommand c = new HubCommand();
|
||||
c.setAccountId(accountId);
|
||||
c.setHub(_hub);
|
||||
c.setCreated(created);
|
||||
c.setCharacteristic(characteristic);
|
||||
c.setData(data);
|
||||
return c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object _o) {
|
||||
if (this == _o) return true;
|
||||
if (_o == null || getClass() != _o.getClass()) return false;
|
||||
HubCommand that = (HubCommand) _o;
|
||||
return Objects.equals(id, that.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor;
|
||||
|
||||
import com.lanternsoftware.util.dao.annotations.DBSerializable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@DBSerializable
|
||||
public class HubCommands {
|
||||
private List<HubCommand> commands;
|
||||
|
||||
public HubCommands() {
|
||||
}
|
||||
|
||||
public HubCommands(List<HubCommand> _commands) {
|
||||
commands = _commands;
|
||||
}
|
||||
|
||||
public List<HubCommand> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
|
||||
public void setCommands(List<HubCommand> _commands) {
|
||||
commands = _commands;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,10 @@ public enum HubConfigCharacteristic {
|
||||
Host(10, CharacteristicFlag.WRITE),
|
||||
Log(11, CharacteristicFlag.READ),
|
||||
NetworkDetails(12, CharacteristicFlag.READ),
|
||||
Shutdown(13, CharacteristicFlag.WRITE);
|
||||
Shutdown(13, CharacteristicFlag.WRITE),
|
||||
Version(14, CharacteristicFlag.READ),
|
||||
Update(15, CharacteristicFlag.WRITE),
|
||||
ReloadConfig(15, CharacteristicFlag.WRITE);
|
||||
|
||||
public final int idx;
|
||||
public final UUID uuid;
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -31,7 +30,6 @@ public class BillingRateSerializer extends AbstractDaoSerializer<BillingRate>
|
||||
d.put("meter", _o.getMeter());
|
||||
d.put("flow", DaoSerializer.toEnumName(_o.getFlow()));
|
||||
d.put("rate", _o.getRate());
|
||||
d.put("unit", DaoSerializer.toEnumName(_o.getCurrency())); //TODO: Remove post migration
|
||||
d.put("currency", DaoSerializer.toEnumName(_o.getCurrency()));
|
||||
d.put("time_of_day_start", _o.getTimeOfDayStart());
|
||||
d.put("time_of_day_end", _o.getTimeOfDayEnd());
|
||||
@@ -51,8 +49,6 @@ public class BillingRateSerializer extends AbstractDaoSerializer<BillingRate>
|
||||
o.setFlow(DaoSerializer.getEnum(_d, "flow", GridFlow.class));
|
||||
o.setRate(DaoSerializer.getDouble(_d, "rate"));
|
||||
o.setCurrency(DaoSerializer.getEnum(_d, "currency", BillingCurrency.class));
|
||||
if (o.getCurrency() == null)
|
||||
o.setCurrency(DaoSerializer.getEnum(_d, "unit", BillingCurrency.class));
|
||||
o.setTimeOfDayStart(DaoSerializer.getInteger(_d, "time_of_day_start"));
|
||||
o.setTimeOfDayEnd(DaoSerializer.getInteger(_d, "time_of_day_end"));
|
||||
o.setMonthKWhStart(DaoSerializer.getDouble(_d, "month_kwh_start"));
|
||||
|
||||
@@ -26,8 +26,8 @@ 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("voltage_calibration_factor", _o.getRawVoltageCalibrationFactor());
|
||||
d.put("port_calibration_factor", _o.getRawPortCalibrationFactor());
|
||||
d.put("frequency", _o.getFrequency());
|
||||
d.put("bluetooth_mac", _o.getBluetoothMac());
|
||||
return d;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.HubCommand;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.HubConfigCharacteristic;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class HubCommandSerializer extends AbstractDaoSerializer<HubCommand>
|
||||
{
|
||||
@Override
|
||||
public Class<HubCommand> getSupportedClass()
|
||||
{
|
||||
return HubCommand.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(HubCommand _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
if (_o.getId() != null)
|
||||
d.put("_id", _o.getId());
|
||||
d.put("account_id", _o.getAccountId());
|
||||
d.put("hub", _o.getHub());
|
||||
d.put("created", DaoSerializer.toLong(_o.getCreated()));
|
||||
d.put("characteristic", DaoSerializer.toEnumName(_o.getCharacteristic()));
|
||||
d.put("data", _o.getData());
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HubCommand fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
HubCommand o = new HubCommand();
|
||||
o.setId(DaoSerializer.getString(_d, "_id"));
|
||||
o.setAccountId(DaoSerializer.getInteger(_d, "account_id"));
|
||||
o.setHub(DaoSerializer.getInteger(_d, "hub"));
|
||||
o.setCreated(DaoSerializer.getDate(_d, "created"));
|
||||
o.setCharacteristic(DaoSerializer.getEnum(_d, "characteristic", HubConfigCharacteristic.class));
|
||||
o.setData(DaoSerializer.getByteArray(_d, "data"));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.lanternsoftware.datamodel.currentmonitor.dao;
|
||||
|
||||
import com.lanternsoftware.datamodel.currentmonitor.HubCommand;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.HubCommands;
|
||||
import com.lanternsoftware.util.dao.AbstractDaoSerializer;
|
||||
import com.lanternsoftware.util.dao.DaoEntity;
|
||||
import com.lanternsoftware.util.dao.DaoProxyType;
|
||||
import com.lanternsoftware.util.dao.DaoSerializer;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class HubCommandsSerializer extends AbstractDaoSerializer<HubCommands>
|
||||
{
|
||||
@Override
|
||||
public Class<HubCommands> getSupportedClass()
|
||||
{
|
||||
return HubCommands.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DaoProxyType> getSupportedProxies() {
|
||||
return Collections.singletonList(DaoProxyType.MONGO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoEntity toDaoEntity(HubCommands _o)
|
||||
{
|
||||
DaoEntity d = new DaoEntity();
|
||||
d.put("commands", DaoSerializer.toDaoEntities(_o.getCommands(), DaoProxyType.MONGO));
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HubCommands fromDaoEntity(DaoEntity _d)
|
||||
{
|
||||
HubCommands o = new HubCommands();
|
||||
o.setCommands(DaoSerializer.getList(_d, "commands", HubCommand.class));
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,8 @@ com.lanternsoftware.datamodel.currentmonitor.dao.ChargeTotalSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.EnergyBlockSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.EnergySummarySerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.EnergyTotalSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.HubCommandSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.HubCommandsSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.HubPowerMinuteSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.MeterSerializer
|
||||
com.lanternsoftware.datamodel.currentmonitor.dao.NetworkStatusSerializer
|
||||
|
||||
Reference in New Issue
Block a user