diff --git a/attribute/monitor.go b/attribute/monitor.go index 05e22ae..4a7dbec 100644 --- a/attribute/monitor.go +++ b/attribute/monitor.go @@ -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) @@ -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())) @@ -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.") diff --git a/go.mod b/go.mod index 40afba3..19fbeef 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 3a3a93d..d70c846 100644 --- a/go.sum +++ b/go.sum @@ -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=