Skip to content

Commit

Permalink
Merge pull request #43 from matt-mazzucato/remove-redundant-interface…
Browse files Browse the repository at this point in the history
…-validations

Device: remove redundant validations when adding an interface
  • Loading branch information
bettio authored Jun 22, 2022
2 parents d92ff88 + 688bae8 commit c4658c4
Showing 1 changed file with 3 additions and 25 deletions.
28 changes: 3 additions & 25 deletions device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,32 +275,10 @@ func (d *Device) IsConnected() bool {
}

// AddInterface adds an interface to the device. The interface must be loaded with ParseInterface
// from the astarte-go/interfaces package.
// AddInterface returns `nil` if the interface was loaded successfully, or a corresponding error
// otherwise (e.g. interface validation failed).
// from the astarte-go/interfaces package, which also ensures that the interface is valid.
// The return value should be ignored as the error is always `nil` (i.e. AddInterface cannot fail).
// TODO since the function always returns nil, do not return an error (target release 1.0)
func (d *Device) AddInterface(astarteInterface interfaces.AstarteInterface) error {
if err := astarteInterface.Aggregation.IsValid(); err != nil {
return err
}
if err := astarteInterface.Type.IsValid(); err != nil {
return err
}
if err := astarteInterface.Ownership.IsValid(); err != nil {
return err
}

for _, mapping := range astarteInterface.Mappings {
if err := mapping.Reliability.IsValid(); err != nil {
return err
}
if err := mapping.Retention.IsValid(); err != nil {
return err
}
if err := mapping.DatabaseRetentionPolicy.IsValid(); err != nil {
return err
}
}

d.interfaces[astarteInterface.Name] = astarteInterface
return nil
}
Expand Down

0 comments on commit c4658c4

Please sign in to comment.