Skip to content

Commit 49fbe49

Browse files
authored
fix: adding missing rsp fields to card.voltage; clarify descriptions (#300)
1 parent cb3c5b8 commit 49fbe49

2 files changed

Lines changed: 97 additions & 18 deletions

File tree

card.voltage.rsp.notecard.api.json

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,46 @@
1010
"CELL",
1111
"CELL+WIFI",
1212
"LORA",
13+
"SKYLO",
1314
"WIFI"
1415
],
1516
"properties": {
17+
"alert": {
18+
"description": "`true` if the Notecard is configured to add an entry to the `health.qo` Notefile on USB connect/disconnect (enabled by sending `card.voltage` with `\"usb\": true, \"alert\": true`).",
19+
"type": "boolean"
20+
},
21+
"calibration": {
22+
"description": "If a user calibration value has been saved (via `\"set\": true`), this is that value; otherwise it is the hardware-supplied default.",
23+
"type": "number"
24+
},
1625
"daily": {
17-
"description": "Change of moving average in the last 24 hours, if relevant to the time period analyzed.",
26+
"description": "Change in the 24-hour moving average over the analyzed window. Only present when historic voltage trend calculations have been enabled with `\"on\": true` and the analyzed window includes at least 24 hours of history.",
1827
"type": "number"
1928
},
2029
"hours": {
21-
"description": "The number of hours used for trend analysis.",
30+
"description": "The number of hours of voltage history actually used in the analysis. Only present when historic voltage trend calculations have been enabled with `\"on\": true`.",
2231
"type": "integer"
2332
},
2433
"minutes": {
25-
"description": "Represents the Notecard's uptime in minutes. This field is not present when the device is powered via USB.",
34+
"description": "The number of minutes since the Notecard was last on USB power. Not present when the Notecard is currently connected to USB power.",
2635
"type": "integer"
2736
},
2837
"mode": {
2938
"description": "The current voltage-variable threshold value returned from Notecard.\n\nFor example, if the voltage threshold is `\"usb:4.6;normal:3.5;dead:0\"` and the power source returns a voltage of `3.9`, the mode value would be `\"normal\"`.",
3039
"type": "string"
3140
},
3241
"monthly": {
33-
"description": "Change of moving average in the last 30 days, if relevant to the time period analyzed.",
42+
"description": "Change in the 30-day moving average over the analyzed window. Only present when historic voltage trend calculations have been enabled with `\"on\": true` and the analyzed window includes at least 30 days of history.",
3443
"type": "number"
3544
},
45+
"on": {
46+
"description": "`true` if the request that produced this response set `\"on\": true`.",
47+
"type": "boolean"
48+
},
49+
"sync": {
50+
"description": "`true` if the Notecard is configured to perform a sync on USB connect/disconnect (enabled by sending `card.voltage` with `\"usb\": true, \"sync\": true`).",
51+
"type": "boolean"
52+
},
3653
"usb": {
3754
"description": "`true` if the Notecard is connected to USB power.",
3855
"type": "boolean",
@@ -43,33 +60,43 @@
4360
"type": "number"
4461
},
4562
"vavg": {
46-
"description": "The average voltage value during the measured period.",
63+
"description": "The average voltage during the analyzed window. Only present when historic voltage trend calculations have been enabled with `\"on\": true`.",
4764
"type": "number"
4865
},
4966
"vmax": {
50-
"description": "The highest voltage value captured during the measurement period.",
67+
"description": "The highest voltage during the analyzed window. Only present when historic voltage trend calculations have been enabled with `\"on\": true`.",
5168
"type": "number"
5269
},
5370
"vmin": {
54-
"description": "The lowest voltage value captured during the measurement period.",
71+
"description": "The lowest voltage during the analyzed window. Only present when historic voltage trend calculations have been enabled with `\"on\": true`.",
5572
"type": "number"
5673
},
5774
"weekly": {
58-
"description": "Change of moving average in the last 7 days, if relevant to the time period analyzed.",
75+
"description": "Change in the 7-day moving average over the analyzed window. Only present when historic voltage trend calculations have been enabled with `\"on\": true` and the analyzed window includes at least 7 days of history.",
5976
"type": "number"
6077
}
6178
},
6279
"additionalProperties": false,
6380
"samples": [
6481
{
65-
"title": "USB-Powered Voltage Response",
66-
"description": "Example response when Notecard is powered via USB.",
82+
"title": "Bare Request (USB-Powered, History Disabled)",
83+
"description": "Minimal response from a bare `card.voltage` request on a USB-powered Notecard. No historical fields are present because trend analysis has not been enabled with `\"on\": true`.",
84+
"json": "{\"usb\": true, \"mode\": \"usb\", \"value\": 5.112190219747135}"
85+
},
86+
{
87+
"title": "USB-Powered with Trends",
88+
"description": "Response when Notecard is powered via USB and historic voltage trend calculations have been enabled with `\"on\": true`.",
6789
"json": "{\"usb\": true, \"hours\": 120, \"mode\": \"usb\", \"value\": 5.112190219747135, \"vmin\": 4, \"vmax\": 4, \"vavg\": 4}"
6890
},
6991
{
7092
"title": "Battery-Powered with Trends",
71-
"description": "Example response showing battery voltage with trend analysis.",
93+
"description": "Response when Notecard is on battery and historic voltage trend calculations have been enabled with `\"on\": true`.",
7294
"json": "{\"mode\": \"normal\", \"value\": 3.85, \"hours\": 720, \"vmin\": 3.2, \"vmax\": 4.1, \"vavg\": 3.75, \"daily\": -0.05, \"weekly\": -0.3, \"monthly\": -0.8, \"minutes\": 43200}"
95+
},
96+
{
97+
"title": "Query Current Thresholds",
98+
"description": "Response to a `card.voltage` request that includes `\"mode\": \"?\"`. The `mode` field carries the configured threshold definition string, not a bucket label.",
99+
"json": "{\"usb\": true, \"mode\": \"usb:4.6;high:4.0;normal:3.5;low:3.2;dead:0\", \"value\": 5.112190219747135}"
73100
}
74101
]
75102
}

