Skip to content

Commit

Permalink
Fixed update device, now properly igoring not wanted values
Browse files Browse the repository at this point in the history
  • Loading branch information
fbuedding committed Mar 29, 2024
1 parent ca6924e commit 2e83ce1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
4 changes: 3 additions & 1 deletion iota-device.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (i IoTA) ReadDevice(fs FiwareService, id DeciveId) (*Device, error) {
}

var device Device
err = json.Unmarshal(responseData, &device)
json.Unmarshal(responseData, &device)
if err != nil {
log.Panic().Err(err).Msg("Could not Marshal struct")
}
Expand Down Expand Up @@ -205,6 +205,8 @@ func (i IoTA) UpdateDevice(fs FiwareService, d Device) error {
// Ensure these fields are not set
d.Id = ""
d.Transport = ""
d.Service = ""
d.ServicePath = ""

method := "PUT"

Expand Down
55 changes: 42 additions & 13 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,49 @@ func TestMain(m *testing.M) {
log.Info().Msgf("Starting test with iot-agent host: %s", host)
iota = *i.NewIoTAgent(host, 4061, 1000)
fs = i.FiwareService{Service: service, ServicePath: servicePath}
d = i.Device{Id: deviceId, EntityName: entityName}
d = i.Device{
Id: deviceId,
Service: service,
ServicePath: servicePath,
EntityName: entityName,
EntityType: "",
Timezone: "",
Timestamp: new(bool),
Apikey: apiKey,
Endpoint: "",
Protocol: "",
Transport: "",
Attributes: []i.Attribute{},
Commands: []i.Command{},
Lazy: []i.LazyAttribute{},
StaticAttributes: []i.StaticAttribute{},
InternalAttributes: []interface{}{},
ExplicitAttrs: true,
NgsiVersion: "",
PayloadType: "",
}
sg = i.ConfigGroup{
Service: service,
ServicePath: servicePath,
Resource: resource,
Apikey: apiKey,
EntityType: "Test",
Autoprovision: false,
StaticAttributes: []i.StaticAttribute{{
Name: "test",
Type: "Number",
Value: 6,
Metadata: map[string]i.Metadata{},
}},
Service: service,
ServicePath: servicePath,
Resource: resource,
Apikey: apiKey,
Timestamp: new(bool),
EntityType: "Test",
Trust: "",
CbHost: host,
Lazy: []i.LazyAttribute{},
Commands: []i.Command{},
Attributes: []i.Attribute{},
StaticAttributes: []i.StaticAttribute{{Name: "test", Type: "Number", Value: 6, Metadata: map[string]i.Metadata{}}},
InternalAttributes: []interface{}{},
ExplicitAttrs: "",
EntityNameExp: entityName,
NgsiVersion: "",
DefaultEntityNameConjunction: entityName,
Autoprovision: false,
PayloadType: "",
Transport: "",
Endpoint: "",
}
iota.DeleteDevice(fs, d.Id)
err := iota.CreateDevice(fs, d)
Expand Down

0 comments on commit 2e83ce1

Please sign in to comment.