From 516fa4b31da2f2a004e1c7f309c1e34803d18555 Mon Sep 17 00:00:00 2001 From: xegineering Date: Wed, 2 Oct 2024 18:46:50 +0200 Subject: Add soundbox.fromHardwareAddr() This splits the soundbox.NewSoundbox() function into two smaller functions. --- soundbox.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/soundbox.go b/soundbox.go index 389d1da..d6a0a34 100644 --- a/soundbox.go +++ b/soundbox.go @@ -18,12 +18,14 @@ func NewSoundbox(mac string) (Soundbox, error) { if err != nil { return Soundbox{}, err } - - if len(hardwareAddr) != 6 { + + return fromHardwareAddr(hardwareAddr) +} + +func fromHardwareAddr(addr net.HardwareAddr) (Soundbox, error) { + if len(addr) != 6 { return Soundbox{}, fmt.Errorf("Only IEEE 802 MAC-48 addresses supported") } - return Soundbox{ - HardwareAddr: hardwareAddr, - }, nil + return Soundbox{HardwareAddr: addr}, nil } -- cgit v1.2.3-70-g09d2