Files
OpsLog/relaycount_test.go
T
rouggy 5c958572dc fix(relays): let the HTTP board's channel count be chosen
The selector offered 1, 2, 4, 8 and 16 and none of them took: the board stayed
at four relays.

The count is decided in three places — deviceRelayCount in Go, chanCount in the
Station Control panel, relayCountUI in Settings. The new type was added to the
first and the dropdown, and to neither of the others, so the panel resized the
labels from a helper that had never heard of it and fell straight through to
its fixed default. The Go side was right the whole time, which is why the
driver would have been built correctly for a count the operator could not set.

All three now know the type. A test pins the Go side against every count the
dropdown offers, and against the fixed boards, whose hardware decides and which
must keep ignoring the field.
2026-08-15 02:35:14 +02:00

31 lines
1.2 KiB
Go

package main
import "testing"
// The relay count is decided in Go and mirrored in the panel. When the HTTP
// board was added to one and not the other, an operator could pick 8 channels
// and still get 4 rows — the selector "did nothing".
//
// This pins the Go side, which is the one the driver is built from.
func TestDeviceRelayCountHonoursTheChosenChannels(t *testing.T) {
for _, typ := range []string{"httpgen", "usbrelay", "denkovi", "dingtian"} {
for _, n := range []int{1, 2, 4, 8, 16} {
if got := deviceRelayCount(StationDevice{Type: typ, Channels: n}); got != n {
t.Errorf("%s with %d channels → %d", typ, n, got)
}
}
}
// Fixed-size boards ignore it: their hardware decides.
for typ, want := range map[string]int{"webswitch": 5, "kmtronic": 8} {
if got := deviceRelayCount(StationDevice{Type: typ, Channels: 3}); got != want {
t.Errorf("%s → %d, want its fixed %d", typ, got, want)
}
}
// Unset falls back to something sensible per type, not to another's default.
for typ, want := range map[string]int{"httpgen": 4, "dingtian": 2, "usbrelay": 8, "denkovi": 8} {
if got := deviceRelayCount(StationDevice{Type: typ}); got != want {
t.Errorf("%s with no choice → %d, want %d", typ, got, want)
}
}
}