diff --git a/CHANGES.md b/CHANGES.md index cc73eda..c5ccae1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Release Notes +## 1.7.0 (develop) + +- Add CLI for remote start/stop + ## 1.6.1 (2023-12-01) - Fix problem with empty body in PUT diff --git a/chargeamps/cli.py b/chargeamps/cli.py index 7433ebe..7ced632 100644 --- a/chargeamps/cli.py +++ b/chargeamps/cli.py @@ -6,6 +6,7 @@ import logging import os import sys +import uuid from datetime import datetime from aiohttp.client_exceptions import ClientResponseError @@ -13,7 +14,7 @@ from isoduration import parse_duration from . import __version__ -from .base import ChargeAmpsClient +from .base import ChargeAmpsClient, StartAuth from .external import ChargeAmpsExternalClient logger = logging.getLogger(__name__) @@ -136,7 +137,29 @@ async def command_set_connector_settings( print(json.dumps(settings.to_dict(), indent=4)) -def add_arg_chargepoint(parser, required=False) -> None: +async def command_remote_start( + client: ChargeAmpsClient, args: argparse.Namespace +) -> None: + charge_point_id = await get_chargepoint_id(client, args) + connector_id = args.connector_id + start_auth = StartAuth( + rfid_length=len(args.rfid) // 2, + rfid_format="hex", + rfid=args.rfid, + external_transaction_id=str(uuid.uuid4()), + ) + await client.remote_start(charge_point_id, connector_id, start_auth) + + +async def command_remote_stop( + client: ChargeAmpsClient, args: argparse.Namespace +) -> None: + charge_point_id = await get_chargepoint_id(client, args) + connector_id = args.connector_id + await client.remote_stop(charge_point_id, connector_id) + + +def add_arg_chargepoint(parser, required=False): parser.add_argument( "--chargepoint", dest="charge_point_id", @@ -290,6 +313,27 @@ async def main_loop() -> None: help="Max current", ) + parser_remote_start = subparsers.add_parser( + "start-connector", help="Remote start connector" + ) + parser_remote_start.set_defaults(func=command_remote_start) + add_arg_chargepoint(parser_remote_start) + add_arg_connector(parser_remote_start) + parser_remote_start.add_argument( + "--rfid", + dest="rfid", + type=str, + required=True, + help="RFID identifier", + ) + + parser_remote_stop = subparsers.add_parser( + "stop-connector", help="Remote stop connector" + ) + parser_remote_stop.set_defaults(func=command_remote_stop) + add_arg_chargepoint(parser_remote_stop) + add_arg_connector(parser_remote_stop) + args = parser.parse_args() if args.debug: diff --git a/pyproject.toml b/pyproject.toml index f38d1ed..07a1d04 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ [tool.poetry] name = "chargeamps" -version = "1.6.1" +version = "1.7.0" readme = "README.md" description = "Charge-Amps API bindings for Python" authors = ["Jakob Schlyter "]