Skip to content

Commit 80e740b

Browse files
committed
feat: generate APIs using notecard-schema
1 parent 65d3627 commit 80e740b

File tree

21 files changed

+1934
-1078
lines changed

21 files changed

+1934
-1078
lines changed

notecard/aliases.json

Lines changed: 0 additions & 32 deletions
This file was deleted.

notecard/card.py

Lines changed: 546 additions & 658 deletions
Large diffs are not rendered by default.

notecard/dfu.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"""dfu Fluent API Helper."""
2+
3+
##
4+
# @file dfu.py
5+
#
6+
# @brief dfu Fluent API Helper.
7+
#
8+
# @section description Description
9+
# This module contains helper methods for calling dfu.* Notecard API commands.
10+
# This module is optional and not required for use with the Notecard.
11+
12+
from notecard.validators import validate_card_object
13+
14+
15+
@validate_card_object
16+
def get(card, length=None, offset=None):
17+
"""Retrieve downloaded firmware data from the Notecard for use with IAP host MCU firmware updates.
18+
19+
Args:
20+
card (Notecard): The current Notecard object.
21+
length (int): The number of bytes of firmware data to read and return to the host. Set to `0` to verify that the Notecard is in DFU mode without attempting to retrieve data.
22+
offset (int): The offset to use before performing a read of firmware data.
23+
24+
Returns:
25+
dict: The result of the Notecard request.
26+
"""
27+
req = {"req": "dfu.get"}
28+
if length is not None:
29+
req["length"] = length
30+
if offset is not None:
31+
req["offset"] = offset
32+
return card.Transaction(req)
33+
34+
35+
@validate_card_object
36+
def status(card, name=None, stop=None, status=None, version=None, vvalue=None, on=None, off=None, err=None):
37+
"""Get and sets the background download status of MCU host or Notecard firmware updates.
38+
39+
Args:
40+
card (Notecard): The current Notecard object.
41+
name (str): Determines which type of firmware update status to view. The value can be `"user"` (default), which gets the status of MCU host firmware updates, or `"card"`, which gets the status of Notecard firmware updates.
42+
stop (bool): `true` to clear DFU state and delete the local firmware image from the Notecard.
43+
status (str): When setting `stop` to `true`, an optional string synchronized to Notehub, which can be used for informational or diagnostic purposes.
44+
version (str): Version information on the host firmware to pass to Notehub. You may pass a simple version number string (e.g. `"1.0.0.0"`), or an object with detailed information about the firmware image (recommended).
45+
vvalue (str): A voltage-variable string that controls, by Notecard voltage, whether or not DFU is enabled. Use a boolean `1` (on) or `0` (off) for each source/voltage level: `usb:<1/0>;high:<1/0>;normal:<1/0>;low:<1/0>;dead:0`.
46+
on (bool): `true` to allow firmware downloads from Notehub.
47+
off (bool): `true` to disable firmware downloads from Notehub.
48+
err (str): If `err` text is provided along with `"stop":true`, this sets the host DFU to an error state with the specified string.
49+
50+
Returns:
51+
dict: The result of the Notecard request.
52+
"""
53+
req = {"req": "dfu.status"}
54+
if name:
55+
req["name"] = name
56+
if stop is not None:
57+
req["stop"] = stop
58+
if status:
59+
req["status"] = status
60+
if version:
61+
req["version"] = version
62+
if vvalue:
63+
req["vvalue"] = vvalue
64+
if on is not None:
65+
req["on"] = on
66+
if off is not None:
67+
req["off"] = off
68+
if err:
69+
req["err"] = err
70+
return card.Transaction(req)

notecard/env.py

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@
99
# This module contains helper methods for calling env.* Notecard API commands.
1010
# This module is optional and not required for use with the Notecard.
1111

12-
import notecard
1312
from notecard.validators import validate_card_object
1413

1514

