Skip to content
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

CLI for remote start stop #23

Merged
merged 6 commits into from
Jun 29, 2024
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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
48 changes: 46 additions & 2 deletions chargeamps/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import logging
import os
import sys
import uuid
from datetime import datetime

from aiohttp.client_exceptions import ClientResponseError
from ciso8601 import parse_datetime
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__)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <jakob@kirei.se>"]
Expand Down
Loading