Skip to content

Commit

Permalink
Add class_c_timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtmc committed May 9, 2024
1 parent 3e32b90 commit 57265ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/resources/device_profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ resource "chirpstack_device_profile" "mydeviceprofile" {

- `adr_algorithm` (String) The ADR algorithm that will be used for controlling the device data-rate.
- `allow_roaming` (Boolean) If enabled (and if roaming is configured on the server), this allows the device to use roaming.
- `class_c_timeout` (Number) Class-C timeout (seconds). This is the maximum time ChirpStack will wait to receive an acknowledgement from the device (if requested).
- `description` (String) Device profile description
- `device_status_request_frequency` (Number) Frequency to initiate an End-Device status request (request/day). Set to 0 to disable.
- `device_supports_class_b` (Boolean) Device supports Class-B
Expand Down
10 changes: 10 additions & 0 deletions internal/provider/device_profile_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type DeviceProfileResourceModel struct {
DeviceSupportsOTAA types.Bool `tfsdk:"device_supports_otaa"`
DeviceSupportsClassB types.Bool `tfsdk:"device_supports_class_b"`
DeviceSupportsClassC types.Bool `tfsdk:"device_supports_class_c"`
ClassCTimeout types.Int64 `tfsdk:"class_c_timeout"`
}

func (r *DeviceProfileResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
Expand Down Expand Up @@ -128,6 +129,11 @@ func (r *DeviceProfileResource) Schema(ctx context.Context, req resource.SchemaR
MarkdownDescription: "Device supports Class-C",
Optional: true,
},
"class_c_timeout": schema.Int64Attribute{
MarkdownDescription: "Class-C timeout (seconds). This is the maximum time ChirpStack will wait to receive an acknowledgement from the device (if requested).",
Optional: true,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -198,6 +204,7 @@ func deviceProfileFromData(data *DeviceProfileResourceModel) *api.DeviceProfile
if !data.DeviceSupportsClassC.IsNull() {
deviceProfile.SupportsClassC = data.DeviceSupportsClassC.ValueBool()
}
deviceProfile.ClassCTimeout = uint32(data.ClassCTimeout.ValueInt64())

return deviceProfile
}
Expand Down Expand Up @@ -226,6 +233,7 @@ func deviceProfileToData(deviceProfile *api.DeviceProfile, data *DeviceProfileRe
data.DeviceSupportsOTAA = types.BoolValue(deviceProfile.SupportsOtaa)
data.DeviceSupportsClassB = types.BoolValue(deviceProfile.SupportsClassB)
data.DeviceSupportsClassC = types.BoolValue(deviceProfile.SupportsClassC)
data.ClassCTimeout = types.Int64Value(int64(deviceProfile.ClassCTimeout))
}

func (r *DeviceProfileResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
Expand Down Expand Up @@ -256,6 +264,7 @@ func (r *DeviceProfileResource) Create(ctx context.Context, req resource.CreateR
// For the purposes of this device profile code, hardcoding a response value to
// save into the Terraform state.
data.Id = types.StringValue(id)
deviceProfileToData(deviceProfile, &data)

// Write logs using the tflog package
// Documentation: https://terraform.io/plugin/log
Expand Down Expand Up @@ -317,6 +326,7 @@ func (r *DeviceProfileResource) Update(ctx context.Context, req resource.UpdateR
resp.Diagnostics.AddError("Chirpstack Error", fmt.Sprintf("Unable to update device profile, got error: %s", err))
return
}
deviceProfileToData(deviceProfile, &data)

// Save updated data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
Expand Down

0 comments on commit 57265ac

Please sign in to comment.