update API helpers to match current API · blues/note-python@b0aec85 · GitHub
Skip to content

Commit b0aec85

Browse files
committed
update API helpers to match current API
1 parent 8c62cef commit b0aec85

6 files changed

Lines changed: 166 additions & 7 deletions

File tree

API.md

Lines changed: 3 additions & 0 deletions

notecard/card.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@
1414

1515

1616
@validate_card_object
17-
def attn(card, mode=None, files=None, seconds=None):
17+
def attn(card, mode=None, files=None, seconds=None, payload=None, start=None):
1818
"""Configure interrupt detection between a host and Notecard.
1919
2020
Args:
2121
card (Notecard): The current Notecard object.
2222
mode (string): The attn mode to set.
2323
files (array): A collection of notefiles to watch.
2424
seconds (int): A timeout to use when arming attn mode.
25+
payload (int): When using sleep mode, a payload of data from the host
26+
that the Notecard should hold in memory until retrieved by
27+
the host.
28+
start (bool): When using sleep mode and the host has reawakened,
29+
request the Notecard to return the stored payload.
2530
2631
Returns:
2732
string: The result of the Notecard request.
@@ -33,6 +38,10 @@ def attn(card, mode=None, files=None, seconds=None):
3338
req["files"] = files
3439
if seconds:
3540
req["seconds"] = seconds
41+
if payload:
42+
req["payload"] = payload
43+
if start:
44+
req["start"] = start
3645
return card.Transaction(req)
3746

3847

@@ -65,16 +74,21 @@ def status(card):
6574

6675

6776
@validate_card_object
68-
def temp(card):
77+
def temp(card, minutes=None):
6978
"""Retrieve the current temperature from the Notecard.
7079
7180
Args:
7281
card (Notecard): The current Notecard object.
82+
mintues (int): If specified, creates a templated _temp.qo file that
83+
gathers Notecard temperature value at the specified minutes
84+
interval.
7385
7486
Returns:
7587
string: The result of the Notecard request.
7688
"""
7789
req = {"req": "card.temp"}
90+
if minutes:
91+
req["minutes"] = minutes
7892
return card.Transaction(req)
7993

8094

@@ -119,18 +133,21 @@ def voltage(card, hours=None, offset=None, vmax=None, vmin=None):
119133

120134

121135
@validate_card_object
122-
def wireless(card, mode=None):
136+
def wireless(card, mode=None, apn=None):
123137
"""Retrieve wireless modem info or customize modem behavior.
124138
125139
Args:
126140
card (Notecard): The current Notecard object.
127141
mode (string): The wireless module mode to set.
142+
apn (string): Access Point Name (APN) when using an external SIM.
128143
129144
Returns:
130145
string: The result of the Notecard request.
131146
"""
132147
req = {"req": "card.wireless"}
133148
if mode:
134149
req["mode"] = mode
150+
if apn:
151+
req["apn"] = apn
135152

136153
return card.Transaction(req)

notecard/env.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@
1313
from .validators import validate_card_object
1414

1515

16+
@validate_card_object
17+
def default(card, name=None, text=None):
18+
"""Perform an env.default request against a Notecard.
19+
20+
Args:
21+
card (Notecard): The current Notecard object.
22+
name (string): The name of an environment variable to set a default
23+
for.
24+
text (optional): The default value. Omit to delete the default.
25+
26+
Returns:
27+
string: The result of the Notecard request.
28+
"""
29+
req = {"req": "env.default"}
30+
if name:
31+
req["name"] = name
32+
if text:
33+
req["text"] = text
34+
return card.Transaction(req)
35+
36+
1637
@validate_card_object
1738
def get(card, name=None):
1839
"""Perform an env.get request against a Notecard.
@@ -28,3 +49,37 @@ def get(card, name=None):
2849
if name:
2950
req["name"] = name
3051
return card.Transaction(req)
52+
53+
54+
@validate_card_object
55+
def modified(card):
56+
"""Perform an env.modified request against a Notecard.
57+
58+
Args:
59+
card (Notecard): The current Notecard object.
60+
61+
Returns:
62+
string: The result of the Notecard request.
63+
"""
64+
req = {"req": "env.modified"}
65+
return card.Transaction(req)
66+
67+
68+
@validate_card_object
69+
def set(card, name=None, text=None):
70+
"""Perform an env.set request against a Notecard.
71+
72+
Args:
73+
card (Notecard): The current Notecard object.
74+
name (string): The name of an environment variable to set.
75+
text (optional): The variable value. Omit to delete.
76+
77+
Returns:
78+
string: The result of the Notecard request.
79+
"""
80+
req = {"req": "env.set"}
81+
if name:
82+
req["name"] = name
83+
if text:
84+
req["text"] = text
85+
return card.Transaction(req)

notecard/hub.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
@validate_card_object
1717
def set(card, product, sn=None, mode=None, outbound=None,
18-
inbound=None, sync=False, align=None, voutbound=None,
18+
inbound=None, duration=None, sync=False, align=None, voutbound=None,
1919
vinbound=None, host=None):
2020
"""Configure Notehub behavior on the Notecard.
2121
@@ -26,6 +26,8 @@ def set(card, product, sn=None, mode=None, outbound=None,
2626
mode (string): The sync mode to use.
2727
outbound (int): Max time to wait to sync outgoing data.
2828
inbound (int): Max time to wait to sync incoming data.
29+
duration (int): If in continuous mode, the amount of time, in minutes,
30+
of each session.
2931
sync (bool): If in continuous mode, whether to automatically
3032
sync each time a change is detected on the device or Notehub.
3133
align (bool): To align syncs to a regular time-interval, as opposed
@@ -48,6 +50,8 @@ def set(card, product, sn=None, mode=None, outbound=None,
4850
req["outbound"] = outbound
4951
if inbound:
5052
req["inbound"] = inbound
53+
if duration:
54+
req["duration"] = duration
5155
if sync is not None:
5256
req["sync"] = sync
5357
if align is not None:

notecard/note.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,29 @@ def update(card, file=None, note_id=None, body=None, payload=None):
121121
if payload:
122122
req["payload"] = payload
123123
return card.Transaction(req)
124+
125+
126+
@validate_card_object
127+
def template(card, file=None, body=None, length=None):
128+
"""Create a template for new Notes in a Notefile.
129+
130+
Args:
131+
card (Notecard): The current Notecard object.
132+
file (string): The file name of the notefile.
133+
body (JSON): A sample JSON body that specifies field names and
134+
values as "hints" for the data type. Possible data types
135+
are: boolean, integer, float, and string.
136+
length (int): If provided, the maximum length of a payload that
137+
can be sent in Notes for the template Notefile.
138+
139+
Returns:
140+
string: The result of the Notecard request.
141+
"""
142+
req = {"req": "note.get"}
143+
if file:
144+
req["file"] = file
145+
if body:
146+
req["body"] = body
147+
if length:
148+
req["length"] = length
149+
return card.Transaction(req)

test/test_notecard.py

Lines changed: 57 additions & 3 deletions

0 commit comments

Comments
 (0)