From d5cd0d89f8b4a2de66c7435bc6119953a819ca37 Mon Sep 17 00:00:00 2001 From: Lior Ben Ari Date: Mon, 25 Dec 2023 11:16:11 +0200 Subject: [PATCH 01/10] Objects for Tokens authorization logic --- .../Token/AuthorizationInfo.cs | 41 +++++++++++++++++++ .../Token/LocationReferences.cs | 29 +++++++++++++ src/OCPI.Net.Core/Enums/Token/AllowedType.cs | 41 +++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 src/OCPI.Net.Contracts/Token/AuthorizationInfo.cs create mode 100644 src/OCPI.Net.Contracts/Token/LocationReferences.cs create mode 100644 src/OCPI.Net.Core/Enums/Token/AllowedType.cs diff --git a/src/OCPI.Net.Contracts/Token/AuthorizationInfo.cs b/src/OCPI.Net.Contracts/Token/AuthorizationInfo.cs new file mode 100644 index 0000000..5ef921d --- /dev/null +++ b/src/OCPI.Net.Contracts/Token/AuthorizationInfo.cs @@ -0,0 +1,41 @@ +using System.Text.Json.Serialization; + +namespace OCPI.Contracts; + +public class AuthorizationInfo +{ + /// + /// Status of the Token, and whether charging is allowed at the optionally + /// given location. + /// + [JsonPropertyName("allowed")] + public AllowedType Allowed { get; set; } + + /// + /// The complete Token object for which this authorization was requested. + /// + [JsonPropertyName("token")] + public OcpiToken Token { get; set; } + + /// + /// Optional reference to the location if it was included in the request, and if + /// the EV driver is allowed to charge at that location.Only the EVSEs the + /// EV driver is allowed to charge at are returned. + /// + [JsonPropertyName("location")] + public LocationReferences? LocationReferences { get; set; } + + /// + /// Reference to the authorization given by the eMSP, when given, this + /// reference will be provided in the relevant Session and/or CDR. + /// + [JsonPropertyName("authorization_reference")] + public string? AuthorizationReference { get; set; } + + /// + /// Optional display text, additional information to the EV driver. + /// + [JsonPropertyName("info")] + public OcpiDisplayText? Info { get; set; } + +} \ No newline at end of file diff --git a/src/OCPI.Net.Contracts/Token/LocationReferences.cs b/src/OCPI.Net.Contracts/Token/LocationReferences.cs new file mode 100644 index 0000000..908fc56 --- /dev/null +++ b/src/OCPI.Net.Contracts/Token/LocationReferences.cs @@ -0,0 +1,29 @@ +using System.Text.Json.Serialization; + +namespace OCPI.Contracts; + +public class LocationReferences +{ + /// + /// Unique identifier for the location. + /// + [JsonPropertyName("location_id")] + public string LocationId { get; set; } + + /// + /// Unique identifiers for EVSEs within the CPO’s platform for the EVSE within the + /// given location. + /// + [JsonPropertyName("evse_uids")] + public string? EvseUids { get; set; } + + //==================== Deprecated in OCPI 2.2 ======================== + + /// + /// Identifies the connectors within the given EVSEs. + /// + [OcpiDeprecated(after: "2.1.1")] + [JsonPropertyName("connector_ids")] + public string? ConnectorIds { get; set; } + +} \ No newline at end of file diff --git a/src/OCPI.Net.Core/Enums/Token/AllowedType.cs b/src/OCPI.Net.Core/Enums/Token/AllowedType.cs new file mode 100644 index 0000000..741c942 --- /dev/null +++ b/src/OCPI.Net.Core/Enums/Token/AllowedType.cs @@ -0,0 +1,41 @@ +using System.Runtime.Serialization; + +namespace OCPI; + +public enum AllowedType : byte +{ + //====================1x: Allowed======================== + /// + /// This Token is allowed to charge (at this location). + /// + [EnumMember(Value = "ALLOWED")] + Allowed = 11, + + //====================2x: Not Allowed======================== + + /// + /// This Token is blocked. + /// + [EnumMember(Value = "BLOCKED")] + Blocked = 21, + + /// + /// This Token has expired. + /// + [EnumMember(Value = "EXPIRED")] + Expired = 22, + + /// + /// This Token belongs to an account that has not enough credits to charge (at the given location). + /// + [EnumMember(Value = "NO_CREDIT")] + NoCredit = 23, + + /// + /// Token is valid, but is not allowed to charge at the given location. + /// + [EnumMember(Value = "NOT_ALLOWED")] + NotAllowed = 24 + + +} \ No newline at end of file From 82e9e26e77476dea35efe561408a657863c9590f Mon Sep 17 00:00:00 2001 From: Lior Ben Ari Date: Mon, 25 Dec 2023 11:18:29 +0200 Subject: [PATCH 02/10] add new lines at end of files --- src/OCPI.Net.Contracts/Token/AuthorizationInfo.cs | 3 +-- src/OCPI.Net.Contracts/Token/LocationReferences.cs | 2 +- src/OCPI.Net.Core/Enums/Token/AllowedType.cs | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/OCPI.Net.Contracts/Token/AuthorizationInfo.cs b/src/OCPI.Net.Contracts/Token/AuthorizationInfo.cs index 5ef921d..dcf3d54 100644 --- a/src/OCPI.Net.Contracts/Token/AuthorizationInfo.cs +++ b/src/OCPI.Net.Contracts/Token/AuthorizationInfo.cs @@ -37,5 +37,4 @@ public class AuthorizationInfo /// [JsonPropertyName("info")] public OcpiDisplayText? Info { get; set; } - -} \ No newline at end of file +} diff --git a/src/OCPI.Net.Contracts/Token/LocationReferences.cs b/src/OCPI.Net.Contracts/Token/LocationReferences.cs index 908fc56..56a8434 100644 --- a/src/OCPI.Net.Contracts/Token/LocationReferences.cs +++ b/src/OCPI.Net.Contracts/Token/LocationReferences.cs @@ -25,5 +25,5 @@ public class LocationReferences [OcpiDeprecated(after: "2.1.1")] [JsonPropertyName("connector_ids")] public string? ConnectorIds { get; set; } +} -} \ No newline at end of file diff --git a/src/OCPI.Net.Core/Enums/Token/AllowedType.cs b/src/OCPI.Net.Core/Enums/Token/AllowedType.cs index 741c942..17323fe 100644 --- a/src/OCPI.Net.Core/Enums/Token/AllowedType.cs +++ b/src/OCPI.Net.Core/Enums/Token/AllowedType.cs @@ -36,6 +36,5 @@ public enum AllowedType : byte /// [EnumMember(Value = "NOT_ALLOWED")] NotAllowed = 24 +} - -} \ No newline at end of file From e5056796d236f34af368b7b247f22465924ce6b2 Mon Sep 17 00:00:00 2001 From: Lior Ben Ari Date: Tue, 6 Feb 2024 17:23:10 +0200 Subject: [PATCH 03/10] Smart Charging - SetChargingProfile object and data types --- .../ChargingProfiles/ChargingProfile.cs | 47 +++++++++++++++++++ .../ChargingProfiles/ChargingProfilePeriod.cs | 20 ++++++++ .../ChargingProfileResponse.cs | 18 +++++++ .../ChargingProfiles/SetChargingProfile.cs | 19 ++++++++ .../ChargingProfileResponseType.cs | 43 +++++++++++++++++ .../Enums/SmartCharging/ChargingRateUnit.cs | 28 +++++++++++ 6 files changed, 175 insertions(+) create mode 100644 src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs create mode 100644 src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfilePeriod.cs create mode 100644 src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfileResponse.cs create mode 100644 src/OCPI.Net.Contracts/ChargingProfiles/SetChargingProfile.cs create mode 100644 src/OCPI.Net.Core/Enums/SmartCharging/ChargingProfileResponseType.cs create mode 100644 src/OCPI.Net.Core/Enums/SmartCharging/ChargingRateUnit.cs diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs new file mode 100644 index 0000000..dd18adb --- /dev/null +++ b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs @@ -0,0 +1,47 @@ +using System.Text.Json.Serialization; +using OCPI.Enums.SmartCharging; + +namespace OCPI.Contracts.ChargingProfiles; + +public class ChargingProfile +{ + /// + /// Starting point of an absolute profile. If absent the profile + /// will be relative to start of charging. + /// + [JsonPropertyName("start_date_time")] + public DateTime? StartDateTime { get; set; } + + /// + /// Duration of the charging profile in seconds. If the + /// duration is left empty, the last period will continue + /// indefinitely or until end of the transaction in case + /// start_date_time is absent. + /// + [JsonPropertyName("duration")] + public int? Duration { get; set; } + + /// + /// The unit of measure. + /// + [JsonPropertyName("charging_rate_unit")] + public required ChargingRateUnit ChargingRateUnit { get; set; } + + /// + /// Minimum charging rate supported by the EV. The unit + /// of measure is defined by the chargingRateUnit.This + /// parameter is intended to be used by a local smart + /// charging algorithm to optimize the power allocation for + /// in the case a charging process is inefficient at lower + /// charging rates.Accepts at most one digit fraction. + /// + [JsonPropertyName("min_charging_rate")] + public decimal? MinChargingRate { get; set; } + + /// + /// List of ChargingProfilePeriod elements defining + /// maximum power or current usage over time. + /// + [JsonPropertyName("charging_profile_period")] + public IEnumerable? ChargingProfilePeriod { get; set; } +} \ No newline at end of file diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfilePeriod.cs b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfilePeriod.cs new file mode 100644 index 0000000..3f55b34 --- /dev/null +++ b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfilePeriod.cs @@ -0,0 +1,20 @@ +using System.Text.Json.Serialization; + +namespace OCPI.Contracts.ChargingProfiles; + +public class ChargingProfilePeriod +{ + /// + /// Start of the period, in seconds from the start of profile. The value of StartPeriod + /// also defines the stop time of the previous period. + /// + [JsonPropertyName("start_period")] + public required int StartPeriod { get; set; } + + /// + /// Charging rate limit during the profile period, in the applicable chargingRateUnit, + /// for example in Amperes(A) or Watts(W). Accepts at most one digit fraction. + /// + [JsonPropertyName("limit")] + public required decimal Limit { get; set; } +} \ No newline at end of file diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfileResponse.cs b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfileResponse.cs new file mode 100644 index 0000000..4550897 --- /dev/null +++ b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfileResponse.cs @@ -0,0 +1,18 @@ +using System.Text.Json.Serialization; +using OCPI.Enums.SmartCharging; + +namespace OCPI.Contracts.ChargingProfiles; +public class ChargingProfileResponse +{ + /// + /// Response from the CPO on the ChargingProfile request. + /// + [JsonPropertyName("result")] + public required ChargingProfileResponseType Result { get; set; } + + /// + /// Response from the CPO on the ChargingProfile request. + /// + [JsonPropertyName("timeout")] + public required int Timeout { get; set; } +} \ No newline at end of file diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/SetChargingProfile.cs b/src/OCPI.Net.Contracts/ChargingProfiles/SetChargingProfile.cs new file mode 100644 index 0000000..4ae6804 --- /dev/null +++ b/src/OCPI.Net.Contracts/ChargingProfiles/SetChargingProfile.cs @@ -0,0 +1,19 @@ +using System.Text.Json.Serialization; + +namespace OCPI.Contracts.ChargingProfiles; +public class SetChargingProfile +{ + /// + /// Contains limits for the available power or current over time. + /// + [JsonPropertyName("charging_profile")] + public required ChargingProfile ChargingProfile { get; set; } = null!; + + /// + /// URL that the ChargingProfileResult POST should be send to. This + /// URL might contain an unique ID to be able to distinguish between + /// GET ActiveChargingProfile requests. + /// + [JsonPropertyName("response_url")] + public required string ResponseUrl { get; set; } = null!; +} \ No newline at end of file diff --git a/src/OCPI.Net.Core/Enums/SmartCharging/ChargingProfileResponseType.cs b/src/OCPI.Net.Core/Enums/SmartCharging/ChargingProfileResponseType.cs new file mode 100644 index 0000000..8f4035c --- /dev/null +++ b/src/OCPI.Net.Core/Enums/SmartCharging/ChargingProfileResponseType.cs @@ -0,0 +1,43 @@ +using System.Runtime.Serialization; + +namespace OCPI.Enums.SmartCharging; + +public enum ChargingProfileResponseType : byte +{ + //====================1x: Success======================== + + /// + /// ChargingProfile request accepted by the CPO, request will be forwarded to the EVSE. + /// + [EnumMember(Value = "ACCEPTED")] + Accepted = 11, + + //====================2x: Rejected======================== + + /// + /// ChargingProfile request rejected by the CPO. (Session might not be from a customer of the eMSP + /// that send this request) + /// + [EnumMember(Value = "REJECTED")] + Rejected = 21, + + /// + /// ChargingProfile request rejected by the CPO, requests are send more often then allowed. + /// + [EnumMember(Value = "TOO_OFTEN")] + TooOften = 22, + + //====================3x: Fail======================== + + /// + /// The ChargingProfiles not supported by this CPO, Charge Point, EVSE etc. + /// + [EnumMember(Value = "NOT_SUPPORTED")] + NotSupported = 31, + + /// + /// The Session in the requested command is not known by this CPO. + /// + [EnumMember(Value = "UNKNOWN_SESSION")] + UnknownSession = 32, +} \ No newline at end of file diff --git a/src/OCPI.Net.Core/Enums/SmartCharging/ChargingRateUnit.cs b/src/OCPI.Net.Core/Enums/SmartCharging/ChargingRateUnit.cs new file mode 100644 index 0000000..015bbdc --- /dev/null +++ b/src/OCPI.Net.Core/Enums/SmartCharging/ChargingRateUnit.cs @@ -0,0 +1,28 @@ +using System.Runtime.Serialization; + +namespace OCPI.Enums.SmartCharging; + +public enum ChargingRateUnit : byte +{ + /// + /// Watts (power) + /// This is the TOTAL allowed charging power. If used for AC Charging, the phase current should be + /// calculated via: Current per phase = Power / (Line Voltage * Number of Phases). The "Line Voltage" + /// used in the calculation is the Line to Neutral Voltage (VLN). In Europe and Asia VLN is typically + /// 220V or 230V and the corresponding Line to Line Voltage (VLL) is 380V and 400V. The "Number of + /// Phases" is the numberPhases from the ChargingProfilePeriod. It is usually more convenient to use + /// this for DC charging. Note that if numberPhases in a ChargingProfilePeriod is absent, 3 SHALL be + /// assumed. + /// + [EnumMember(Value = "W")] + Watts = 11, + + /// + /// Amperes (current) + /// The amount of Ampere per phase, not the sum of all phases. It is usually more convenient to use + /// this for AC charging. + /// + [EnumMember(Value = "A")] + Amperes = 12, + +} \ No newline at end of file From 7f815d68e2a751c13493448bb6074c2846ed3691 Mon Sep 17 00:00:00 2001 From: Lior Ben Ari Date: Tue, 6 Feb 2024 17:25:38 +0200 Subject: [PATCH 04/10] new lines at end of files --- src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs | 2 +- .../ChargingProfiles/ChargingProfilePeriod.cs | 2 +- .../ChargingProfiles/ChargingProfileResponse.cs | 2 +- src/OCPI.Net.Contracts/ChargingProfiles/SetChargingProfile.cs | 2 +- .../ChargingProfileResponseType.cs | 2 +- .../{SmartCharging => ChargingProfiles}/ChargingRateUnit.cs | 3 +-- 6 files changed, 6 insertions(+), 7 deletions(-) rename src/OCPI.Net.Core/Enums/{SmartCharging => ChargingProfiles}/ChargingProfileResponseType.cs (99%) rename src/OCPI.Net.Core/Enums/{SmartCharging => ChargingProfiles}/ChargingRateUnit.cs (99%) diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs index dd18adb..4f2029d 100644 --- a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs +++ b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs @@ -44,4 +44,4 @@ public class ChargingProfile /// [JsonPropertyName("charging_profile_period")] public IEnumerable? ChargingProfilePeriod { get; set; } -} \ No newline at end of file +} diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfilePeriod.cs b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfilePeriod.cs index 3f55b34..d161e11 100644 --- a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfilePeriod.cs +++ b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfilePeriod.cs @@ -17,4 +17,4 @@ public class ChargingProfilePeriod /// [JsonPropertyName("limit")] public required decimal Limit { get; set; } -} \ No newline at end of file +} diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfileResponse.cs b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfileResponse.cs index 4550897..ab198d1 100644 --- a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfileResponse.cs +++ b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfileResponse.cs @@ -15,4 +15,4 @@ public class ChargingProfileResponse /// [JsonPropertyName("timeout")] public required int Timeout { get; set; } -} \ No newline at end of file +} diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/SetChargingProfile.cs b/src/OCPI.Net.Contracts/ChargingProfiles/SetChargingProfile.cs index 4ae6804..80f1257 100644 --- a/src/OCPI.Net.Contracts/ChargingProfiles/SetChargingProfile.cs +++ b/src/OCPI.Net.Contracts/ChargingProfiles/SetChargingProfile.cs @@ -16,4 +16,4 @@ public class SetChargingProfile /// [JsonPropertyName("response_url")] public required string ResponseUrl { get; set; } = null!; -} \ No newline at end of file +} diff --git a/src/OCPI.Net.Core/Enums/SmartCharging/ChargingProfileResponseType.cs b/src/OCPI.Net.Core/Enums/ChargingProfiles/ChargingProfileResponseType.cs similarity index 99% rename from src/OCPI.Net.Core/Enums/SmartCharging/ChargingProfileResponseType.cs rename to src/OCPI.Net.Core/Enums/ChargingProfiles/ChargingProfileResponseType.cs index 8f4035c..c072a39 100644 --- a/src/OCPI.Net.Core/Enums/SmartCharging/ChargingProfileResponseType.cs +++ b/src/OCPI.Net.Core/Enums/ChargingProfiles/ChargingProfileResponseType.cs @@ -40,4 +40,4 @@ public enum ChargingProfileResponseType : byte /// [EnumMember(Value = "UNKNOWN_SESSION")] UnknownSession = 32, -} \ No newline at end of file +} diff --git a/src/OCPI.Net.Core/Enums/SmartCharging/ChargingRateUnit.cs b/src/OCPI.Net.Core/Enums/ChargingProfiles/ChargingRateUnit.cs similarity index 99% rename from src/OCPI.Net.Core/Enums/SmartCharging/ChargingRateUnit.cs rename to src/OCPI.Net.Core/Enums/ChargingProfiles/ChargingRateUnit.cs index 015bbdc..1f06870 100644 --- a/src/OCPI.Net.Core/Enums/SmartCharging/ChargingRateUnit.cs +++ b/src/OCPI.Net.Core/Enums/ChargingProfiles/ChargingRateUnit.cs @@ -24,5 +24,4 @@ public enum ChargingRateUnit : byte /// [EnumMember(Value = "A")] Amperes = 12, - -} \ No newline at end of file +} From c8fa81aeadea03b84b52ce24a7bbd957110a8200 Mon Sep 17 00:00:00 2001 From: Lior Ben Ari Date: Wed, 7 Feb 2024 21:39:02 +0200 Subject: [PATCH 05/10] add ToString Methods --- .../ChargingProfiles/ChargingProfile.cs | 22 ++++++++++++++++++- .../ChargingProfiles/ChargingProfilePeriod.cs | 2 ++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs index 4f2029d..29d6e31 100644 --- a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs +++ b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs @@ -1,4 +1,5 @@ -using System.Text.Json.Serialization; +using System.Text; +using System.Text.Json.Serialization; using OCPI.Enums.SmartCharging; namespace OCPI.Contracts.ChargingProfiles; @@ -44,4 +45,23 @@ public class ChargingProfile /// [JsonPropertyName("charging_profile_period")] public IEnumerable? ChargingProfilePeriod { get; set; } + + public override string ToString() + { + var toStringBuilder = new StringBuilder(); + toStringBuilder.Append($"Start date time: {StartDateTime}, "); + toStringBuilder.AppendLine($"Duration: {Duration},"); + toStringBuilder.Append($"Charging rate unit: {ChargingRateUnit}, "); + toStringBuilder.AppendLine($"Minimum charging rate: {MinChargingRate},"); + + if (ChargingProfilePeriod == null) + return toStringBuilder.ToString(); + + var periodNum = 1; + toStringBuilder.AppendLine("ChargingProfilePeriods:"); + foreach (var period in ChargingProfilePeriod) + toStringBuilder.Append($"Period #{periodNum++} - {period}, "); + + return toStringBuilder.ToString(); + } } diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfilePeriod.cs b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfilePeriod.cs index d161e11..455395b 100644 --- a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfilePeriod.cs +++ b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfilePeriod.cs @@ -17,4 +17,6 @@ public class ChargingProfilePeriod /// [JsonPropertyName("limit")] public required decimal Limit { get; set; } + + public override string ToString() => $"Start Period: {StartPeriod}, Limit: {Limit}"; } From 44a6962197341e0981714dc92ee846228f83e645 Mon Sep 17 00:00:00 2001 From: Lior Ben Ari Date: Thu, 8 Feb 2024 11:51:27 +0200 Subject: [PATCH 06/10] improve ToString --- .../ChargingProfiles/ChargingProfile.cs | 20 ++++++++++++------- ...le.cs => OcpiSetChargingProfileCommand.cs} | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) rename src/OCPI.Net.Contracts/ChargingProfiles/{SetChargingProfile.cs => OcpiSetChargingProfileCommand.cs} (93%) diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs index 29d6e31..699af80 100644 --- a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs +++ b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs @@ -1,4 +1,5 @@ -using System.Text; +using System.Collections.Immutable; +using System.Text; using System.Text.Json.Serialization; using OCPI.Enums.SmartCharging; @@ -53,15 +54,20 @@ public override string ToString() toStringBuilder.AppendLine($"Duration: {Duration},"); toStringBuilder.Append($"Charging rate unit: {ChargingRateUnit}, "); toStringBuilder.AppendLine($"Minimum charging rate: {MinChargingRate},"); + var chargingProfilePeriodToString = ChargingProfilePeriodToString(); + return toStringBuilder.Append(chargingProfilePeriodToString).ToString(); + } - if (ChargingProfilePeriod == null) - return toStringBuilder.ToString(); + private string ChargingProfilePeriodToString() + { + var toStringBuilder = new StringBuilder(); + toStringBuilder.AppendLine("ChargingProfilePeriods:"); + var periodsToIterate = ChargingProfilePeriod ?? ImmutableList.Empty; var periodNum = 1; - toStringBuilder.AppendLine("ChargingProfilePeriods:"); - foreach (var period in ChargingProfilePeriod) - toStringBuilder.Append($"Period #{periodNum++} - {period}, "); - + foreach (var period in periodsToIterate) + toStringBuilder.Append($"Period #{periodNum++}: {period}; "); + return toStringBuilder.ToString(); } } diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/SetChargingProfile.cs b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiSetChargingProfileCommand.cs similarity index 93% rename from src/OCPI.Net.Contracts/ChargingProfiles/SetChargingProfile.cs rename to src/OCPI.Net.Contracts/ChargingProfiles/OcpiSetChargingProfileCommand.cs index 80f1257..abc6571 100644 --- a/src/OCPI.Net.Contracts/ChargingProfiles/SetChargingProfile.cs +++ b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiSetChargingProfileCommand.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; namespace OCPI.Contracts.ChargingProfiles; -public class SetChargingProfile +public class OcpiSetChargingProfileCommand { /// /// Contains limits for the available power or current over time. From 07653243918da22ea27af0a605f189d473366c5b Mon Sep 17 00:00:00 2001 From: Lior Ben Ari Date: Thu, 8 Feb 2024 12:13:06 +0200 Subject: [PATCH 07/10] Name fix --- src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs index 699af80..dcd86a6 100644 --- a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs +++ b/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs @@ -54,11 +54,11 @@ public override string ToString() toStringBuilder.AppendLine($"Duration: {Duration},"); toStringBuilder.Append($"Charging rate unit: {ChargingRateUnit}, "); toStringBuilder.AppendLine($"Minimum charging rate: {MinChargingRate},"); - var chargingProfilePeriodToString = ChargingProfilePeriodToString(); + var chargingProfilePeriodToString = ChargingProfilePeriodsToString(); return toStringBuilder.Append(chargingProfilePeriodToString).ToString(); } - private string ChargingProfilePeriodToString() + private string ChargingProfilePeriodsToString() { var toStringBuilder = new StringBuilder(); toStringBuilder.AppendLine("ChargingProfilePeriods:"); From 87d25f49600e972603a1cc3b4b9e4939c6c2b6f2 Mon Sep 17 00:00:00 2001 From: Lior Ben Ari Date: Thu, 8 Feb 2024 12:28:12 +0200 Subject: [PATCH 08/10] Align class names with lib conventaion --- .../{ChargingProfile.cs => OcpiChargingProfile.cs} | 6 +++--- ...hargingProfilePeriod.cs => OcpiChargingProfilePeriod.cs} | 2 +- ...ingProfileResponse.cs => OcpiChargingProfileResponse.cs} | 2 +- .../ChargingProfiles/OcpiSetChargingProfileCommand.cs | 2 +- .../{AuthorizationInfo.cs => OcpiAuthorizationInfo.cs} | 4 ++-- .../{LocationReferences.cs => OcpiLocationReferences.cs} | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) rename src/OCPI.Net.Contracts/ChargingProfiles/{ChargingProfile.cs => OcpiChargingProfile.cs} (94%) rename src/OCPI.Net.Contracts/ChargingProfiles/{ChargingProfilePeriod.cs => OcpiChargingProfilePeriod.cs} (95%) rename src/OCPI.Net.Contracts/ChargingProfiles/{ChargingProfileResponse.cs => OcpiChargingProfileResponse.cs} (92%) rename src/OCPI.Net.Contracts/Token/{AuthorizationInfo.cs => OcpiAuthorizationInfo.cs} (92%) rename src/OCPI.Net.Contracts/Token/{LocationReferences.cs => OcpiLocationReferences.cs} (95%) diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfile.cs similarity index 94% rename from src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs rename to src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfile.cs index dcd86a6..2c89fa8 100644 --- a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfile.cs +++ b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfile.cs @@ -5,7 +5,7 @@ namespace OCPI.Contracts.ChargingProfiles; -public class ChargingProfile +public class OcpiChargingProfile { /// /// Starting point of an absolute profile. If absent the profile @@ -45,7 +45,7 @@ public class ChargingProfile /// maximum power or current usage over time. /// [JsonPropertyName("charging_profile_period")] - public IEnumerable? ChargingProfilePeriod { get; set; } + public IEnumerable? ChargingProfilePeriod { get; set; } public override string ToString() { @@ -63,7 +63,7 @@ private string ChargingProfilePeriodsToString() var toStringBuilder = new StringBuilder(); toStringBuilder.AppendLine("ChargingProfilePeriods:"); - var periodsToIterate = ChargingProfilePeriod ?? ImmutableList.Empty; + var periodsToIterate = ChargingProfilePeriod ?? ImmutableList.Empty; var periodNum = 1; foreach (var period in periodsToIterate) toStringBuilder.Append($"Period #{periodNum++}: {period}; "); diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfilePeriod.cs b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfilePeriod.cs similarity index 95% rename from src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfilePeriod.cs rename to src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfilePeriod.cs index 455395b..5e3212c 100644 --- a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfilePeriod.cs +++ b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfilePeriod.cs @@ -2,7 +2,7 @@ namespace OCPI.Contracts.ChargingProfiles; -public class ChargingProfilePeriod +public class OcpiChargingProfilePeriod { /// /// Start of the period, in seconds from the start of profile. The value of StartPeriod diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfileResponse.cs b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfileResponse.cs similarity index 92% rename from src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfileResponse.cs rename to src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfileResponse.cs index ab198d1..1a44b60 100644 --- a/src/OCPI.Net.Contracts/ChargingProfiles/ChargingProfileResponse.cs +++ b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfileResponse.cs @@ -2,7 +2,7 @@ using OCPI.Enums.SmartCharging; namespace OCPI.Contracts.ChargingProfiles; -public class ChargingProfileResponse +public class OcpiChargingProfileResponse { /// /// Response from the CPO on the ChargingProfile request. diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/OcpiSetChargingProfileCommand.cs b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiSetChargingProfileCommand.cs index abc6571..c1e0e21 100644 --- a/src/OCPI.Net.Contracts/ChargingProfiles/OcpiSetChargingProfileCommand.cs +++ b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiSetChargingProfileCommand.cs @@ -7,7 +7,7 @@ public class OcpiSetChargingProfileCommand /// Contains limits for the available power or current over time. /// [JsonPropertyName("charging_profile")] - public required ChargingProfile ChargingProfile { get; set; } = null!; + public required OcpiChargingProfile ChargingProfile { get; set; } = null!; /// /// URL that the ChargingProfileResult POST should be send to. This diff --git a/src/OCPI.Net.Contracts/Token/AuthorizationInfo.cs b/src/OCPI.Net.Contracts/Token/OcpiAuthorizationInfo.cs similarity index 92% rename from src/OCPI.Net.Contracts/Token/AuthorizationInfo.cs rename to src/OCPI.Net.Contracts/Token/OcpiAuthorizationInfo.cs index dcf3d54..57e6904 100644 --- a/src/OCPI.Net.Contracts/Token/AuthorizationInfo.cs +++ b/src/OCPI.Net.Contracts/Token/OcpiAuthorizationInfo.cs @@ -2,7 +2,7 @@ namespace OCPI.Contracts; -public class AuthorizationInfo +public class OcpiAuthorizationInfo { /// /// Status of the Token, and whether charging is allowed at the optionally @@ -23,7 +23,7 @@ public class AuthorizationInfo /// EV driver is allowed to charge at are returned. /// [JsonPropertyName("location")] - public LocationReferences? LocationReferences { get; set; } + public OcpiLocationReferences? LocationReferences { get; set; } /// /// Reference to the authorization given by the eMSP, when given, this diff --git a/src/OCPI.Net.Contracts/Token/LocationReferences.cs b/src/OCPI.Net.Contracts/Token/OcpiLocationReferences.cs similarity index 95% rename from src/OCPI.Net.Contracts/Token/LocationReferences.cs rename to src/OCPI.Net.Contracts/Token/OcpiLocationReferences.cs index 56a8434..72e44e1 100644 --- a/src/OCPI.Net.Contracts/Token/LocationReferences.cs +++ b/src/OCPI.Net.Contracts/Token/OcpiLocationReferences.cs @@ -2,7 +2,7 @@ namespace OCPI.Contracts; -public class LocationReferences +public class OcpiLocationReferences { /// /// Unique identifier for the location. From 16b47a5392a3c76183f62f27645ab6e5105768e2 Mon Sep 17 00:00:00 2001 From: Lior Ben Ari Date: Thu, 8 Feb 2024 15:21:54 +0200 Subject: [PATCH 09/10] CR fixes --- .../ChargingProfiles/OcpiChargingProfile.cs | 14 ++++++++++---- ...Command.cs => OcpiSetChargingProfileRequest.cs} | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) rename src/OCPI.Net.Contracts/ChargingProfiles/{OcpiSetChargingProfileCommand.cs => OcpiSetChargingProfileRequest.cs} (93%) diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfile.cs b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfile.cs index 2c89fa8..3811c6e 100644 --- a/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfile.cs +++ b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfile.cs @@ -45,27 +45,33 @@ public class OcpiChargingProfile /// maximum power or current usage over time. /// [JsonPropertyName("charging_profile_period")] - public IEnumerable? ChargingProfilePeriod { get; set; } + public IEnumerable? ChargingProfilePeriods { get; set; } public override string ToString() { var toStringBuilder = new StringBuilder(); + toStringBuilder.Append($"Start date time: {StartDateTime}, "); toStringBuilder.AppendLine($"Duration: {Duration},"); toStringBuilder.Append($"Charging rate unit: {ChargingRateUnit}, "); toStringBuilder.AppendLine($"Minimum charging rate: {MinChargingRate},"); + var chargingProfilePeriodToString = ChargingProfilePeriodsToString(); - return toStringBuilder.Append(chargingProfilePeriodToString).ToString(); + toStringBuilder.Append(chargingProfilePeriodToString); + + return toStringBuilder.ToString(); } private string ChargingProfilePeriodsToString() { + if (ChargingProfilePeriods is null || !ChargingProfilePeriods.Any()) + return string.Empty; + var toStringBuilder = new StringBuilder(); toStringBuilder.AppendLine("ChargingProfilePeriods:"); - var periodsToIterate = ChargingProfilePeriod ?? ImmutableList.Empty; var periodNum = 1; - foreach (var period in periodsToIterate) + foreach (var period in ChargingProfilePeriods) toStringBuilder.Append($"Period #{periodNum++}: {period}; "); return toStringBuilder.ToString(); diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/OcpiSetChargingProfileCommand.cs b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiSetChargingProfileRequest.cs similarity index 93% rename from src/OCPI.Net.Contracts/ChargingProfiles/OcpiSetChargingProfileCommand.cs rename to src/OCPI.Net.Contracts/ChargingProfiles/OcpiSetChargingProfileRequest.cs index c1e0e21..a391d4a 100644 --- a/src/OCPI.Net.Contracts/ChargingProfiles/OcpiSetChargingProfileCommand.cs +++ b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiSetChargingProfileRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; namespace OCPI.Contracts.ChargingProfiles; -public class OcpiSetChargingProfileCommand +public class OcpiSetChargingProfileRequest { /// /// Contains limits for the available power or current over time. From 3038aa742d0fcb42c2e274897dc4194597831bba Mon Sep 17 00:00:00 2001 From: Lior Ben Ari Date: Thu, 8 Feb 2024 15:40:48 +0200 Subject: [PATCH 10/10] remove required attribute and make all properties nullable --- .../ChargingProfiles/OcpiChargingProfile.cs | 5 ++--- .../ChargingProfiles/OcpiChargingProfilePeriod.cs | 4 ++-- .../ChargingProfiles/OcpiChargingProfileResponse.cs | 4 ++-- .../ChargingProfiles/OcpiSetChargingProfileRequest.cs | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfile.cs b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfile.cs index 3811c6e..058c4da 100644 --- a/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfile.cs +++ b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfile.cs @@ -1,5 +1,4 @@ -using System.Collections.Immutable; -using System.Text; +using System.Text; using System.Text.Json.Serialization; using OCPI.Enums.SmartCharging; @@ -27,7 +26,7 @@ public class OcpiChargingProfile /// The unit of measure. /// [JsonPropertyName("charging_rate_unit")] - public required ChargingRateUnit ChargingRateUnit { get; set; } + public ChargingRateUnit? ChargingRateUnit { get; set; } /// /// Minimum charging rate supported by the EV. The unit diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfilePeriod.cs b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfilePeriod.cs index 5e3212c..0f73d5b 100644 --- a/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfilePeriod.cs +++ b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfilePeriod.cs @@ -9,14 +9,14 @@ public class OcpiChargingProfilePeriod /// also defines the stop time of the previous period. /// [JsonPropertyName("start_period")] - public required int StartPeriod { get; set; } + public int? StartPeriod { get; set; } /// /// Charging rate limit during the profile period, in the applicable chargingRateUnit, /// for example in Amperes(A) or Watts(W). Accepts at most one digit fraction. /// [JsonPropertyName("limit")] - public required decimal Limit { get; set; } + public decimal? Limit { get; set; } public override string ToString() => $"Start Period: {StartPeriod}, Limit: {Limit}"; } diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfileResponse.cs b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfileResponse.cs index 1a44b60..3406674 100644 --- a/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfileResponse.cs +++ b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiChargingProfileResponse.cs @@ -8,11 +8,11 @@ public class OcpiChargingProfileResponse /// Response from the CPO on the ChargingProfile request. /// [JsonPropertyName("result")] - public required ChargingProfileResponseType Result { get; set; } + public ChargingProfileResponseType? Result { get; set; } /// /// Response from the CPO on the ChargingProfile request. /// [JsonPropertyName("timeout")] - public required int Timeout { get; set; } + public int? Timeout { get; set; } } diff --git a/src/OCPI.Net.Contracts/ChargingProfiles/OcpiSetChargingProfileRequest.cs b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiSetChargingProfileRequest.cs index a391d4a..8a05855 100644 --- a/src/OCPI.Net.Contracts/ChargingProfiles/OcpiSetChargingProfileRequest.cs +++ b/src/OCPI.Net.Contracts/ChargingProfiles/OcpiSetChargingProfileRequest.cs @@ -7,7 +7,7 @@ public class OcpiSetChargingProfileRequest /// Contains limits for the available power or current over time. /// [JsonPropertyName("charging_profile")] - public required OcpiChargingProfile ChargingProfile { get; set; } = null!; + public OcpiChargingProfile? ChargingProfile { get; set; } /// /// URL that the ChargingProfileResult POST should be send to. This @@ -15,5 +15,5 @@ public class OcpiSetChargingProfileRequest /// GET ActiveChargingProfile requests. /// [JsonPropertyName("response_url")] - public required string ResponseUrl { get; set; } = null!; + public string? ResponseUrl { get; set; } }