From a567d1ac9349c4b76c5182413919180bc16a8677 Mon Sep 17 00:00:00 2001 From: Peter Wood Date: Sat, 15 Jun 2024 13:07:14 +0100 Subject: [PATCH] Update converters to reflect change of error removal from Set. --- converter/converter.go | 4 ++-- converter/time.go | 8 ++++---- converter/time_test.go | 6 ++---- converter/zigbee.go | 28 ++++++++++++++-------------- converter/zigbee_test.go | 21 +++++++-------------- 5 files changed, 29 insertions(+), 38 deletions(-) diff --git a/converter/converter.go b/converter/converter.go index d703f5d..ea51254 100644 --- a/converter/converter.go +++ b/converter/converter.go @@ -2,8 +2,8 @@ package converter import "github.com/shimmeringbee/persistence" -func Store[T any](section persistence.Section, key string, val T, enc func(persistence.Section, string, T) error) error { - return enc(section, key, val) +func Store[T any](section persistence.Section, key string, val T, enc func(persistence.Section, string, T)) { + enc(section, key, val) } func Retrieve[T any](section persistence.Section, key string, dec func(persistence.Section, string) (T, bool), defValue ...T) (T, bool) { diff --git a/converter/time.go b/converter/time.go index c1c6abd..d614ab2 100644 --- a/converter/time.go +++ b/converter/time.go @@ -5,8 +5,8 @@ import ( "time" ) -func TimeEncoder(s persistence.Section, k string, v time.Time) error { - return s.Set(k, v.UnixMilli()) +func TimeEncoder(s persistence.Section, k string, v time.Time) { + s.Set(k, v.UnixMilli()) } func TimeDecoder(s persistence.Section, k string) (time.Time, bool) { @@ -17,8 +17,8 @@ func TimeDecoder(s persistence.Section, k string) (time.Time, bool) { } } -func DurationEncoder(s persistence.Section, k string, v time.Duration) error { - return s.Set(k, v.Milliseconds()) +func DurationEncoder(s persistence.Section, k string, v time.Duration) { + s.Set(k, v.Milliseconds()) } func DurationDecoder(s persistence.Section, k string) (time.Duration, bool) { diff --git a/converter/time_test.go b/converter/time_test.go index 661f690..e19d773 100644 --- a/converter/time_test.go +++ b/converter/time_test.go @@ -15,8 +15,7 @@ func TestTime(t *testing.T) { expected := time.UnixMilli(time.Now().UnixMilli()) - err := Store(s, Key, expected, TimeEncoder) - assert.NoError(t, err) + Store(s, Key, expected, TimeEncoder) actual, found := Retrieve(s, Key, TimeDecoder) assert.True(t, found) @@ -30,8 +29,7 @@ func TestDuration(t *testing.T) { expected := time.Duration(1234) * time.Millisecond - err := Store(s, Key, expected, DurationEncoder) - assert.NoError(t, err) + Store(s, Key, expected, DurationEncoder) actual, found := Retrieve(s, Key, DurationDecoder) assert.True(t, found) diff --git a/converter/zigbee.go b/converter/zigbee.go index 6bee4b7..2c127ef 100644 --- a/converter/zigbee.go +++ b/converter/zigbee.go @@ -7,8 +7,8 @@ import ( "strconv" ) -func AttributeIDEncoder(s persistence.Section, k string, v zcl.AttributeID) error { - return s.Set(k, int64(v)) +func AttributeIDEncoder(s persistence.Section, k string, v zcl.AttributeID) { + s.Set(k, int64(v)) } func AttributeIDDecoder(s persistence.Section, k string) (zcl.AttributeID, bool) { @@ -19,8 +19,8 @@ func AttributeIDDecoder(s persistence.Section, k string) (zcl.AttributeID, bool) } } -func AttributeDataTypeEncoder(s persistence.Section, k string, v zcl.AttributeDataType) error { - return s.Set(k, int64(v)) +func AttributeDataTypeEncoder(s persistence.Section, k string, v zcl.AttributeDataType) { + s.Set(k, int64(v)) } func AttributeDataTypeDecoder(s persistence.Section, k string) (zcl.AttributeDataType, bool) { @@ -31,8 +31,8 @@ func AttributeDataTypeDecoder(s persistence.Section, k string) (zcl.AttributeDat } } -func IEEEEncoder(s persistence.Section, k string, v zigbee.IEEEAddress) error { - return s.Set(k, v.String()) +func IEEEEncoder(s persistence.Section, k string, v zigbee.IEEEAddress) { + s.Set(k, v.String()) } func IEEEDecoder(s persistence.Section, k string) (zigbee.IEEEAddress, bool) { @@ -47,8 +47,8 @@ func IEEEDecoder(s persistence.Section, k string) (zigbee.IEEEAddress, bool) { } } -func NetworkAddressEncoder(s persistence.Section, k string, v zigbee.NetworkAddress) error { - return s.Set(k, int64(v)) +func NetworkAddressEncoder(s persistence.Section, k string, v zigbee.NetworkAddress) { + s.Set(k, int64(v)) } func NetworkAddressDecoder(s persistence.Section, k string) (zigbee.NetworkAddress, bool) { @@ -59,8 +59,8 @@ func NetworkAddressDecoder(s persistence.Section, k string) (zigbee.NetworkAddre } } -func LogicalTypeEncoder(s persistence.Section, k string, v zigbee.LogicalType) error { - return s.Set(k, int64(v)) +func LogicalTypeEncoder(s persistence.Section, k string, v zigbee.LogicalType) { + s.Set(k, int64(v)) } func LogicalTypeDecoder(s persistence.Section, k string) (zigbee.LogicalType, bool) { @@ -71,8 +71,8 @@ func LogicalTypeDecoder(s persistence.Section, k string) (zigbee.LogicalType, bo } } -func ClusterIDEncoder(s persistence.Section, k string, v zigbee.ClusterID) error { - return s.Set(k, int64(v)) +func ClusterIDEncoder(s persistence.Section, k string, v zigbee.ClusterID) { + s.Set(k, int64(v)) } func ClusterIDDecoder(s persistence.Section, k string) (zigbee.ClusterID, bool) { @@ -83,8 +83,8 @@ func ClusterIDDecoder(s persistence.Section, k string) (zigbee.ClusterID, bool) } } -func EndpointEncoder(s persistence.Section, k string, v zigbee.Endpoint) error { - return s.Set(k, int64(v)) +func EndpointEncoder(s persistence.Section, k string, v zigbee.Endpoint) { + s.Set(k, int64(v)) } func EndpointDecoder(s persistence.Section, k string) (zigbee.Endpoint, bool) { diff --git a/converter/zigbee_test.go b/converter/zigbee_test.go index d54d6f2..e4aa655 100644 --- a/converter/zigbee_test.go +++ b/converter/zigbee_test.go @@ -14,8 +14,7 @@ func TestClusterID(t *testing.T) { expected := zigbee.ClusterID(1) - err := Store(s, Key, expected, ClusterIDEncoder) - assert.NoError(t, err) + Store(s, Key, expected, ClusterIDEncoder) actual, found := Retrieve(s, Key, ClusterIDDecoder) assert.True(t, found) @@ -29,8 +28,7 @@ func TestEndpoint(t *testing.T) { expected := zigbee.Endpoint(1) - err := Store(s, Key, expected, EndpointEncoder) - assert.NoError(t, err) + Store(s, Key, expected, EndpointEncoder) actual, found := Retrieve(s, Key, EndpointDecoder) assert.True(t, found) @@ -44,8 +42,7 @@ func TestIEEEAddress(t *testing.T) { expected := zigbee.GenerateLocalAdministeredIEEEAddress() - err := Store(s, Key, expected, IEEEEncoder) - assert.NoError(t, err) + Store(s, Key, expected, IEEEEncoder) actual, found := Retrieve(s, Key, IEEEDecoder) assert.True(t, found) @@ -59,8 +56,7 @@ func TestNetworkAddress(t *testing.T) { expected := zigbee.NetworkAddress(0x1122) - err := Store(s, Key, expected, NetworkAddressEncoder) - assert.NoError(t, err) + Store(s, Key, expected, NetworkAddressEncoder) actual, found := Retrieve(s, Key, NetworkAddressDecoder) assert.True(t, found) @@ -74,8 +70,7 @@ func TestLogicalType(t *testing.T) { expected := zigbee.Router - err := Store(s, Key, expected, LogicalTypeEncoder) - assert.NoError(t, err) + Store(s, Key, expected, LogicalTypeEncoder) actual, found := Retrieve(s, Key, LogicalTypeDecoder) assert.True(t, found) @@ -89,8 +84,7 @@ func TestAttributeID(t *testing.T) { expected := zcl.AttributeID(1) - err := Store(s, Key, expected, AttributeIDEncoder) - assert.NoError(t, err) + Store(s, Key, expected, AttributeIDEncoder) actual, found := Retrieve(s, Key, AttributeIDDecoder) assert.True(t, found) @@ -104,8 +98,7 @@ func TestAttributeDataType(t *testing.T) { expected := zcl.AttributeDataType(1) - err := Store(s, Key, expected, AttributeDataTypeEncoder) - assert.NoError(t, err) + Store(s, Key, expected, AttributeDataTypeEncoder) actual, found := Retrieve(s, Key, AttributeDataTypeDecoder) assert.True(t, found)