diff --git a/vallox.go b/vallox.go index aac1e0f..451deea 100644 --- a/vallox.go +++ b/vallox.go @@ -220,6 +220,10 @@ func valueToSpeed(value byte) int8 { return -1 } +func speedToValue(speed int8) byte { + return fanSpeedConversion[speed-1] +} + func valueToTemp(value byte) int8 { return tempConversion[value] } diff --git a/vallox_test.go b/vallox_test.go new file mode 100644 index 0000000..423f3f5 --- /dev/null +++ b/vallox_test.go @@ -0,0 +1,39 @@ +package valloxrs485 + +import ( + "testing" +) + +func TestValueToTemp(t *testing.T) { + assertTemp(0, -74, t) + assertTemp(255, 100, t) + assertTemp(246, 97, t) + assertTemp(247, 100, t) +} + +func TestValueToSpeed(t *testing.T) { + assertSpeed(1, 1, t) + assertSpeed(3, 2, t) + assertSpeed(7, 3, t) + assertSpeed(15, 4, t) + assertSpeed(31, 5, t) + assertSpeed(63, 6, t) + assertSpeed(127, 7, t) + assertSpeed(255, 8, t) +} + +func assertTemp(raw byte, value int8, t *testing.T) { + if c := valueToTemp(raw); c != value { + t.Errorf("temp %d was not converted to %d but to %d", raw, value, c) + } +} + +func assertSpeed(raw byte, value int8, t *testing.T) { + if c := valueToSpeed(raw); c != value { + t.Errorf("raw %d to speed was not converted to %d but to %d", raw, value, c) + } + + if c := speedToValue(value); c != raw { + t.Errorf("speed %d to raw was not converted to %d but to %d", value, raw, c) + } +}