Skip to content

Commit 82ae6d1

Browse files
test(ocpp-server): add OCPP 1.6 mock server and extend reservation coverage (#2047)
* test(ocpp-server): add OCPP 1.6 mock server and extend reservation coverage - Add server16.py: standalone OCPP 1.6 mock server mirroring server.py architecture (AuthConfig, ServerConfig, ChargePoint, on_connect, main) - Add test_server16.py: 59 tests covering handlers, outgoing commands, signed meter values, timer, on_connect and main (~96% branch coverage) - Add _send_reserve_now/_send_cancel_reservation to server.py (OCPP 2.0.1) with matching ServerConfig fields and DEFAULT_RESERVATION_* constants - Extend test_server.py: tests for ReserveNow/CancelReservation commands, entries in EXPECTED_OUTGOING_COMMANDS and FAILURE_PATH_CASES, strengthen timestamp assertions (fromisoformat + tzinfo check) - Update pyproject.toml: server16 run task, typecheck and coverage source - Add tools/http_broadcast_timing.py and tools/reused_ws_request_id.py: ad-hoc diagnostic scripts for UI-server fixes #2037 and #2033 * chore(serena): update project knowledge base * revert: remove tools/ from tracked files (kept locally) * fix(ocpp-server): address review findings M1-M3 and m1-m8 M1 - test_boot_status_sequence_parsed: reuse _patch_main (add **args_overrides), capture ServerConfig via side_effect, assert boot_sequence == (pending, accepted) M2 - DRY: extract check_positive_number to _common.py; update typecheck task, coverage source, and mypy override to include it M3 - README: rename to 'OCPP Mock Servers', add Running the Servers section, add full OCPP 1.6 server documentation (20 CLI flags, supported commands, transaction tracking) m1 - remove dead DEFAULT_VENDOR_ID constant (server16.py) m2 - align --reservation-id flag (server.py: --reserve-id -> --reservation-id) and fix coupled Namespace in test_server.py m3 - _call_and_log: log response.status on failure (server.py) m4 - pyproject.toml: add test_server16 to mypy disallow_untyped_defs override m5 - add type hints to on_start_transaction, on_stop_transaction, on_status_notification handlers (server16.py) m6 - add test_windows_handler_schedules_via_call_soon_threadsafe (test_server16.py) m7 - document intentional 1.6 command scope in _COMMAND_HANDLERS m8 - remove dead AuthMode.offline member (server.py) INFO - boot_index: clarify shared-across-all-stations behavior INFO - magic number 128: add Unix convention comment INFO - argparse: 'OCPP2 Server' -> 'OCPP 2.0.1 Server' (server.py) INFO - _parse_commands: raw_entry/entry variable naming (server.py) Coverage tests: test_custom_auth_config, token vide x2, test_meter_values_with_signed_meter_value (test_server16.py) Quality gates: 335 passed, format/lint/typecheck clean, 94.78% * fix(ocpp-server): address post-review findings N1-N6 N1/M2 - server16.py: import check_positive_number from _common, remove local duplicate (567-576); _common.py now has a single consumer N1/m1 - server16.py: remove dead DEFAULT_VENDOR_ID constant N1/m5 - server16.py: add type hints to on_start_transaction (connector_id, meter_start: int; id_tag: str), on_stop_transaction (meter_stop, transaction_id: int), on_status_notification (connector_id: int; error_code, status: str) N1/m7 - server16.py: document intentional subset scope above _COMMAND_HANDLERS with runtime behavior note N1/INFO - server16.py: add Unix 128+signal comment before sys.exit; expand boot_index one-liner to full NOTE (shared across ALL stations, not per-station) N2 - test_server.py: extend _patch_main with **args_overrides (same pattern as test_server16.py); add test_boot_status_sequence_parsed in TestMainGracefulShutdown — covers server.py:1134-1149 N3 - test_server16.py: add test_boot_status_single_value — covers server16.py:786-787 (elif --boot-status single value branch) N4 - pyproject.toml: update description to cover both 1.6 and 2.0.1 N5 - README.md: remove duplicated sentence at line 38 N6 - test_server16.py: fix RuntimeWarning (coroutine never awaited) in test_commands_sequence_scheduled_on_connect — mock_cp.send_commands was AsyncMock, its coroutine was passed to mocked create_task unrun; replace with MagicMock() to prevent the orphan coroutine Quality gates: 337 passed (0 warnings), format/lint/typecheck clean, coverage 95.95% (+1.17pp) * test(charging-station): relax template file count assertion Replace strictEqual(15) with ok(count >= 15) so adding new station templates does not require updating the hardcoded count. * fix(ocpp-server): address round-3 review findings MAJOR-1 - README.md 2.0.1: add ReserveNow and CancelReservation to Outgoing Commands list; add --reservation-id, --reserve-id-token, --reserve-evse-id flags to Command-specific options; add example command MAJOR-2a - test_server.py: add caplog assertions to 4 signed MeterValue tests (started/updated/ended/meter_values) — verify _log_signed_meter_values actually logs, not just that the handler returns correct type MAJOR-2b - test_server.py: rewrite test_unsupported_command_logs_warning with caplog + assert 'not supported' in log output MAJOR-2c - test_server.py: align 7 empty-response handlers on equality pattern (== EmptyResult()) on top of isinstance — matches test_server16 MINOR-1 - _common.py: add generic parse_commands(str, type[ActionT]) factored from the two identical _parse_commands; both servers now use a one-line wrapper; remove import math from server16/server (now in _common only); coverage 96.76% (+0.81pp) MINOR-2 - server.py: add intentional-subset scope comment above _COMMAND_HANDLERS (mirrors server16.py:451-453) MINOR-3 - server.py:342: (kwargs.get('evse') or {}).get('id', 0) prevents AttributeError when payload carries evse=null explicitly; add regression test test_transaction_event_started_null_evse_defaults_to_zero MINOR-4 - test_server.py: port 3 missing tests from test_server16: - test_unexpected_error_is_caught (covers server.py:782-783) - test_commands_sequence_scheduled_on_connect (covers server.py:866) - test_boot_status_single_value via main() (covers server.py:1151) MINOR-5 - README.md 1.6: enumerate valid --trigger-message types (StatusNotification, BootNotification, Heartbeat, MeterValues, FirmwareStatusNotification, DiagnosticsStatusNotification, LogStatusNotification, SignChargePointCertificate) Quality gates: 341 passed (0 warnings), format/lint/typecheck clean, coverage 96.76% (+0.81pp from 95.95%) * fix(ocpp-server): address round-4 review findings MAJOR-A - README.md 2.0.1: replace invalid --trigger-message value SignCertificate with the 11 exact MessageTriggerEnumType members (SignChargingStationCertificate/SignV2GCertificate/SignCombinedCertificate + TransactionEvent + PublishFirmwareStatusNotification); the 1.6 list was fixed in round-3, this is its 2.0.1 counterpart MAJOR-B - test_server.py: add TestLogSignedMeterValues (3 tests) adapted to 2.0.1 semantics (signed_meter_value field, not format=SignedData); covers the previously-uncovered unsigned branch server.py:97->95 MINOR-C - test_server.py + test_server16.py: 6 error-handling tests (timeout/ocpp_error/unexpected) upgraded from swallowing-only to caplog assertions on level ERROR + message substring MINOR-D - DRY: extract negotiate_subprotocol + install_signal_handlers_and_wait to _common.py (version-agnostic lifecycle, logger passed explicitly to preserve observability); both servers use them; remove import signal from both servers; retarget 4 signal.signal patches to _common. Instance methods (_call_and_log/_send_command/...) and DEFAULT_RESERVATION_* constants left in place (OCPP coupling / locality cost > DRY gain for a test mock) MINOR-E - _common.py to 100%: add non-numeric-delay and empty-entry tests for _parse_commands in both suites INFO MORT-1 - remove unreachable dead code (if not boot_sequence) in both servers' main() INFO-D - server.py: handle_connection_closed(self) -> None annotation Quality gates: 348 passed (0 warnings), format/lint/typecheck clean, coverage 97.51% (+0.75pp); _common.py 100% * test(ocpp-server): close round-5 parity + config findings MINOR parity - test_server.py: assert len(config.charge_points) == 0 on both on_connect rejection tests (missing subprotocol / protocol mismatch), mirroring test_server16.py; guards against a regression registering a ChargePoint on a rejected connection in 2.0.1 MINOR parity - test_server.py: strengthen Heartbeat test_returns_current_time with a freshness window (delta < 60s) + import timezone, mirroring the 1.6 suite (was isinstance + tzinfo only) INFO I4 - pyproject.toml: mypy python_version 3.14 -> 3.12 to match the requires-python floor (>=3.12); mypy stays clean (verified live) INFO I5 - README.md: add the --boot-status shorthand sentence to the 1.6 section for parity with 2.0.1 (identical behavior) Deliberately NOT changed (accepted debt, evidence-based): - DRY mixin for send_command/send_commands/handle_connection_closed: moving them to _common would emit lifecycle logs under _common instead of server/server16 (silent observability regression) for ~24 lines in a mock - mypy test override kept: real guard (test files carry untyped defs) - docstrings on _common helpers: 0/4 documented, keeping style consistent Quality gates: 348 passed, format/lint/typecheck clean (python 3.12), coverage 97.51% * test(ocpp-server): close round-6 parity + hygiene findings MINOR-1 - test_server16.py: add test_parent_id_tag_absent_by_default, mirroring 2.0.1 test_authorize_no_enrichment_by_default; asserts parent_id_tag is absent from id_tag_info under the default AuthConfig (closes the last inter-suite rigor asymmetry) MINOR-2 - server.py: harmonize _call_and_log docstring with server16.py (both now '...based on its status') MINOR-3 - test_server.py: add test_parse_set_variable_specs_skips_empty_entries and test_parse_get_variable_specs_invalid_no_dot, covering the two previously-uncovered branches of _parse_variable_specs (empty-entry skip, require_value=False missing-dot); server.py 875/885 now covered I1 - server.py + server16.py: derive --auth-mode choices/default from the local AuthMode StrEnum ([mode.value for mode in AuthMode] / AuthMode.normal.value) instead of string literals (AGENTS.md: avoid string literals when an enumeration exists); order/content identical (verified live), no behavior change Quality gates: 351 passed, format/lint/typecheck clean (python 3.12), coverage 97.88% (server.py 98%) * test(ocpp-server): close round-7 style + DRY findings - test_server.py: fix stale docstring (20 -> 24 _send_* methods) - server.py/server16.py: --auth-mode type=str -> type=AuthMode to match the sibling enum-typed CLI args (--boot-status, --reset-type, ...); keep choices for unchanged help/UX - server.py/server16.py: extract DEFAULT_WHITELIST/DEFAULT_BLACKLIST module constants (single source of truth; removes __init__/argparse duplication) - test_server.py/test_server16.py: TestHandlerCoverage now asserts @on registration (_on_action) so an undecorated handler is caught * test(ocpp-server): close round-8 findings (harmonize auth-mode, DRY, handler routing) - _common.py: host DEFAULT_WHITELIST/DEFAULT_BLACKLIST as the single source of truth; server.py and server16.py now import them (removes cross-file literal duplication) - server.py/server16.py: drop now-dead choices=list(AuthMode) from --auth-mode and move valid values into the help text, matching the sibling enum-typed args (--boot-status, --reset-type, ...); uniform invalid-value error message - server.py/server16.py: mode=args.auth_mode (args value is already an AuthMode via type=AuthMode; drop redundant re-wrap) - test_server.py/test_server16.py: TestHandlerCoverage now asserts each handler is registered for the CORRECT OCPP action (_on_action == expected), not merely decorated with some @on * test(ocpp-server): address bot review comments on server16 - test_server16.py: use supported CSMS->CS commands (TriggerMessage/Reset) instead of ClearCache/Heartbeat in the send_commands sequencing and _parse_commands tests, so the fixtures reflect commands actually in _COMMAND_HANDLERS rather than unsupported outgoing actions - server.py/server16.py: replace the empty `except KeyboardInterrupt: pass` with contextlib.suppress(KeyboardInterrupt) (clears the empty-except finding without a comment; both servers for parity) - server.py/server16.py: _resolve_auth_status returns default_status via an unconditional trailing return instead of a wildcard `case _`, making the control flow unambiguous to static analysis (both servers for parity)
1 parent db46f9f commit 82ae6d1

9 files changed

Lines changed: 2893 additions & 183 deletions

File tree

‎.serena/project.yml‎

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ ignore_all_files_in_gitignore: true
77

88
# list of additional paths to ignore in this project.
99
# Same syntax as gitignore, so you can use * and **.
10+
# Important: quote patterns that start with `*`, otherwise YAML treats them as aliases.
11+
# Example:
12+
# ignored_paths:
13+
# - "examples/**"
14+
# - ".worktrees/**"
15+
# - "**/bin/**"
16+
# - "**/obj/**"
1017
# Note: global ignored_paths from serena_config.yml are also applied additively.
1118
ignored_paths: []
1219

@@ -56,41 +63,6 @@ included_optional_tools: []
5663
# Find the list of tools here: https://oraios.github.io/serena/01-about/035_tools.html
5764
fixed_tools: []
5865

59-
# list of languages for which language servers are started (LSP backend only); choose from:
60-
# ada al angular ansible bash
61-
# bsl clojure cpp cpp_ccls crystal
62-
# csharp csharp_omnisharp cue dart elixir
63-
# elm erlang fortran fsharp gdscript
64-
# go groovy haskell haxe hlsl
65-
# html java json julia kotlin
66-
# latex lean4 lua luau markdown
67-
# matlab msl nix ocaml pascal
68-
# perl php php_phpactor php_phpantom powershell
69-
# python python_jedi python_pyrefly python_ty r
70-
# rego ruby ruby_solargraph rust scala
71-
# scss solidity svelte swift systemverilog
72-
# terraform toml typescript typescript_vts vue
73-
# yaml zig
74-
# (This list may be outdated; generated with scripts/print_language_list.py;
75-
# For the current list, see values of Language enum here:
76-
# https://github.com/oraios/serena/blob/main/src/solidlsp/ls_config.py)
77-
# For some languages, there are alternative language servers, e.g. csharp_omnisharp, ruby_solargraph.)
78-
# Note:
79-
# - For C, use cpp
80-
# - For JavaScript, use typescript
81-
# - For Angular projects, use angular (subsumes typescript+html; requires `npm install` in the project root)
82-
# - For Svelte projects, use svelte (subsumes typescript/javascript for .svelte projects; requires npm)
83-
# - For SCSS / Sass / plain CSS, use scss (some-sass-language-server handles all three)
84-
# - For Free Pascal/Lazarus, use pascal
85-
# Special requirements:
86-
# Some languages require additional setup/installations.
87-
# See here for details: https://oraios.github.io/serena/01-about/020_programming-languages.html#language-servers
88-
# When using multiple languages, the first language server that supports a given file will be used for that file.
89-
# The first language is the default language and the respective language server will be used as a fallback.
90-
# Note that when using the JetBrains backend, language servers are not used and this list is correspondingly ignored.
91-
languages:
92-
- typescript
93-
9466
# time budget (seconds) per tool call for the retrieval of additional symbol information
9567
# such as docstrings or parameter information.
9668
# This overrides the corresponding setting in the global configuration; see the documentation there.
@@ -167,3 +139,38 @@ activation_command:
167139
# maximum time in seconds to wait for activation_command to complete before killing it (default 180s).
168140
# must be a positive number.
169141
activation_command_timeout: 180.0
142+
143+
# list of language servers to start when using the LSP backend; choose from:
144+
# ada al angular ansible bash
145+
# bsl clojure cpp cpp_ccls crystal
146+
# csharp csharp_omnisharp cue dart elixir
147+
# elm erlang fortran fsharp gdscript
148+
# go groovy haskell haxe hlsl
149+
# html java json julia kotlin
150+
# latex lean4 lua luau markdown
151+
# matlab msl nix ocaml pascal
152+
# perl php php_phpactor php_phpantom powershell
153+
# python python_basedpyright python_jedi python_pyrefly python_ty
154+
# qml r rego ruby ruby_solargraph
155+
# rust scala scss solidity svelte
156+
# swift systemverilog terraform toml typescript
157+
# typescript_vts vue yaml zig
158+
# (This list may be outdated; generated with scripts/print_language_list.py;
159+
# For the current list, see values of the LanguageServerId enum here:
160+
# https://github.com/oraios/serena/blob/main/src/solidlsp/ls_config.py)
161+
# For some languages, there are several alternative language servers, e.g. csharp_omnisharp, ruby_solargraph.)
162+
# Note:
163+
# - For C, use cpp
164+
# - For JavaScript, use typescript
165+
# - For Angular projects, use angular (subsumes typescript+html; requires `npm install` in the project root)
166+
# - For Svelte projects, use svelte (subsumes typescript/javascript for .svelte projects; requires npm)
167+
# - For SCSS / Sass / plain CSS, use scss (some-sass-language-server handles all three)
168+
# - For Free Pascal/Lazarus, use pascal
169+
# Special requirements:
170+
# Some language servers require additional setup/installations.
171+
# See here for details: https://oraios.github.io/serena/01-about/020_programming-languages.html#language-servers
172+
# When using multiple language servers, the first language server that supports a given file will be used for that file.
173+
# The first language server is the default language and the respective language server will be used as a fallback.
174+
# Note that when using the JetBrains backend, language servers are not used and this list is correspondingly ignored.
175+
language_servers:
176+
- typescript

‎tests/charging-station/TemplateValidation.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,16 @@ await describe('TemplateValidation', async () => {
279279
})
280280

281281
await describe('all template files round-trip', async () => {
282-
await it('should validate all 15 station template files through the pipeline', async t => {
282+
await it('should validate all station template files through the pipeline', async t => {
283283
mockLoggerWarnDebug(t, logger)
284284
const fs = await import('node:fs')
285285
const path = await import('node:path')
286286
const templateDir = path.join(import.meta.dirname, '../../src/assets/station-templates')
287287
const files = fs.readdirSync(templateDir).filter(f => f.endsWith('.json'))
288-
assert.strictEqual(files.length, 15)
288+
assert.ok(
289+
files.length >= 15,
290+
`expected at least 15 template files, found ${String(files.length)}`
291+
)
289292

290293
for (const file of files) {
291294
const content = fs.readFileSync(path.join(templateDir, file), 'utf8')

‎tests/ocpp-server/README.md‎

Lines changed: 144 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
# OCPP2 Mock Server
1+
# OCPP Mock Servers
22

3-
An OCPP 2.0.1 mock CSMS (Central System Management System) for end-to-end testing of charging station simulators.
3+
Mock CSMS (Central System Management System) servers for end-to-end testing of charging station simulators:
4+
5+
- **`server.py`** — OCPP 2.0.1 mock CSMS
6+
- **`server16.py`** — OCPP 1.6 mock CSMS
47

58
## Prerequisites
69

@@ -18,13 +21,21 @@ Then install dependencies:
1821
poetry install --no-root
1922
```
2023

21-
## Running the Server
24+
## Running the Servers
25+
26+
OCPP 2.0.1:
2227

2328
```shell
2429
poetry run python server.py
2530
```
2631

27-
The server listens on `127.0.0.1:9000` by default.
32+
OCPP 1.6:
33+
34+
```shell
35+
poetry run python server16.py
36+
```
37+
38+
Both servers listen on `127.0.0.1:9000` by default.
2839

2940
## Configuration
3041

@@ -103,7 +114,7 @@ poetry run python server.py --commands "RequestStartTransaction:5,RequestStopTra
103114
These flags customize the payload of specific commands:
104115

105116
- `--trigger-message <TYPE>`: TriggerMessage requested message type (default: `StatusNotification`)
106-
- `StatusNotification`, `BootNotification`, `Heartbeat`, `MeterValues`, `FirmwareStatusNotification`, `LogStatusNotification`, `SignCertificate`
117+
- `StatusNotification`, `BootNotification`, `Heartbeat`, `MeterValues`, `FirmwareStatusNotification`, `LogStatusNotification`, `PublishFirmwareStatusNotification`, `TransactionEvent`, `SignChargingStationCertificate`, `SignV2GCertificate`, `SignCombinedCertificate`
107118
- `--reset-type <TYPE>`: Reset type (default: `Immediate`)
108119
- `Immediate` — Reset now
109120
- `OnIdle` — Reset when no transaction is active
@@ -113,6 +124,9 @@ These flags customize the payload of specific commands:
113124
- `--set-variables <SPECS>`: SetVariables data as `Component.Variable=Value,...` (values must not contain commas)
114125
- `--get-variables <SPECS>`: GetVariables data as `Component.Variable,...`
115126
- `--local-list-tokens TOKEN ...`: Tokens to include in SendLocalList (default: test token)
127+
- `--reservation-id <ID>`: ReserveNow/CancelReservation reservation id (default: `1`)
128+
- `--reserve-id-token <TOKEN>`: ReserveNow id_token value the reservation is bound to (default: `reserved_token`)
129+
- `--reserve-evse-id <ID>`: ReserveNow target EVSE id (default: `1`)
116130

117131
```shell
118132
poetry run python server.py --command TriggerMessage --trigger-message BootNotification --delay 5
@@ -122,12 +136,14 @@ poetry run python server.py --command SetVariables --delay 5 \
122136
--set-variables "OCPPCommCtrlr.HeartbeatInterval=30,TxCtrlr.EVConnectionTimeOut=60"
123137
poetry run python server.py --command GetLocalListVersion --delay 5
124138
poetry run python server.py --command SendLocalList --delay 5 --local-list-tokens token1 token2
139+
poetry run python server.py --command ReserveNow --reserve-evse-id 1 --reserve-id-token mytag --reservation-id 42 --delay 5
125140
```
126141

127142
## Supported OCPP 2.0.1 Messages
128143

129144
### Outgoing Commands (CSMS → CS)
130145

146+
- `CancelReservation` — Cancel a reservation
131147
- `CertificateSigned` — Send a signed certificate to the charging station
132148
- `ChangeAvailability` — Change connector availability
133149
- `ClearCache` — Clear the charging station cache
@@ -143,6 +159,7 @@ poetry run python server.py --command SendLocalList --delay 5 --local-list-token
143159
- `InstallCertificate` — Install a CA certificate
144160
- `RequestStartTransaction` — Remote start a transaction
145161
- `RequestStopTransaction` — Remote stop a transaction
162+
- `ReserveNow` — Reserve an EVSE
146163
- `Reset` — Reset the charging station
147164
- `SendLocalList` — Send a local authorization list update
148165
- `SetNetworkProfile` — Set the network connection profile
@@ -173,6 +190,128 @@ poetry run python server.py --command SendLocalList --delay 5 --local-list-token
173190

174191
The server tracks active transaction IDs from `TransactionEvent.Started` and uses real IDs in `RequestStopTransaction` and `GetTransactionStatus`. Falls back to a test ID when no transaction is active.
175192

193+
## OCPP 1.6 Server (`server16.py`)
194+
195+
An OCPP 1.6 mock CSMS. Runs independently of the 2.0.1 server; both share the same CLI conventions.
196+
197+
### Server
198+
199+
- `--host <HOST>`: Bind address (default: `127.0.0.1`)
200+
- `--port <PORT>`: Listening port (default: `9000`)
201+
- `--connector-id <ID>`: Connector id used in CSMS→CS commands (default: `1`)
202+
203+
### Boot Behavior
204+
205+
- `--boot-status <STATUS>`: Fixed BootNotification response status (default: `Accepted`)
206+
- `Accepted` — Station registered
207+
- `Pending` — Station not yet registered, must retry
208+
- `Rejected` — Station rejected, must retry
209+
- `--boot-status-sequence <SEQ>`: Comma-separated status sequence (e.g., `Pending,Pending,Accepted`). Returns the next status on each BootNotification, stays on the last value once exhausted.
210+
211+
`--boot-status` and `--boot-status-sequence` are mutually exclusive. `--boot-status X` is shorthand for `--boot-status-sequence X`.
212+
213+
```shell
214+
poetry run python server16.py --boot-status Rejected
215+
poetry run python server16.py --boot-status-sequence Pending,Pending,Accepted
216+
```
217+
218+
### Authorization
219+
220+
- `--auth-mode <MODE>`: Authorization mode (default: `normal`)
221+
- `normal` — Accept all id tags
222+
- `whitelist` — Only accept id tags in the whitelist
223+
- `blacklist` — Block id tags in the blacklist, accept all others
224+
- `--whitelist TAG ...`: Authorized id tags (default: `valid_token test_token authorized_user`)
225+
- `--blacklist TAG ...`: Blocked id tags (default: `blocked_token invalid_user`)
226+
- `--offline`: Simulate network failure (raises `InternalError` on Authorize)
227+
- `--auth-parent-id-tag <TAG>`: Include `parentIdTag` in Authorize and StartTransaction responses (default: none)
228+
229+
```shell
230+
poetry run python server16.py --auth-mode whitelist --whitelist valid_token test_token
231+
poetry run python server16.py --auth-mode blacklist --blacklist blocked_token
232+
poetry run python server16.py --offline
233+
poetry run python server16.py --auth-parent-id-tag ParentTag
234+
```
235+
236+
### OCPP Commands
237+
238+
Send CSMS-initiated commands to connected charging stations.
239+
240+
#### Single command
241+
242+
- `--command <NAME>`: OCPP command to send (see supported commands below)
243+
- `--delay <SEC>`: One-shot delay before sending (mutually exclusive with `--period`)
244+
- `--period <SEC>`: Repeat interval in seconds (mutually exclusive with `--delay`)
245+
246+
`--delay` or `--period` is required when `--command` is specified.
247+
248+
```shell
249+
poetry run python server16.py --command Reset --delay 5
250+
poetry run python server16.py --command TriggerMessage --period 10
251+
```
252+
253+
#### Command sequence
254+
255+
- `--commands <SEQ>`: Comma-separated `CMD:DELAY` pairs, executed sequentially (e.g., `RemoteStartTransaction:5,RemoteStopTransaction:30`)
256+
257+
Mutually exclusive with `--command`.
258+
259+
```shell
260+
poetry run python server16.py --commands "RemoteStartTransaction:5,RemoteStopTransaction:30"
261+
```
262+
263+
#### Command-specific options
264+
265+
- `--trigger-message <TYPE>`: TriggerMessage requested message type (default: `StatusNotification`)
266+
- `StatusNotification`, `BootNotification`, `Heartbeat`, `MeterValues`, `FirmwareStatusNotification`, `DiagnosticsStatusNotification`, `LogStatusNotification`, `SignChargePointCertificate`
267+
- `--reset-type <TYPE>`: Reset type (default: `Hard`)
268+
- `Hard` — Reset now
269+
- `Soft` — Graceful reset
270+
- `--availability-type <TYPE>`: ChangeAvailability type (default: `Operative`)
271+
- `Operative` — Connector available
272+
- `Inoperative` — Connector unavailable
273+
- `--reserve-connector-id <ID>`: ReserveNow connector id (default: `1`)
274+
- `--reserve-id-tag <TAG>`: ReserveNow id tag reserving the connector (default: `reserved_tag`)
275+
- `--reservation-id <ID>`: ReserveNow/CancelReservation reservation id (default: `1`)
276+
277+
```shell
278+
poetry run python server16.py --command TriggerMessage --trigger-message BootNotification --delay 5
279+
poetry run python server16.py --command Reset --reset-type Soft --delay 5
280+
poetry run python server16.py --command ChangeAvailability --availability-type Inoperative --delay 5
281+
poetry run python server16.py --command ReserveNow --reserve-connector-id 1 --reserve-id-tag mytag --reservation-id 42 --delay 5
282+
```
283+
284+
### Supported OCPP 1.6 Messages
285+
286+
#### Outgoing Commands (CSMS → CS)
287+
288+
- `TriggerMessage` — Trigger a specific message from the station
289+
- `RemoteStartTransaction` — Remote start a transaction
290+
- `RemoteStopTransaction` — Remote stop a transaction
291+
- `Reset` — Reset the charging station
292+
- `ChangeAvailability` — Change connector availability
293+
- `UpdateFirmware` — Request firmware update
294+
- `GetDiagnostics` — Request diagnostics upload
295+
- `ReserveNow` — Reserve a connector
296+
- `CancelReservation` — Cancel a reservation
297+
298+
#### Incoming Handlers (CS → CSMS)
299+
300+
- `Authorize` — Handle authorization requests (configurable auth modes)
301+
- `BootNotification` — Handle boot notification (configurable status sequence)
302+
- `Heartbeat` — Handle heartbeat messages
303+
- `StartTransaction` — Handle transaction start
304+
- `StopTransaction` — Handle transaction stop (logs signed transaction data)
305+
- `MeterValues` — Handle meter value reports (logs `SignedData`-format samples)
306+
- `StatusNotification` — Handle connector status notifications
307+
- `DataTransfer` — Handle vendor-specific data transfer
308+
- `FirmwareStatusNotification` — Handle firmware update status
309+
- `DiagnosticsStatusNotification` — Handle diagnostics upload status
310+
311+
### Transaction Tracking
312+
313+
The server tracks active transaction IDs from `StartTransaction` and uses real IDs in `RemoteStopTransaction`. Falls back to transaction ID `1` when no transaction is active.
314+
176315
## Development
177316

178317
### Code formatting

0 commit comments

Comments
 (0)