Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add resource, command, and device tags to reading/event #1297

Merged
merged 1 commit into from
Feb 6, 2023

Conversation

FelixTing
Copy link
Member

@FelixTing FelixTing commented Jan 31, 2023

fix #1294

  1. Add device resource tags to reading
  2. Add device command tags to event
  3. Add device tags to event
    Note: Device tags take precedence over Device Command tags.

Signed-off-by: Felix Ting felix@iotechsys.com

If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/device-sdk-go/blob/main/.github/Contributing.md

PR Checklist

Please check if your PR fulfills the following requirements:

  • I am not introducing a breaking change (if you are, flag in conventional commit message with BREAKING CHANGE: describing the break)
  • I am not introducing a new dependency (add notes below if you are)
  • I have added unit tests for the new feature or bug fix (if not, why?)
  • I have fully tested (add details below) this the new feature or bug fix (if not, why?)
  • I have opened a PR for the related docs change (if not, why?)

Testing Instructions

  1. Run non-secure EdgeX Stack
  2. Based on this branch, modify the device configuration of Device Simple to add device tags

simple-device.toml

[[DeviceList]]
  Name = "Simple-Device01"
  ProfileName = "Simple-Device"
  Description = "Example of Simple Device"
  Labels = [ "industrial" ]
  [DeviceList.Tags]
    deviceTag = "deviceTag"
  [DeviceList.Protocols]
  [DeviceList.Protocols.other]
    Address = "simple01"
    Port = "300"
  [[DeviceList.AutoEvents]]
    Interval = "10s"
    OnChange = false
    SourceName = "Switch"
  [[DeviceList.AutoEvents]]
    Interval = "30s"
    OnChange = false
    SourceName = "Image"
  1. Modify the device profile configuration of Device Simple to add resource and command tags

Simple-Driver.yaml

apiVersion: "v2"
name: "Simple-Device"
manufacturer: "Simple Corp."
model: "SP-01"
labels:
  - "modbus"
description: "Example of Simple Device"

deviceResources:
  -
    name: "SwitchButton"
    isHidden: false
    description: "Switch On/Off."
    tags:
      resourceTag: "resourceTag"
    properties:
        valueType: "Bool"
        readWrite: "RW"
        defaultValue: "true"
  -
    name: "Image"
    isHidden: false
    description: "Visual representation of Switch state."
    properties:
        valueType: "Binary"
        readWrite: "R"
        mediaType: "image/jpeg"
  -
    name: "Xrotation"
    isHidden: true
    description: "X axis rotation rate"
    properties:
        valueType: "Int32"
        readWrite: "RW"
        units: "rpm"
  -
    name: "Yrotation"
    isHidden: true
    description: "Y axis rotation rate"
    properties:
        valueType: "Int32"
        readWrite: "RW"
        "units": "rpm"
  -
    name: "Zrotation"
    isHidden: true
    description: "Z axis rotation rate"
    properties:
        valueType: "Int32"
        readWrite: "RW"
        "units": "rpm"
  -
    name: "StringArray"
    isHidden: false
    description: "String array"
    properties:
      valueType: "StringArray"
      readWrite: "RW"
  -
    name: "Uint8Array"
    isHidden: false
    description: "Unsigned 8bit array"
    properties:
        valueType: "Uint8Array"
        readWrite: "RW"
  -
    name: "Counter"
    isHidden: false
    description: "Counter data"
    properties:
      valueType: "Object"
      readWrite: "RW"

deviceCommands:
  -
    name: "Switch"
    isHidden: false
    readWrite: "RW"
    tags:
      commandTag: "commandTag"
    resourceOperations:
      - { deviceResource: "SwitchButton", defaultValue: "false" }
  -
    name: "Image"
    isHidden: false
    readWrite: "R"
    resourceOperations:
      - { deviceResource: "Image" }
  -
    name: "Rotation"
    isHidden: false
    readWrite: "RW"
    resourceOperations:
      - { deviceResource: "Xrotation", defaultValue: "0" }
      - { deviceResource: "Yrotation", defaultValue: "0" }
      - { deviceResource: "Zrotation", defaultValue: "0" }

  1. Run Device Simple
  2. curl http://localhost:59882/api/v2/device/name/Simple-Device01/Switch
    Verify the returned event contains resource, command, and device tags.
{
    "apiVersion": "v2",
    "statusCode": 200,
    "event": {
        "apiVersion": "v2",
        "id": "de6e7c7c-5cb3-4af6-b3ac-3d0c460fe211",
        "deviceName": "Simple-Device01",
        "profileName": "Simple-Device",
        "sourceName": "Switch",
        "origin": 1675147339613147000,
        "readings": [
            {
                "id": "98bf94c7-6a9b-45a6-a2a9-f7c976728c8c",
                "origin": 1675147339613147000,
                "deviceName": "Simple-Device01",
                "resourceName": "SwitchButton",
                "profileName": "Simple-Device",
                "valueType": "Bool",
                "tags": {
                    "resourceTag": "resourceTag"
                },
                "value": "false"
            }
        ],
        "tags": {
            "commandTag": "commandTag",
            "deviceTag": "deviceTag"
        }
    }
}

New Dependency Instructions (If applicable)

@codecov-commenter
Copy link

codecov-commenter commented Jan 31, 2023

Codecov Report

Merging #1297 (4b20157) into main (881f109) will increase coverage by 0.40%.
The diff coverage is 100.00%.

❗ Current head 4b20157 differs from pull request most recent head f710fef. Consider uploading reports for the commit f710fef to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main    #1297      +/-   ##
==========================================
+ Coverage   50.91%   51.31%   +0.40%     
==========================================
  Files          27       27              
  Lines        2406     2426      +20     
==========================================
+ Hits         1225     1245      +20     
  Misses       1075     1075              
  Partials      106      106              
Impacted Files Coverage Δ
internal/common/utils.go 71.42% <100.00%> (+7.79%) ⬆️
internal/transformer/transform.go 38.38% <100.00%> (+1.27%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@lenny-goodell lenny-goodell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just need to add missing unit tests

internal/common/utils.go Show resolved Hide resolved
lenny-goodell
lenny-goodell previously approved these changes Feb 1, 2023
Copy link
Member

@lenny-goodell lenny-goodell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cloudxxx8
Copy link
Member

@FelixTing please resolve the conflict

@FelixTing
Copy link
Member Author

rebased

@cloudxxx8
Copy link
Member

@FelixTing please make sure the unit test can be passed

1. Add device resource tags to reading
2. Add device command tags to event
3. Add device tags to event
Note: Device tags take precedence over Device Command tags.

Signed-off-by: Felix Ting <felix@iotechsys.com>
@FelixTing
Copy link
Member Author

all unit tests have passed

Copy link
Member

@lenny-goodell lenny-goodell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lenny-goodell lenny-goodell merged commit 93a0268 into edgexfoundry:main Feb 6, 2023
@FelixTing FelixTing deleted the issue-1294 branch February 7, 2023 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add resource, command, and device tags to reading/event
4 participants