Skip to content

Commit

Permalink
Merge pull request #23 from kirei/cli_remote_start_stop
Browse files Browse the repository at this point in the history
CLI for remote start stop
  • Loading branch information
jschlyter authored Jun 29, 2024
2 parents fed438e + 657f7a5 commit f91dedc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
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

0 comments on commit f91dedc

Please sign in to comment.