# SPDX-License-Identifier: MIT
# Copyright (c) 2025 Hammerheads Engineers Sp. z o.o.
# See the accompanying LICENSE file for terms.

name: evse_ocpp16j_independent_20261114_1621
description: |
  Standalone OCPP 1.6J charge-point simulation for protocol verification.
  Charging telemetry follows the local enable and current controls. This
  model does not send StartTransaction or StopTransaction.

meta_parameters:
  ocpp_endpoint:
    type: str
    default: "ws://localhost:9000/ocpp"
  ocpp_subprotocol:
    type: str
    default: "ocpp1.6"
  ocpp_charge_point_id:
    type: str
    default: "independent-evse-20261114-1621"

attributes:
  cp_vendor:
    type: str
    default: "SPX Independent Test"
  cp_model:
    type: str
    default: "OCPP16J-EVSE"
  cp_serial:
    type: str
    default: "INDEPENDENT-EVSE-1621"
  cp_firmware_version:
    type: str
    default: "1.0.0"
  cp_status_info:
    type: str
    default: "independent test EVSE"
  k__charging_enabled:
    type: int
    default: 0
  k__commanded_current_a:
    type: float
    default: 16.0
    unit: A
  k__max_current_a:
    type: float
    default: 32.0
    unit: A
  voltage_v:
    type: float
    default: 230.0
    unit: V
  current_a:
    type: float
    default: 0.0
    unit: A
  power_kw:
    type: float
    default: 0.0
    unit: kW
  energy_total_wh:
    type: float
    default: 0.0
    unit: Wh
  connector_status:
    type: str
    default: "Available"
  error_code:
    type: str
    default: "NoError"
  boot_status:
    type: str
    default: ""
  csms_current_time:
    type: str
    default: "2025-01-01T00:00:00Z"
  heartbeat_interval_s:
    type: int
    default: 30
    unit: s
  meter_values:
    type: list
    default: []
  _previous_time_s:
    type: float
    default: 0.0
    unit: s
  _elapsed_step_s:
    type: float
    default: 0.0
    unit: s

actions:
  - function: $in(_elapsed_step_s)
    name: calculate_elapsed_time
    call: max(0.0, $in(__timer) - $in(_previous_time_s))
  - function: $in(_previous_time_s)
    name: save_elapsed_time
    call: $in(__timer)
  - function: $in(connector_status)
    name: update_connector_status
    call: '"Charging" if $in(k__charging_enabled) == 1 else "Available"'
  - function: $in(current_a)
    name: apply_current_command
    call: max(0.0, min($in(k__max_current_a), $in(k__commanded_current_a))) if $in(k__charging_enabled) == 1 else 0.0
  - function: $in(power_kw)
    name: calculate_power
    call: round($in(voltage_v) * $in(current_a) / 1000.0, 3)
  - function: $in(energy_total_wh)
    name: integrate_energy
    call: $in(energy_total_wh) + ($in(power_kw) * 1000.0 * $in(_elapsed_step_s) / 3600.0)
  - function: $in(meter_values)
    name: prepare_meter_values
    call: |
      [{
        "timestamp": $in(csms_current_time),
        "sampledValue": [
          {"value": str(round($in(energy_total_wh), 1)), "measurand": "Energy.Active.Import.Register", "unit": "Wh"},
          {"value": str(round($in(power_kw) * 1000.0, 1)), "measurand": "Power.Active.Import", "unit": "W"},
          {"value": str(round($in(current_a), 2)), "measurand": "Current.Import", "unit": "A"},
          {"value": str(round($in(voltage_v), 1)), "measurand": "Voltage", "unit": "V"}
        ]
      }]

communication:
  - ocpp:
      role: charge_point
      endpoint: "$param(ocpp_endpoint)"
      subprotocol: "$param(ocpp_subprotocol)"
      charge_point_id: "$param(ocpp_charge_point_id)"
      bindings:
        send_boot_notification:
          direction: outbound
          frame_type: call
          action: BootNotification
          payload:
            chargePointVendor: "#attr(cp_vendor)"
            chargePointModel: "#attr(cp_model)"
            chargePointSerialNumber: "#attr(cp_serial)"
            firmwareVersion: "#attr(cp_firmware_version)"
        receive_boot_notification:
          direction: inbound
          frame_type: call_result
          action: BootNotification
          payload:
            status: "#attr(boot_status)"
            currentTime: "#attr(csms_current_time)"
            interval: "#attr(heartbeat_interval_s)"
        send_heartbeat:
          direction: outbound
          frame_type: call
          action: Heartbeat
          interval: 30.0
          payload: {}
        receive_heartbeat:
          direction: inbound
          frame_type: call_result
          action: Heartbeat
          payload:
            currentTime: "#attr(csms_current_time)"
        send_status_notification:
          direction: outbound
          frame_type: call
          action: StatusNotification
          interval: 6.0
          payload:
            connectorId: 1
            status: "#attr(connector_status)"
            errorCode: "#attr(error_code)"
            info: "#attr(cp_status_info)"
            vendorId: "#attr(cp_vendor)"
        receive_status_notification:
          direction: inbound
          frame_type: call_result
          action: StatusNotification
          payload: {}
        send_meter_values:
          direction: outbound
          frame_type: call
          action: MeterValues
          interval: 5.0
          payload:
            connectorId: 1
            meterValue: "#attr(meter_values)"
        receive_meter_values:
          direction: inbound
          frame_type: call_result
          action: MeterValues
          payload: {}

scenarios:
  enabled_charging_telemetry:
    enabled: false
    display_name: "Enabled Charging Telemetry"
    description: Enable simulated current, power, and energy telemetry without an OCPP transaction.
    duration: 30.0
    overrides:
      $in(k__charging_enabled): 1
      $in(k__commanded_current_a): 16.0
