Skip to content

Commit

Permalink
[modbus][sunspec] Fixed type and scale errors on acc32 fields (openha…
Browse files Browse the repository at this point in the history
…b#7826)

* [modbus][sunspec] Fixed type and scale errors on acc32 fields

ACC32 fields were mistakenly parsed as unsigned int instead of signed
default scale value is 10^0=1 now
scaling was missing for 10^1 fields

* [modbus][sunspec] Changed CODEOWNERS order

Seems like mrbig is not recognized as codeowner by github. Trying
to fix the alphabetic order to see if this helps

Signed-off-by: Nagy Attila Gabor <mrbig@sneaker.hu>
Signed-off-by: Daan Meijer <daan@studioseptember.nl>
  • Loading branch information
mrbig authored and DaanMeijer committed Sep 1, 2020
1 parent 0d38cc3 commit 3fb846d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
/bundles/org.openhab.binding.milight/ @davidgraeff
/bundles/org.openhab.binding.minecraft/ @ibaton
/bundles/org.openhab.binding.modbus/ @ssalonen
/bundles/org.openhab.binding.modbus.sunspec/ @mrbig
/bundles/org.openhab.binding.mqtt/ @davidgraeff
/bundles/org.openhab.binding.mqtt.generic/ @davidgraeff
/bundles/org.openhab.binding.mqtt.homeassistant/ @davidgraeff
Expand Down Expand Up @@ -192,7 +193,6 @@
/bundles/org.openhab.binding.sonyprojector/ @lolodomo
/bundles/org.openhab.binding.spotify/ @Hilbrand
/bundles/org.openhab.binding.squeezebox/ @digitaldan @mhilbush
/bundles/org.openhab.binding.modbus.sunspec/ @mrbig
/bundles/org.openhab.binding.synopanalyzer/ @clinique
/bundles/org.openhab.binding.systeminfo/ @svilenvul
/bundles/org.openhab.binding.tado/ @dfrommi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ protected State getScaled(Optional<? extends Number> value, Short scaleFactor, U
* @return the scaled value as a DecimalType
*/
protected State getScaled(Number value, Short scaleFactor, Unit<?> unit) {
if (scaleFactor == 1) {
if (scaleFactor == 0) {
return new QuantityType<>(value.longValue(), unit);
}
return new QuantityType<>(BigDecimal.valueOf(value.longValue(), scaleFactor * -1), unit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected Integer extractUInt16(ModbusRegisterArray raw, int index, int def) {
* @return the parsed value or empty if the field is not implemented
*/
protected Optional<Long> extractOptionalAcc32(ModbusRegisterArray raw, int index) {
return ModbusBitUtilities.extractStateFromRegisters(raw, index, ValueType.UINT32).map(DecimalType::longValue)
return ModbusBitUtilities.extractStateFromRegisters(raw, index, ValueType.INT32).map(DecimalType::longValue)
.filter(value -> value != 0);
}

Expand Down Expand Up @@ -121,6 +121,6 @@ protected Optional<Short> extractOptionalSunSSF(ModbusRegisterArray raw, int ind
* @return the parsed value or 1 if the field is not implemented
*/
protected Short extractSunSSF(ModbusRegisterArray raw, int index) {
return extractOptionalSunSSF(raw, index).orElse((short) 1);
return extractOptionalSunSSF(raw, index).orElse((short) 0);
}
}

0 comments on commit 3fb846d

Please sign in to comment.