Skip to content

Conversation

@m-mcgowan
Copy link
Contributor

@m-mcgowan m-mcgowan commented Apr 12, 2023

Changes

  • added SetAppUserAgent, which allows the application to provide a dictionary of app user agent properties. This is merged with the host user agent info.
  • Sends the user agent info as the body of the hub.set request.
  • Unit tests to verify the expected changes to the hub.set request

Testing

Test Setup:

  • Circuitpython 8.x running on Adafruit nRF52840
  • Notecard + Notecarrier F
  • notecard directory from note-python library copied to CIRCUITPY/lib/notecard
  • Notecard connected to a Notehub project

Test Script:

import board
import busio
import notecard

port = busio.I2C(board.SCL, board.SDA)
card = notecard.OpenI2C(port, 0, 0, debug = True)
card.SetAppUserAgent({"app":"myapp"})
req = {"req": "hub.set"}
rsp = card.Transaction(req)

Test Output:

code.py output:
{"body": {"os_family": "Adafruit Feather nRF52840 Express with nRF52840", "req_interface": "i2c", "os_name": "circuitpython", "os_platform": "nRF52840", "agent": "note-python", "req_port": 0, "os_version": "3.4.0", "app": "myapp"}, "req": "hub.set"}
{}

Notehub event:

    "req": "note.update",
    "file": "_env.dbs",
    "note": "_state_vars",
    ...
    "body": {
        ...
        "user_agent": {
            "agent": "note-python",
            "app": "myapp",
            "os_family": "Adafruit Feather nRF52840 Express with nRF52840",
            "os_name": "circuitpython",
            "os_platform": "nRF52840",
            "os_version": "3.4.0",
            "req_interface": "i2c",
            "req_port": 0
        }
    },
    ...

…nt info. Fixes how the user agent info is communicated to the notecard via the `body` property.
@m-mcgowan m-mcgowan requested a review from bsatrom April 12, 2023 02:42
Comment on lines 218 to 220
ua = {'body': self.GetUserAgent()}
new_req.update(ua)
req = new_req
Copy link
Member

Choose a reason for hiding this comment

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

This is a nit pick, but why not something like new_req.update({'body': self.GetUserAgent()}) instead of these two lines?

Copy link
Contributor Author

@m-mcgowan m-mcgowan Apr 12, 2023

Choose a reason for hiding this comment

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

Can't say I gave it much thought, although I prefer lower density code for readability, plus it's helpful to have the intermediate values available for debugging. I'll factor it together.

@bsatrom bsatrom self-requested a review April 12, 2023 21:27
@m-mcgowan m-mcgowan merged commit 108cf6e into main Apr 12, 2023
@m-mcgowan m-mcgowan deleted the mdm-ua-fix branch April 12, 2023 21:34
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.

3 participants