1615
@validate_card_object
1716
def default(card, name=None, text=None):
18-
"""Perform an env.default request against a Notecard.
17+
"""Use by the Notecard host to specify a default value for an environment variable until that variable is overridden by a device, project or fleet-wide setting at Notehub.
1918
2019
Args:
2120
card (Notecard): The current Notecard object.
22-
name (string): The name of an environment var to set a default for.
23-
text (optional): The default value. Omit to delete the default.
21+
name (str): The name of the environment variable (case-insensitive).
22+
text (str): The value of the variable. Pass `""` or omit from the request to delete it.
2423
2524
Returns:
26-
string: The result of the Notecard request.
25+
dict: The result of the Notecard request.
2726
"""
2827
req = {"req": "env.default"}
2928
if name:
@@ -34,51 +33,77 @@ def default(card, name=None, text=None):
3433

3534

3635
@validate_card_object
37-
def get(card, name=None):
38-
"""Perform an env.get request against a Notecard.
36+
def get(card, name=None, names=None, time=None):
37+
"""Return a single environment variable, or all variables according to precedence rules.
3938
4039
Args:
4140
card (Notecard): The current Notecard object.
42-
name (string): The name of an environment variable to get.
41+
name (str): The name of the environment variable (case-insensitive). Omit to return all environment variables known to the Notecard.
42+
names (list): A list of one or more variables to retrieve, by name (case-insensitive).
43+
time (int): Request a modified environment variable or variables from the Notecard, but only if modified after the time provided.
4344
4445
Returns:
45-
string: The result of the Notecard request.
46+
dict: The result of the Notecard request.
4647
"""
4748
req = {"req": "env.get"}
4849
if name:
4950
req["name"] = name
51+
if names:
52+
req["names"] = names
53+
if time is not None:
54+
req["time"] = time
5055
return card.Transaction(req)
5156

5257

5358
@validate_card_object
54-
def modified(card):
55-
"""Perform an env.modified request against a Notecard.
59+
def modified(card, time=None):
60+
"""Get the time of the update to any environment variable managed by the Notecard.
5661
5762
Args:
5863
card (Notecard): The current Notecard object.
64+
time (int): Request whether the Notecard has detected an environment variable change since a known epoch time.
5965
6066
Returns:
61-
string: The result of the Notecard request.
67+
dict: The result of the Notecard request.
6268
"""
6369
req = {"req": "env.modified"}
70+
if time is not None:
71+
req["time"] = time
6472
return card.Transaction(req)
6573

6674

6775
@validate_card_object
6876
def set(card, name=None, text=None):
69-
"""Perform an env.set request against a Notecard.
77+
"""Set a local environment variable on the Notecard. Local environment variables cannot be overridden by a Notehub variable of any scope.
7078
7179
Args:
7280
card (Notecard): The current Notecard object.
73-
name (string): The name of an environment variable to set.
74-
text (optional): The variable value. Omit to delete.
81+
name (str): The name of the environment variable (case-insensitive).
82+
text (str): The value of the variable. Pass `""` or omit from the request to delete it.
7583
7684
Returns:
77-
string: The result of the Notecard request.
85+
dict: The result of the Notecard request.
7886
"""
7987
req = {"req": "env.set"}
8088
if name:
8189
req["name"] = name
8290
if text:
8391
req["text"] = text
8492
return card.Transaction(req)
93+
94+
95+
@validate_card_object
96+
def template(card, body=None):
97+
"""Use env.template request allows developers to provide a schema for the environment variables the Notecard uses. The provided template allows the Notecard to store environment variables as fixed-length binary records rather than as flexible JSON objects that require much more memory.
98+
99+
Args:
100+
card (Notecard): The current Notecard object.
101+
body (dict): A sample JSON body that specifies environment variables names and values as "hints" for the data type. Possible data types are: boolean, integer, float, and string. See Understanding Template Data Types for a full explanation of type hints.
102+
103+
Returns:
104+
dict: The result of the Notecard request.
105+
"""
106+
req = {"req": "env.template"}
107+
if body:
108+
req["body"] = body
109+
return card.Transaction(req)

