Skip to content

Commit

Permalink
Add support for LogicalType and NetworkAddress.
Browse files Browse the repository at this point in the history
  • Loading branch information
pwood committed Jun 14, 2024
1 parent f9aa3ea commit f587e84
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
24 changes: 24 additions & 0 deletions converter/zigbee.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,30 @@ 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 NetworkAddressDecoder(s persistence.Section, k string) (zigbee.NetworkAddress, bool) {
if ev, found := s.Int(k); found {
return zigbee.NetworkAddress(ev), true
} else {
return 0, false
}
}

func LogicalTypeEncoder(s persistence.Section, k string, v zigbee.LogicalType) error {
return s.Set(k, int64(v))
}

func LogicalTypeDecoder(s persistence.Section, k string) (zigbee.LogicalType, bool) {
if ev, found := s.Int(k); found {
return zigbee.LogicalType(ev), true
} else {
return 0, false
}
}

func ClusterIDEncoder(s persistence.Section, k string, v zigbee.ClusterID) error {
return s.Set(k, int64(v))
}
Expand Down
30 changes: 30 additions & 0 deletions converter/zigbee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,36 @@ func TestIEEEAddress(t *testing.T) {
})
}

func TestNetworkAddress(t *testing.T) {
t.Run("stored and retrieved", func(t *testing.T) {
s := memory.New()

expected := zigbee.NetworkAddress(0x1122)

err := Store(s, Key, expected, NetworkAddressEncoder)
assert.NoError(t, err)

actual, found := Retrieve(s, Key, NetworkAddressDecoder)
assert.True(t, found)
assert.Equal(t, expected, actual)
})
}

func TestLogicalType(t *testing.T) {
t.Run("stored and retrieved", func(t *testing.T) {
s := memory.New()

expected := zigbee.Router

err := Store(s, Key, expected, LogicalTypeEncoder)
assert.NoError(t, err)

actual, found := Retrieve(s, Key, LogicalTypeDecoder)
assert.True(t, found)
assert.Equal(t, expected, actual)
})
}

func TestAttributeID(t *testing.T) {
t.Run("stored and retrieved", func(t *testing.T) {
s := memory.New()
Expand Down

0 comments on commit f587e84

Please sign in to comment.