Skip to content

Commit

Permalink
Ensured consistency of namings across the files changed (openhab#1230)
Browse files Browse the repository at this point in the history
changed energy_usage and energyusage to energy for consistency - device
type is therefore energy not energyusage

Modified some calculations to ensure correct output of values.

Signed-off-by: Mike McCaffery <mike@mccaffery.co.uk> (github: mccaffm)
  • Loading branch information
mccaffm authored and kaikreuzer committed Sep 23, 2016
1 parent e956643 commit 79e9245
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@
<item-type>Number</item-type>
<label>Instant Amp</label>
<description>Instant current in Amperes</description>
<state pattern="%d A" readOnly="true"></state>
<state pattern="%.2f A" readOnly="true"></state>
</channel-type>

<channel-type id="totalamphours" advanced="true">
<channel-type id="totalamphour" advanced="true">
<item-type>Number</item-type>
<label>Total Ampere-hours</label>
<description>Used "energy" in ampere-hours</description>
<state pattern="%d Ah" readOnly="true"></state>
<state pattern="%.2f Ah" readOnly="true"></state>
</channel-type>

<channel-type id="temperature">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
<description>A Energy device.</description>

<channels>
<channel id="command" typeId="command" />
<channel id="instanPower" typeId="instantpower" />
<channel id="instantPower" typeId="instantpower" />
<channel id="totalUsage" typeId="totalusage" />
<channel id="instantAmp" typeId="instantamp" />
<channel id="totalAmpHours" typeId="totalamphours" />
<channel id="totalAmpHour" typeId="totalamphour" />
<channel id="signalLevel" typeId="system.signal-strength" />
<channel id="batteryLevel" typeId="system.battery-level" />
<channel id="lowBattery" typeId="system.low-battery" />
Expand Down
2 changes: 1 addition & 1 deletion addons/binding/org.openhab.binding.rfxcom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ This binding currently supports following channels:
| signallevel | Number | Received signal strength level. |
| temperature | Number | Current temperature in degree Celsius. |
| totalusage | Number | Used energy in Watt hours. |
| totalamphours | Number | Used "energy" in ampere-hours. |
| totalamphour | Number | Used "energy" in ampere-hours. |
| winddirection | Number | Wind direction in degrees. |
| windspeed | Number | Average wind speed in meters per second. |
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public class RFXComBindingConstants {
public final static String CHANNEL_CHILL_FACTOR = "chillFactor";
public final static String CHANNEL_INSTANT_POWER = "instantPower";
public final static String CHANNEL_TOTAL_USAGE = "totalUsage";
public final static String CHANNEL_INSTANT_AMPS = "instantAmps";
public final static String CHANNEL_TOTAL_AMP_HOURS = "totalAmpHours";
public final static String CHANNEL_INSTANT_AMPS = "instantAmp";
public final static String CHANNEL_TOTAL_AMP_HOUR = "totalAmpHour";
public final static String CHANNEL_STATUS = "status";
public final static String CHANNEL_MOTION = "motion";
public final static String CHANNEL_CONTACT = "contact";
Expand Down Expand Up @@ -123,7 +123,7 @@ public class RFXComBindingConstants {
public final static ThingTypeUID THING_TYPE_UV = new ThingTypeUID(BINDING_ID, "uv");
public final static ThingTypeUID THING_TYPE_DATE_TIME = new ThingTypeUID(BINDING_ID, "datetime");
public final static ThingTypeUID THING_TYPE_CURRENT = new ThingTypeUID(BINDING_ID, "current");
public final static ThingTypeUID THING_TYPE_ENERGY_USAGE = new ThingTypeUID(BINDING_ID, "energyusage");
public final static ThingTypeUID THING_TYPE_ENERGY = new ThingTypeUID(BINDING_ID, "energy");
public final static ThingTypeUID THING_TYPE_CURRENT_ENERGY = new ThingTypeUID(BINDING_ID, "currentenergy");
public final static ThingTypeUID THING_TYPE_POWER = new ThingTypeUID(BINDING_ID, "power");
public final static ThingTypeUID THING_TYPE_WEIGHTING_SCALE = new ThingTypeUID(BINDING_ID, "weightingscale");
Expand All @@ -144,9 +144,9 @@ public class RFXComBindingConstants {
THING_TYPE_THERMOSTAT2, THING_TYPE_THERMOSTAT3, THING_TYPE_BBQ_TEMPERATURE, THING_TYPE_TEMPERATURE_RAIN,
THING_TYPE_TEMPERATURE, THING_TYPE_HUMIDITY, THING_TYPE_TEMPERATURE_HUMIDITY, THING_TYPE_BAROMETRIC,
THING_TYPE_TEMPERATURE_HUMIDITY_BAROMETRIC, THING_TYPE_RAIN, THING_TYPE_WIND, THING_TYPE_UV,
THING_TYPE_DATE_TIME, THING_TYPE_CURRENT, THING_TYPE_ENERGY_USAGE, THING_TYPE_CURRENT_ENERGY,
THING_TYPE_POWER, THING_TYPE_WEIGHTING_SCALE, THING_TYPE_GAS_USAGE, THING_TYPE_WATER_USAGE,
THING_TYPE_RFX_SENSOR, THING_TYPE_RFX_METER, THING_TYPE_FS20, THING_TYPE_RFY);
THING_TYPE_DATE_TIME, THING_TYPE_CURRENT, THING_TYPE_ENERGY, THING_TYPE_CURRENT_ENERGY, THING_TYPE_POWER,
THING_TYPE_WEIGHTING_SCALE, THING_TYPE_GAS_USAGE, THING_TYPE_WATER_USAGE, THING_TYPE_RFX_SENSOR,
THING_TYPE_RFX_METER, THING_TYPE_FS20, THING_TYPE_RFY);

/**
* Map RFXCOM packet types to RFXCOM Thing types and vice versa.
Expand All @@ -162,7 +162,7 @@ public class RFXComBindingConstants {
.put(PacketType.CURRENT_ENERGY, RFXComBindingConstants.THING_TYPE_CURRENT_ENERGY)
.put(PacketType.CURTAIN1, RFXComBindingConstants.THING_TYPE_CURTAIN1)
.put(PacketType.DATE_TIME, RFXComBindingConstants.THING_TYPE_DATE_TIME)
.put(PacketType.ENERGY, RFXComBindingConstants.THING_TYPE_ENERGY_USAGE)
.put(PacketType.ENERGY, RFXComBindingConstants.THING_TYPE_ENERGY)
.put(PacketType.FAN, RFXComBindingConstants.THING_TYPE_FAN)
.put(PacketType.FS20, RFXComBindingConstants.THING_TYPE_FS20)
.put(PacketType.GAS, RFXComBindingConstants.THING_TYPE_GAS_USAGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public enum RFXComValueSelector {
INSTANT_POWER(RFXComBindingConstants.CHANNEL_INSTANT_POWER, NumberItem.class),
TOTAL_USAGE(RFXComBindingConstants.CHANNEL_TOTAL_USAGE, NumberItem.class),
INSTANT_AMPS(RFXComBindingConstants.CHANNEL_INSTANT_AMPS, NumberItem.class),
TOTAL_AMP_HOURS(RFXComBindingConstants.CHANNEL_TOTAL_AMP_HOURS, NumberItem.class),
TOTAL_AMP_HOUR(RFXComBindingConstants.CHANNEL_TOTAL_AMP_HOUR, NumberItem.class),
STATUS(RFXComBindingConstants.CHANNEL_STATUS, StringItem.class),
MOTION(RFXComBindingConstants.CHANNEL_MOTION, SwitchItem.class),
CONTACT(RFXComBindingConstants.CHANNEL_CONTACT, ContactItem.class),
Expand All @@ -73,7 +73,7 @@ public Class<? extends Item> getItemClass() {

/**
* Procedure to validate selector string.
*
*
* @param valueSelector
* selector string e.g. Command, Temperature
* @return true if item is valid.
Expand Down Expand Up @@ -102,7 +102,7 @@ public static boolean validateBinding(String valueSelector, Class<? extends Item

/**
* Procedure to convert selector string to value selector class.
*
*
* @param valueSelectorText
* selector string e.g. RawData, Command, Temperature
* @return corresponding selector value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ public void onDeviceMessageReceived(ThingUID bridge, RFXComMessage message) {
case TEMPERATURE:
updateState(CHANNEL_TEMPERATURE, message.convertToState(valueSelector));
break;
case TOTAL_AMP_HOURS:
updateState(CHANNEL_TOTAL_AMP_HOURS, message.convertToState(valueSelector));
case TOTAL_AMP_HOUR:
updateState(CHANNEL_TOTAL_AMP_HOUR, message.convertToState(valueSelector));
break;
case TOTAL_USAGE:
updateState(CHANNEL_TOTAL_USAGE, message.convertToState(valueSelector));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,16 @@ public byte toByte() {
}

private final static List<RFXComValueSelector> supportedInputValueSelectors = Arrays.asList(
RFXComValueSelector.SIGNAL_LEVEL, RFXComValueSelector.BATTERY_LEVEL, RFXComValueSelector.COMMAND,
RFXComValueSelector.INSTANT_POWER, RFXComValueSelector.TOTAL_USAGE, RFXComValueSelector.INSTANT_AMPS,
RFXComValueSelector.TOTAL_AMP_HOURS);
RFXComValueSelector.SIGNAL_LEVEL, RFXComValueSelector.BATTERY_LEVEL, RFXComValueSelector.INSTANT_POWER,
RFXComValueSelector.TOTAL_USAGE, RFXComValueSelector.INSTANT_AMPS, RFXComValueSelector.TOTAL_AMP_HOUR);

private final static List<RFXComValueSelector> supportedOutputValueSelectors = Arrays.asList();

public SubType subType = SubType.ELEC1;
public int sensorId = 0;
public byte count = 0;
public double instantAmps = 0;
public double totalAmpHours = 0;
public double instantAmp = 0;
public double totalAmpHour = 0;
public double instantPower = 0;
public double totalUsage = 0;
public byte signalLevel = 0;
Expand All @@ -85,10 +84,12 @@ public String toString() {
str += ", Sub type = " + subType;
str += ", Device Id = " + getDeviceId();
str += ", Count = " + count;
str += ", Instant Amps = " + instantAmps;
str += ", Total Amp Hours = " + totalAmpHours;
str += ", Instant Amps = " + instantAmp;
str += ", Total Amp Hours = " + totalAmpHour;
str += ", Signal level = " + signalLevel;
str += ", Battery level = " + batteryLevel;
str += ", Instant Power = " + instantPower;
str += ", Total Usage = " + totalUsage;

return str;
}
Expand All @@ -108,14 +109,15 @@ public void encodeMessage(byte[] data) {
count = data[6];

// all usage is reported in Watts based on 230V
instantPower = ((data[7] & 0xFF) << 24 | (data[8] & 0xFF) << 16 | (data[9] & 0xFF) << 8 | (data[10] & 0xFF))
/ TOTAL_USAGE_CONVERSION_FACTOR;
instantPower = ((data[7] & 0xFF) << 24 | (data[8] & 0xFF) << 16 | (data[9] & 0xFF) << 8 | (data[10] & 0xFF));

totalUsage = ((data[11] & 0xFF) << 40 | (data[12] & 0xFF) << 32 | (data[13] & 0xFF) << 24
| (data[14] & 0xFF) << 16 | (data[15] & 0xFF) << 8 | (data[16] & 0xFF));
| (data[14] & 0xFF) << 16 | (data[15] & 0xFF) << 8 | (data[16] & 0xFF)) / TOTAL_USAGE_CONVERSION_FACTOR;
;

// convert to amps so external code can determine the watts based on local voltage
instantAmps = instantPower / WATTS_TO_AMPS_CONVERSION_FACTOR;
totalAmpHours = totalUsage / WATTS_TO_AMPS_CONVERSION_FACTOR;
instantAmp = instantPower / WATTS_TO_AMPS_CONVERSION_FACTOR;
totalAmpHour = totalUsage / WATTS_TO_AMPS_CONVERSION_FACTOR;

signalLevel = (byte) ((data[17] & 0xF0) >> 4);
batteryLevel = (byte) (data[17] & 0x0F);
Expand Down Expand Up @@ -184,11 +186,11 @@ public State convertToState(RFXComValueSelector valueSelector) throws RFXComExce

} else if (valueSelector == RFXComValueSelector.INSTANT_AMPS) {

state = new DecimalType(instantAmps);
state = new DecimalType(instantAmp);

} else if (valueSelector == RFXComValueSelector.TOTAL_AMP_HOURS) {
} else if (valueSelector == RFXComValueSelector.TOTAL_AMP_HOUR) {

state = new DecimalType(totalAmpHours);
state = new DecimalType(totalAmpHour);

} else {

Expand Down

0 comments on commit 79e9245

Please sign in to comment.