tests/test_card_voltage_rsp.py

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,72 @@ def test_invalid_type_for_number_field(schema, field_name):
5656
jsonschema.validate(instance=instance, schema=schema)
5757
assert "'3.9' is not of type 'number'" in str(excinfo.value)
5858

59+
def test_valid_alert(schema):
60+
"""Tests valid alert field."""
61+
instance = {"alert": True}
62+
jsonschema.validate(instance=instance, schema=schema)
63+
64+
def test_alert_invalid_type(schema):
65+
"""Tests invalid type for alert."""
66+
instance = {"alert": "true"}
67+
with pytest.raises(jsonschema.ValidationError) as excinfo:
68+
jsonschema.validate(instance=instance, schema=schema)
69+
assert "'true' is not of type 'boolean'" in str(excinfo.value)
70+
71+
def test_valid_calibration(schema):
72+
"""Tests valid calibration field."""
73+
instance = {"calibration": 3.3}
74+
jsonschema.validate(instance=instance, schema=schema)
75+
76+
def test_calibration_invalid_type(schema):
77+
"""Tests invalid type for calibration."""
78+
instance = {"calibration": "3.3"}
79+
with pytest.raises(jsonschema.ValidationError) as excinfo:
80+
jsonschema.validate(instance=instance, schema=schema)
81+
assert "'3.3' is not of type 'number'" in str(excinfo.value)
82+
83+
def test_valid_on(schema):
84+
"""Tests valid on field."""
85+
instance = {"on": True}
86+
jsonschema.validate(instance=instance, schema=schema)
87+
88+
def test_on_invalid_type(schema):
89+
"""Tests invalid type for on."""
90+
instance = {"on": 1}
91+
with pytest.raises(jsonschema.ValidationError) as excinfo:
92+
jsonschema.validate(instance=instance, schema=schema)
93+
assert "1 is not of type 'boolean'" in str(excinfo.value)
94+
95+
def test_valid_sync(schema):
96+
"""Tests valid sync field."""
97+
instance = {"sync": True}
98+
jsonschema.validate(instance=instance, schema=schema)
99+
100+
def test_sync_invalid_type(schema):
101+
"""Tests invalid type for sync."""
102+
instance = {"sync": "true"}
103+
with pytest.raises(jsonschema.ValidationError) as excinfo:
104+
jsonschema.validate(instance=instance, schema=schema)
105+
assert "'true' is not of type 'boolean'" in str(excinfo.value)
106+
59107
def test_valid_all_fields(schema):
60108
"""Tests a valid response with all fields."""
61109
instance = {
110+
"alert": True,
111+
"calibration": 3.3,
112+
"daily": -0.05,
113+
"hours": 720,
114+
"minutes": 43200,
62115
"mode": "normal",
116+
"monthly": -0.8,
117+
"on": True,
118+
"sync": False,
63119
"usb": True,
64120
"value": 3.85,
65-
"hours": 720,
66-
"vmin": 3.2,
67-
"vmax": 4.1,
68121
"vavg": 3.75,
69-
"daily": -0.05,
70-
"weekly": -0.3,
71-
"monthly": -0.8,
72-
"minutes": 43200
122+
"vmax": 4.1,
123+
"vmin": 3.2,
124+
"weekly": -0.3
73125
}
74126
jsonschema.validate(instance=instance, schema=schema)
75127

0 commit comments

Comments
 (0)