Skip to content

Commit

Permalink
Update to use new converters from persistence.
Browse files Browse the repository at this point in the history
  • Loading branch information
pwood committed May 21, 2024
1 parent 273c33e commit 441c5c9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
27 changes: 13 additions & 14 deletions attribute/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,29 +108,29 @@ func (z *zclMonitor) Load(pctx context.Context) error {

z.ieeeAddress, z.localEndpoint, _, _ = z.transmissionLookup(z.device, zigbee.ProfileHomeAutomation)

if v, ok := z.config.Int(RemoteEndpointKey); ok {
z.remoteEndpoint = zigbee.Endpoint(v)
if v, ok := converter.Retrieve(z.config, RemoteEndpointKey, converter.EndpointDecoder); ok {
z.remoteEndpoint = v
} else {
z.logger.Error(ctx, "Required config parameter missing.", logwrap.Datum("name", RemoteEndpointKey))
return fmt.Errorf("monitor missing config parameter: %s", RemoteEndpointKey)
}

if v, ok := z.config.Int(ClusterIdKey); ok {
z.clusterID = zigbee.ClusterID(v)
if v, ok := converter.Retrieve(z.config, ClusterIdKey, converter.ClusterIDDecoder); ok {
z.clusterID = v
} else {
z.logger.Error(ctx, "Required config parameter missing.", logwrap.Datum("name", ClusterIdKey))
return fmt.Errorf("monitor missing config parameter: %s", ClusterIdKey)
}

if v, ok := z.config.Int(AttributeIdKey); ok {
z.attributeID = zcl.AttributeID(v)
if v, ok := converter.Retrieve(z.config, AttributeIdKey, converter.AttributeIDDecoder); ok {
z.attributeID = v
} else {
z.logger.Error(ctx, "Required config parameter missing.", logwrap.Datum("name", AttributeIdKey))
return fmt.Errorf("monitor missing config parameter: %s", AttributeIdKey)
}

if v, ok := z.config.Int(AttributeDataTypeKey); ok {
z.attributeDataType = zcl.AttributeDataType(v)
if v, ok := converter.Retrieve(z.config, AttributeDataTypeKey, converter.AttributeDataTypeDecoder); ok {
z.attributeDataType = v
} else {
z.logger.Error(ctx, "Required config parameter missing.", logwrap.Datum("name", AttributeDataTypeKey))
return fmt.Errorf("monitor missing config parameter: %s", AttributeDataTypeKey)
Expand All @@ -147,8 +147,7 @@ func (z *zclMonitor) reattach(ctx context.Context) error {

// If polling, start timer.
if v, ok := z.config.Bool(PollingConfiguredKey); ok && v {
interval, _ := converter.Retrieve(z.config, PollingIntervalKey, converter.DurationDecoder, time.Duration(5)*time.Minute)
duration := time.Duration(interval) * time.Millisecond
duration, _ := converter.Retrieve(z.config, PollingIntervalKey, converter.DurationDecoder, time.Duration(5)*time.Minute)

z.logger.Info(ctx, "Polling configured, starting...", logwrap.Datum("intervalMs", duration.Milliseconds()))

Expand All @@ -174,10 +173,10 @@ func (z *zclMonitor) Attach(ctx context.Context, e zigbee.Endpoint, c zigbee.Clu
z.attributeID = a
z.attributeDataType = dt

z.config.Set(RemoteEndpointKey, int(z.remoteEndpoint))
z.config.Set(ClusterIdKey, int(z.clusterID))
z.config.Set(AttributeIdKey, int(z.attributeID))
z.config.Set(AttributeDataTypeKey, int(z.attributeDataType))
converter.Store(z.config, RemoteEndpointKey, z.remoteEndpoint, converter.EndpointEncoder)
converter.Store(z.config, ClusterIdKey, z.clusterID, converter.ClusterIDEncoder)
converter.Store(z.config, AttributeIdKey, z.attributeID, converter.AttributeIDEncoder)
converter.Store(z.config, AttributeDataTypeKey, z.attributeDataType, converter.AttributeDataTypeEncoder)

if rc.Mode == AttemptConfigureReporting {
z.logger.Info(ctx, "Attempting to configure attribute reporting.")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/shimmeringbee/callbacks v0.0.0-20221001135028-b85b5f89d5d6
github.com/shimmeringbee/da v0.0.0-20240510193548-96e721e05984
github.com/shimmeringbee/logwrap v0.1.3
github.com/shimmeringbee/persistence v0.0.0-20240521193653-bb35128b5cdf
github.com/shimmeringbee/persistence v0.0.0-20240521204303-323fdd5d7860
github.com/shimmeringbee/retry v0.0.0-20221006193055-2ce01bf139c2
github.com/shimmeringbee/zcl v0.0.0-20240509210644-817a66d91348
github.com/shimmeringbee/zigbee v0.0.0-20221016122511-6c2328db0d94
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ github.com/shimmeringbee/logwrap v0.1.3 h1:1PqPGdgbeQxACQqc6RUWERn7EnpA1jbiHzXVY
github.com/shimmeringbee/logwrap v0.1.3/go.mod h1:NBAcZCUl6aFOGnWTs8m67EUAmWFZXRhoRQf5nknY8W0=
github.com/shimmeringbee/persistence v0.0.0-20240521193653-bb35128b5cdf h1:6qwSES3dm64Js7StXNsMg9QlCkSsx/Bt/GgysZeSdx8=
github.com/shimmeringbee/persistence v0.0.0-20240521193653-bb35128b5cdf/go.mod h1:dKKEj8uVcBM/CArQRE4yLw5DFRfAAzabI7mbgD1ZLeI=
github.com/shimmeringbee/persistence v0.0.0-20240521204303-323fdd5d7860 h1:z8NP5rtWaxQQH91F9kPenSfpuOcXYuMB135MNcdTYBM=
github.com/shimmeringbee/persistence v0.0.0-20240521204303-323fdd5d7860/go.mod h1:Z5euPm65BHgTSRFgaWHByaXejU/J4oUqESV9k0VzQDU=
github.com/shimmeringbee/retry v0.0.0-20221006193055-2ce01bf139c2 h1:HxpPz7w7SxVf1GmcM5oTK1JK64TGpK1UflweYRSOwC4=
github.com/shimmeringbee/retry v0.0.0-20221006193055-2ce01bf139c2/go.mod h1:KYvVq5b7/BSSlWng+AKB5jwNGpc0D7eg8ySWrdPAlms=
github.com/shimmeringbee/zcl v0.0.0-20240509210644-817a66d91348 h1:J0kBfQom8P2bXAychpcd8PN2qjvgxuqcJi3DktvTm+0=
Expand Down

0 comments on commit 441c5c9

Please sign in to comment.