notecard/file.py

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,72 +9,89 @@
99
# This module contains helper methods for calling file.* Notecard API commands.
1010
# This module is optional and not required for use with the Notecard.
1111

12-
import notecard
1312
from notecard.validators import validate_card_object
1413

1514

1615
@validate_card_object
17-
def changes(card, tracker=None, files=None):
18-
"""Perform individual or batch queries on Notefiles.
16+
def changesPending(card):
17+
"""Return info about file changes that are pending upload to Notehub.
1918
2019
Args:
2120
card (Notecard): The current Notecard object.
22-
tracker (string): A developer-defined tracker ID.
23-
files (array): A list of Notefiles to retrieve changes for.
2421
2522
Returns:
26-
string: The result of the Notecard request.
23+
dict: The result of the Notecard request.
2724
"""
28-
req = {"req": "file.changes"}
29-
if tracker:
30-
req["tracker"] = tracker
31-
if files:
32-
req["files"] = files
25+
req = {"req": "file.changes.pending"}
3326
return card.Transaction(req)
3427

3528

3629
@validate_card_object
37-
def delete(card, files=None):
38-
"""Delete individual notefiles and their contents.
30+
def changes(card, files=None, tracker=None):
31+
"""Use file.changes request performs queries on a single or multiple files to determine if new Notes are available to read, or if there are unsynced Notes in local Notefiles. Note: This request is a Notefile API request, only. `.qo` Notes in Notehub are automatically ingested and stored, or sent to applicable Routes.
3932
4033
Args:
4134
card (Notecard): The current Notecard object.
42-
files (array): A list of Notefiles to delete.
35+
files (list): An array of Notefile names to obtain change information from. If not specified, queries all Notefiles.
36+
tracker (str): An ID string for a change tracker to use to determine changes to Notefiles. Each tracker maintains its own state for monitoring file changes.
4337
4438
Returns:
45-
string: The result of the Notecard request.
39+
dict: The result of the Notecard request.
4640
"""
47-
req = {"req": "file.delete"}
41+
req = {"req": "file.changes"}
4842
if files:
4943
req["files"] = files
44+
if tracker:
45+
req["tracker"] = tracker
5046
return card.Transaction(req)
5147

5248

5349
@validate_card_object
54-
def stats(card):
55-
"""Obtain statistics about local notefiles.
50+
def clear(card, file=None):
51+
"""Use to clear the contents of a specified outbound (.qo/.qos) Notefile, deleting all pending Notes.
5652
5753
Args:
5854
card (Notecard): The current Notecard object.
55+
file (str): The name of the Notefile whose Notes you wish to delete.
5956
6057
Returns:
61-
string: The result of the Notecard request.
58+
dict: The result of the Notecard request.
6259
"""
63-
req = {"req": "file.stats"}
64-
60+
req = {"req": "file.clear"}
61+
if file:
62+
req["file"] = file
6563
return card.Transaction(req)
6664

6765

6866
@validate_card_object
69-
def pendingChanges(card):
70-
"""Retrieve information about pending Notehub changes.
67+
def delete(card, files=None):
68+
"""Delete Notefiles and the Notes they contain.
7169
7270
Args:
7371
card (Notecard): The current Notecard object.
72+
files (list): One or more files to delete.
7473
7574
Returns:
76-
string: The result of the Notecard request.
75+
dict: The result of the Notecard request.
7776
"""
78-
req = {"req": "file.changes.pending"}
77+
req = {"req": "file.delete"}
78+
if files:
79+
req["files"] = files
80+
return card.Transaction(req)
81+
82+
83+
@validate_card_object
84+
def stats(card, file=None):
85+
"""Get resource statistics about local Notefiles.
86+
87+
Args:
88+
card (Notecard): The current Notecard object.
89+
file (str): Returns the stats for the specified Notefile only.
7990
91+
Returns:
92+
dict: The result of the Notecard request.
93+
"""
94+
req = {"req": "file.stats"}
95+
if file:
96+
req["file"] = file
8097
return card.Transaction(req)

0 commit comments

Comments
 (0)