Skip to content

Commit

Permalink
Fix NPE when linked device doesn't have the expected value parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
pdegeus committed Oct 10, 2016
1 parent e277295 commit 77a8709
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ public void updateParams() {
LOGGER.error("Couldn't resolve linked energy device '{}', make sure the Item has iss tags", deviceName);
} else {
NumericValueParam valueParam = (NumericValueParam) energyDevice.getParams().get(ParamType.WATTS);

NumericValueParam energyParam = new NumericValueParam(ParamType.ENERGY, valueParam.getUnit(), null);
energyParam.setValue(valueParam.getValue());
addParam(energyParam);
if (valueParam == null) {
LOGGER.warn("Linked energy device has no Watts value parameter: {}", energyDevice);
} else {
NumericValueParam energyParam = new NumericValueParam(ParamType.ENERGY, valueParam.getUnit(), null);
energyParam.setValue(valueParam.getValue());
addParam(energyParam);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public void updateParams() {
AbstractDevice wattsDevice = getDeviceRegistry().getDevice(deviceId);
if (wattsDevice == null) {
LOGGER.error("Couldn't resolve linked watts device '{}', make sure the Item has iss tags", deviceName);
} else {
setWattsParam(wattsDevice);
}

setWattsParam(wattsDevice);
}

if (getLinks().containsKey(LINK_KWH)) {
Expand All @@ -70,15 +70,18 @@ public void updateParams() {
AbstractDevice kwhDevice = getDeviceRegistry().getDevice(deviceId);
if (kwhDevice == null) {
LOGGER.error("Couldn't resolve linked KWh device '{}', make sure the Item has iss tags", deviceName);

} else {
setKwhParam(kwhDevice);
}

setKwhParam(kwhDevice);
}
}

private void setWattsParam(AbstractDevice device) {
NumericValueParam valueParam = (NumericValueParam) device.getParams().get(ParamType.WATTS);
if (valueParam == null) {
LOGGER.warn("Linked Watts device has no Watt value parameter: {}", device);
return;
}

NumericValueParam wattsParam = new NumericValueParam(ParamType.WATTS, valueParam.getUnit(), null);
if (StringUtils.isEmpty(wattsParam.getUnit())) {
Expand All @@ -90,6 +93,10 @@ private void setWattsParam(AbstractDevice device) {

private void setKwhParam(AbstractDevice device) {
NumericValueParam valueParam = (NumericValueParam) device.getParams().get(ParamType.KWH);
if (valueParam == null) {
LOGGER.warn("Linked KWh device has no KWh value parameter: {}", device);
return;
}

NumericValueParam kwhParam = new NumericValueParam(ParamType.KWH, valueParam.getUnit(), null);
if (StringUtils.isEmpty(kwhParam.getUnit())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public void updateParams() {
}

NumericValueParam valueParam = (NumericValueParam) accumDevice.getParams().get(ParamType.GENERIC_VALUE);
if (valueParam == null) {
LOGGER.warn("Linked Accumulation device has no Value parameter: {}", accumDevice);
return;
}

NumericValueParam accumParam = new NumericValueParam(ParamType.ACCUMULATION, valueParam.getUnit(), null);
if (StringUtils.isEmpty(accumParam.getUnit())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ public void updateParams() {
if (hygroDevice == null) {
LOGGER.error("Couldn't resolve linked hygro device '{}', make sure the Item has iss tags", deviceName);
} else {
setHygroParam(hygroDevice);
foundLink = true;
}

setHygroParam(hygroDevice);
}

if (getLinks().containsKey(LINK_TEMP)) {
Expand All @@ -75,11 +74,9 @@ public void updateParams() {
if (tempDevice == null) {
LOGGER.error("Couldn't resolve linked temp device '{}', make sure the Item has iss tags", deviceName);
} else {
setTempParam(tempDevice);
foundLink = true;

}

setTempParam(tempDevice);
}

if (!foundLink) {
Expand All @@ -89,6 +86,10 @@ public void updateParams() {

private void setHygroParam(AbstractDevice device) {
NumericValueParam valueParam = (NumericValueParam) device.getParams().get(ParamType.HYGROMETRY_VALUE);
if (valueParam == null) {
LOGGER.warn("Linked Hygro device has no Value parameter: {}", device);
return;
}

NumericValueParam hygroParam = new NumericValueParam(ParamType.HYGROMETRY_DUAL, valueParam.getUnit(), null);
hygroParam.setValue(valueParam.getValue());
Expand All @@ -97,6 +98,10 @@ private void setHygroParam(AbstractDevice device) {

private void setTempParam(AbstractDevice device) {
NumericValueParam valueParam = (NumericValueParam) device.getParams().get(ParamType.TEMPERATURE_VALUE);
if (valueParam == null) {
LOGGER.warn("Linked Temperature device has no Value parameter: {}", device);
return;
}

NumericValueParam tempParam = new NumericValueParam(ParamType.TEMPERATURE_DUAL, valueParam.getUnit(), null);
tempParam.setValue(valueParam.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public void updateParams() {
}

NumericValueParam valueParam = (NumericValueParam) dirDevice.getParams().get(ParamType.GENERIC_VALUE);
if (valueParam == null) {
LOGGER.warn("Linked Wind direction device has no Value parameter: {}", dirDevice);
return;
}

NumericValueParam dirParam = new NumericValueParam(ParamType.DIRECTION, valueParam.getUnit(), null);
if (StringUtils.isEmpty(dirParam.getUnit())) {
Expand Down

0 comments on commit 77a8709

Please sign in to comment.