[omnikinverter] feature: Add channels for voltage and current (#11645)
Signed-off-by: Hans van den Bogert <hansbogert@gmail.com>
This commit is contained in:
committed by
GitHub
parent
c71e5bd083
commit
4291729c7b
@@ -30,7 +30,18 @@ public class OmnikInverterBindingConstants {
|
||||
public static final ThingTypeUID THING_TYPE_OMNIK = new ThingTypeUID(BINDING_ID, "omnik");
|
||||
|
||||
// List of all Channel ids
|
||||
public static final String CHANNEL_CURRENT_PV1 = "currentPV1";
|
||||
public static final String CHANNEL_CURRENT_PV2 = "currentPV2";
|
||||
public static final String CHANNEL_CURRENT_PV3 = "currentPV3";
|
||||
|
||||
public static final String CHANNEL_VOLTAGE_PV1 = "voltagePV1";
|
||||
public static final String CHANNEL_VOLTAGE_PV2 = "voltagePV2";
|
||||
public static final String CHANNEL_VOLTAGE_PV3 = "voltagePV3";
|
||||
|
||||
public static final String CHANNEL_POWER = "power";
|
||||
public static final String CHANNEL_POWER_AC1 = "powerAC1";
|
||||
public static final String CHANNEL_POWER_AC2 = "powerAC2";
|
||||
public static final String CHANNEL_POWER_AC3 = "powerAC3";
|
||||
|
||||
public static final String CHANNEL_ENERGY_TODAY = "energyToday";
|
||||
|
||||
|
||||
@@ -30,11 +30,153 @@ public class OmnikInverterMessage {
|
||||
this.bytes = b;
|
||||
}
|
||||
|
||||
public double getPower() {
|
||||
private double getShort(int offset, int compensationFactor) {
|
||||
ByteBuffer buf = ByteBuffer.allocate(2);
|
||||
buf.put(bytes, 59, 2);
|
||||
buf.put(bytes, offset, 2);
|
||||
buf.rewind();
|
||||
return buf.getShort();
|
||||
return (double) buf.getShort() / compensationFactor;
|
||||
}
|
||||
|
||||
private double getInt(int offset, int compensationFactor) {
|
||||
ByteBuffer buf = ByteBuffer.allocate(4);
|
||||
buf.put(bytes, offset, 4);
|
||||
buf.rewind();
|
||||
return (double) buf.getInt() / compensationFactor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the voltage for PV1
|
||||
*/
|
||||
public double getVoltagePV1() {
|
||||
return getShort(33, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the voltage for PV2
|
||||
*/
|
||||
public double getVoltagePV2() {
|
||||
return getShort(35, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the voltage for PV3
|
||||
*/
|
||||
public double getVoltagePV3() {
|
||||
return getShort(37, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the amperage for PV1
|
||||
*/
|
||||
public double getCurrentPV1() {
|
||||
return getShort(39, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the amperage for PV2
|
||||
*/
|
||||
public double getCurrentPV2() {
|
||||
return getShort(41, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the amperage for PV3
|
||||
*/
|
||||
public double getCurrentPV3() {
|
||||
return getShort(43, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the amperage for AC1
|
||||
*/
|
||||
public double getAmperageAC1() {
|
||||
return getShort(45, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the amperage for AC2
|
||||
*/
|
||||
public double getAmperageAC2() {
|
||||
return getShort(47, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the amperage for AC3
|
||||
*/
|
||||
public double getAmperageAC3() {
|
||||
return getShort(49, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the voltage for AC1
|
||||
*/
|
||||
public double getVoltageAC1() {
|
||||
return getShort(51, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the voltage for AC2
|
||||
*/
|
||||
public double getVoltageAC2() {
|
||||
return getShort(53, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the voltage for AC3
|
||||
*/
|
||||
public double getVoltageAC3() {
|
||||
return getShort(55, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Frequency for AC1
|
||||
*/
|
||||
public double getFrequencyAC1() {
|
||||
return getShort(57, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the power for AC1
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public double getPower() {
|
||||
return getShort(59, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the power for AC1
|
||||
*/
|
||||
public double getPowerAC1() {
|
||||
return getShort(59, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Frequency for AC2
|
||||
*/
|
||||
public double getFrequencyAC2() {
|
||||
return getShort(61, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the power for AC2
|
||||
*/
|
||||
public double getPowerAC2() {
|
||||
return getShort(63, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Frequency for AC3
|
||||
*/
|
||||
public double getFrequencyAC3() {
|
||||
return getShort(65, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the power for AC3
|
||||
*/
|
||||
public double getPowerAC3() {
|
||||
return getShort(67, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,10 +184,7 @@ public class OmnikInverterMessage {
|
||||
* @return the total energy outputted this day in kWh
|
||||
*/
|
||||
public double getEnergyToday() {
|
||||
ByteBuffer buf = ByteBuffer.allocate(2);
|
||||
buf.put(bytes, 69, 2);
|
||||
buf.rewind();
|
||||
return (buf.getShort() / 100.0);
|
||||
return getShort(69, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,9 +192,6 @@ public class OmnikInverterMessage {
|
||||
* @return the total energy outputted in kWh
|
||||
*/
|
||||
public double getTotalEnergy() {
|
||||
ByteBuffer buf = ByteBuffer.allocate(4);
|
||||
buf.put(bytes, 71, 4);
|
||||
buf.rewind();
|
||||
return buf.getInt() / 10.0;
|
||||
return getInt(71, 10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ import java.net.UnknownHostException;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.measure.quantity.ElectricCurrent;
|
||||
import javax.measure.quantity.ElectricPotential;
|
||||
import javax.measure.quantity.Power;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@@ -58,10 +60,9 @@ public class OmnikInverterHandler extends BaseThingHandler {
|
||||
|
||||
@Override
|
||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||
if (OmnikInverterBindingConstants.CHANNEL_POWER.equals(channelUID.getId())) {
|
||||
if (command instanceof RefreshType) {
|
||||
updateData();
|
||||
}
|
||||
// All channels depend on data gotten from `updateData()`
|
||||
if (command instanceof RefreshType) {
|
||||
updateData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +95,33 @@ public class OmnikInverterHandler extends BaseThingHandler {
|
||||
QuantityType<Power> powerQuantity = new QuantityType<>(message.getPower(), Units.WATT);
|
||||
updateState(OmnikInverterBindingConstants.CHANNEL_POWER, powerQuantity);
|
||||
|
||||
QuantityType<Power> powerQuantity1 = new QuantityType<>(message.getPowerAC1(), Units.WATT);
|
||||
updateState(OmnikInverterBindingConstants.CHANNEL_POWER_AC1, powerQuantity1);
|
||||
|
||||
QuantityType<Power> powerQuantity2 = new QuantityType<>(message.getPowerAC2(), Units.WATT);
|
||||
updateState(OmnikInverterBindingConstants.CHANNEL_POWER_AC2, powerQuantity2);
|
||||
|
||||
QuantityType<Power> powerQuantity3 = new QuantityType<>(message.getPowerAC3(), Units.WATT);
|
||||
updateState(OmnikInverterBindingConstants.CHANNEL_POWER_AC3, powerQuantity3);
|
||||
|
||||
QuantityType<ElectricCurrent> pvAmp1 = new QuantityType<>(message.getCurrentPV1(), Units.AMPERE);
|
||||
updateState(OmnikInverterBindingConstants.CHANNEL_CURRENT_PV1, pvAmp1);
|
||||
|
||||
QuantityType<ElectricCurrent> pvAmp2 = new QuantityType<>(message.getCurrentPV2(), Units.AMPERE);
|
||||
updateState(OmnikInverterBindingConstants.CHANNEL_CURRENT_PV2, pvAmp2);
|
||||
|
||||
QuantityType<ElectricCurrent> pvAmp3 = new QuantityType<>(message.getCurrentPV3(), Units.AMPERE);
|
||||
updateState(OmnikInverterBindingConstants.CHANNEL_CURRENT_PV3, pvAmp3);
|
||||
|
||||
QuantityType<ElectricPotential> pvVoltage1 = new QuantityType<>(message.getVoltagePV1(), Units.VOLT);
|
||||
updateState(OmnikInverterBindingConstants.CHANNEL_VOLTAGE_PV1, pvVoltage1);
|
||||
|
||||
QuantityType<ElectricPotential> pvVoltage2 = new QuantityType<>(message.getVoltagePV2(), Units.VOLT);
|
||||
updateState(OmnikInverterBindingConstants.CHANNEL_VOLTAGE_PV2, pvVoltage2);
|
||||
|
||||
QuantityType<ElectricPotential> pvVoltage3 = new QuantityType<>(message.getVoltagePV3(), Units.VOLT);
|
||||
updateState(OmnikInverterBindingConstants.CHANNEL_VOLTAGE_PV3, pvVoltage3);
|
||||
|
||||
updateState(OmnikInverterBindingConstants.CHANNEL_ENERGY_TODAY,
|
||||
new QuantityType<>(message.getEnergyToday(), Units.KILOWATT_HOUR));
|
||||
|
||||
|
||||
@@ -10,6 +10,15 @@
|
||||
|
||||
<channels>
|
||||
<channel id="power" typeId="power"/>
|
||||
<channel id="powerAC1" typeId="powerAC1"/>
|
||||
<channel id="powerAC2" typeId="powerAC2"/>
|
||||
<channel id="powerAC3" typeId="powerAC3"/>
|
||||
<channel id="currentPV1" typeId="currentPV1"/>
|
||||
<channel id="currentPV2" typeId="currentPV2"/>
|
||||
<channel id="currentPV3" typeId="currentPV3"/>
|
||||
<channel id="voltagePV1" typeId="voltagePV1"/>
|
||||
<channel id="voltagePV2" typeId="voltagePV2"/>
|
||||
<channel id="voltagePV3" typeId="voltagePV3"/>
|
||||
<channel id="energyToday" typeId="energyToday"/>
|
||||
<channel id="energyTotal" typeId="energyTotal"/>
|
||||
</channels>
|
||||
@@ -36,7 +45,61 @@
|
||||
<channel-type id="power">
|
||||
<item-type>Number:Power</item-type>
|
||||
<label>Instantaneous Power</label>
|
||||
<description>The instantaneous power generation</description>
|
||||
<description>The instantaneous power generation for output 1</description>
|
||||
<state readOnly="true" pattern="%.1f %unit%"/>
|
||||
</channel-type>
|
||||
<channel-type id="powerAC1">
|
||||
<item-type>Number:Power</item-type>
|
||||
<label>Instantaneous Power AC1</label>
|
||||
<description>The instantaneous power generation for output 1</description>
|
||||
<state readOnly="true" pattern="%.1f %unit%"/>
|
||||
</channel-type>
|
||||
<channel-type id="powerAC2">
|
||||
<item-type>Number:Power</item-type>
|
||||
<label>Instantaneous Power AC2</label>
|
||||
<description>The instantaneous power generation for output 2</description>
|
||||
<state readOnly="true" pattern="%.1f %unit%"/>
|
||||
</channel-type>
|
||||
<channel-type id="powerAC3">
|
||||
<item-type>Number:Power</item-type>
|
||||
<label>Instantaneous Power AC3</label>
|
||||
<description>The instantaneous power generation for output 3</description>
|
||||
<state readOnly="true" pattern="%.1f %unit%"/>
|
||||
</channel-type>
|
||||
<channel-type id="currentPV1">
|
||||
<item-type>Number:Current</item-type>
|
||||
<label>Current PV1</label>
|
||||
<description>The current on input string 1</description>
|
||||
<state readOnly="true" pattern="%.1f %unit%"/>
|
||||
</channel-type>
|
||||
<channel-type id="currentPV2">
|
||||
<item-type>Number:Current</item-type>
|
||||
<label>Current PV2</label>
|
||||
<description>The current on input string 2</description>
|
||||
<state readOnly="true" pattern="%.1f %unit%"/>
|
||||
</channel-type>
|
||||
<channel-type id="currentPV3">
|
||||
<item-type>Number:Current</item-type>
|
||||
<label>Current PV3</label>
|
||||
<description>The current on input string 3</description>
|
||||
<state readOnly="true" pattern="%.1f %unit%"/>
|
||||
</channel-type>
|
||||
<channel-type id="voltagePV1">
|
||||
<item-type>Number:Voltage</item-type>
|
||||
<label>Voltage PV1</label>
|
||||
<description>The voltage on input string 1</description>
|
||||
<state readOnly="true" pattern="%.1f %unit%"/>
|
||||
</channel-type>
|
||||
<channel-type id="voltagePV2">
|
||||
<item-type>Number:Voltage</item-type>
|
||||
<label>Voltage PV2</label>
|
||||
<description>The voltage on input string 2</description>
|
||||
<state readOnly="true" pattern="%.1f %unit%"/>
|
||||
</channel-type>
|
||||
<channel-type id="voltagePV3">
|
||||
<item-type>Number:Voltage</item-type>
|
||||
<label>The voltage on input string 3</label>
|
||||
<description>The voltage PV3</description>
|
||||
<state readOnly="true" pattern="%.1f %unit%"/>
|
||||
</channel-type>
|
||||
<channel-type id="energyToday">
|
||||
|
||||
@@ -40,6 +40,51 @@ public class OmnikInverterMessageTest {
|
||||
assertEquals(137.0, message.getPower(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPowerAC1() {
|
||||
assertEquals(137.0, message.getPowerAC1(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPowerAC2() {
|
||||
assertEquals(-1.0, message.getPowerAC2(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPowerAC3() {
|
||||
assertEquals(-1.0, message.getPowerAC3(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCurrentPV1() {
|
||||
assertEquals(0.5, message.getCurrentPV1(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCurrentPV2() {
|
||||
assertEquals(0.6, message.getCurrentPV2(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCurrentPV3() {
|
||||
assertEquals(-0.1, message.getCurrentPV3(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVoltagePV1() {
|
||||
assertEquals(160.0, message.getVoltagePV1(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVoltagePV2() {
|
||||
assertEquals(131.9, message.getVoltagePV2(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVoltagePV3() {
|
||||
assertEquals(-0.1, message.getVoltagePV3(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTotalEnergy() {
|
||||
assertEquals(12412.7, message.getTotalEnergy(), 0.01);
|
||||
|
||||
Reference in New Issue
Block a user