Skip to content

Commit

Permalink
fixup! bridge: updates for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 committed May 2, 2024
1 parent d23505f commit 9306327
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions bridge/device/thingDescription/thingDescription.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,44 @@ func StringToPtr(v string) *string {
return &v
}

type PropertyElementOperations struct {
ReadOnly bool
WriteOnly bool
Observable bool
}

func GetPropertyElementOperations(ops resources.SupportedOperation) PropertyElementOperations {
return PropertyElementOperations{
Observable: ops.HasOperation(resources.SupportedOperationObserve),
ReadOnly: ops.HasOperation(resources.SupportedOperationRead) && !ops.HasOperation(resources.SupportedOperationWrite),
WriteOnly: ops.HasOperation(resources.SupportedOperationWrite) && !ops.HasOperation(resources.SupportedOperationRead),
}
}

func (p PropertyElementOperations) ToSupportedOperations() resources.SupportedOperation {
var ops resources.SupportedOperation
if p.Observable {
ops |= resources.SupportedOperationObserve
}
if p.ReadOnly {
return ops | resources.SupportedOperationRead
}
if p.WriteOnly {
return ops | resources.SupportedOperationWrite
}
return ops | resources.SupportedOperationRead | resources.SupportedOperationWrite
}

func PatchPropertyElement(prop thingDescription.PropertyElement, types []string, setForm bool, deviceID uuid.UUID, href string, ops resources.SupportedOperation, contentType string) (thingDescription.PropertyElement, error) {
if len(types) > 0 {
prop.Type = &thingDescription.TypeDeclaration{
StringArray: types,
}
}
observable := ops.HasOperation(resources.SupportedOperationObserve)
isReadOnly := ops.HasOperation(resources.SupportedOperationRead) && !ops.HasOperation(resources.SupportedOperationWrite)
isWriteOnly := ops.HasOperation(resources.SupportedOperationWrite) && !ops.HasOperation(resources.SupportedOperationRead)
prop.Observable = BoolToPtr(observable)
prop.ReadOnly = BoolToPtr(isReadOnly)
prop.WriteOnly = BoolToPtr(isWriteOnly)
prop.Observable = BoolToPtr(observable)
propOps := GetPropertyElementOperations(ops)
prop.Observable = BoolToPtr(propOps.Observable)
prop.ReadOnly = BoolToPtr(propOps.ReadOnly)
prop.WriteOnly = BoolToPtr(propOps.WriteOnly)
if !setForm {
return prop, nil
}
Expand Down

0 comments on commit 9306327

Please sign in to comment.