Skip to content

Commit

Permalink
Update converters to reflect change of error removal from Set.
Browse files Browse the repository at this point in the history
  • Loading branch information
pwood committed Jun 15, 2024
1 parent 680c4a8 commit a567d1a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 38 deletions.
4 changes: 2 additions & 2 deletions converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions converter/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions converter/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
28 changes: 14 additions & 14 deletions converter/zigbee.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
21 changes: 7 additions & 14 deletions converter/zigbee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit a567d1a

Please sign in to comment.