Skip to content

feat: add card.power api #107

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

Merged
merged 1 commit into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions notecard/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,26 @@ def transport(card, method=None, allow=None):
if allow is not None:
req["allow"] = allow
return card.Transaction(req)


@validate_card_object
def power(card, minutes=None, reset=None):
"""Configure a connected Mojo device or request power consumption readings in firmware.

Args:
card (Notecard): The current Notecard object.
minutes (int): The number of minutes to log power consumption. Default is 720 minutes (12 hours).
reset (bool): When True, resets the power consumption counter back to 0.

Returns:
dict: The result of the Notecard request. The response will contain the following fields:
"voltage": The current voltage.
"milliamp_hours": The cumulative energy consumption in milliamp hours.
"temperature": The Notecard's internal temperature in degrees centigrade, including offset.
"""
req = {"req": "card.power"}
if minutes:
req["minutes"] = minutes
if reset:
req["reset"] = reset
return card.Transaction(req)
8 changes: 8 additions & 0 deletions test/fluent_api/test_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@
'method': 'wifi-cell-ntn',
'allow': True
}
),
(
card.power,
'card.power',
{
'minutes': 10,
'reset': True
}
)
]
)
Expand Down