From 281259c30a6083053202db9a7bb118c53e9d73de Mon Sep 17 00:00:00 2001 From: Alex Bucknall Date: Thu, 17 Apr 2025 13:52:27 +0100 Subject: [PATCH] feat: add card.power api --- notecard/card.py | 23 +++++++++++++++++++++++ test/fluent_api/test_card.py | 8 ++++++++ 2 files changed, 31 insertions(+) diff --git a/notecard/card.py b/notecard/card.py index daddf91..5b71f23 100644 --- a/notecard/card.py +++ b/notecard/card.py @@ -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) diff --git a/test/fluent_api/test_card.py b/test/fluent_api/test_card.py index bb4d082..7794558 100644 --- a/test/fluent_api/test_card.py +++ b/test/fluent_api/test_card.py @@ -61,6 +61,14 @@ 'method': 'wifi-cell-ntn', 'allow': True } + ), + ( + card.power, + 'card.power', + { + 'minutes': 10, + 'reset': True + } ) ] )