From e380886c96e6043cf8bd6e98db0201ad67cb296e Mon Sep 17 00:00:00 2001 From: Mohit Jain Date: Thu, 19 Dec 2024 09:43:11 +0530 Subject: [PATCH] Updated imports for v16 datatypes, call and call_result files --- ocpp/v16/call.py | 56 +++++++++++------------------ ocpp/v16/call_result.py | 80 +++++++++++++++-------------------------- ocpp/v16/datatypes.py | 44 ++++++++--------------- 3 files changed, 63 insertions(+), 117 deletions(-) diff --git a/ocpp/v16/call.py b/ocpp/v16/call.py index 0f89e9749..f4795ea94 100644 --- a/ocpp/v16/call.py +++ b/ocpp/v16/call.py @@ -2,23 +2,7 @@ from dataclasses import dataclass, field from typing import Dict, List, Optional, Union -from ocpp.v16.datatypes import ChargingProfile -from ocpp.v16.enums import ( - AvailabilityType, - CertificateUse, - ChargePointErrorCode, - ChargePointStatus, - ChargingProfilePurposeType, - ChargingRateUnitType, - DiagnosticsStatus, - FirmwareStatus, - Log, - MessageTrigger, - Reason, - ResetType, - UpdateType, - UploadLogStatus, -) +from ocpp.v16 import datatypes, enums # Most types of CALL messages can originate from only 1 source, either # from a Charge Point or Central System, but not from both. @@ -51,7 +35,7 @@ class CertificateSigned: @dataclass class ChangeAvailability: connector_id: int - type: AvailabilityType + type: enums.AvailabilityType @dataclass @@ -69,7 +53,7 @@ class ClearCache: class ClearChargingProfile: id: Optional[int] = None connector_id: Optional[int] = None - charging_profile_purpose: Optional[ChargingProfilePurposeType] = None + charging_profile_purpose: Optional[enums.ChargingProfilePurposeType] = None stack_level: Optional[int] = None @@ -80,7 +64,7 @@ class DeleteCertificate: @dataclass class ExtendedTriggerMessage: - requested_message: MessageTrigger + requested_message: enums.MessageTrigger connector_id: Optional[int] = None @@ -88,7 +72,7 @@ class ExtendedTriggerMessage: class GetCompositeSchedule: connector_id: int duration: int - charging_rate_unit: Optional[ChargingRateUnitType] = None + charging_rate_unit: Optional[enums.ChargingRateUnitType] = None @dataclass @@ -107,7 +91,7 @@ class GetDiagnostics: @dataclass class GetInstalledCertificateIds: - certificate_type: CertificateUse + certificate_type: enums.CertificateUse @dataclass @@ -118,7 +102,7 @@ class GetLocalListVersion: @dataclass class GetLog: log: Dict - log_type: Log + log_type: enums.Log request_id: int retries: Optional[int] = None retry_interval: Optional[int] = None @@ -126,7 +110,7 @@ class GetLog: @dataclass class InstallCertificate: - certificate_type: CertificateUse + certificate_type: enums.CertificateUse certificate: str @@ -134,7 +118,7 @@ class InstallCertificate: class RemoteStartTransaction: id_tag: str connector_id: Optional[int] = None - charging_profile: Optional[Union[Dict, ChargingProfile]] = None + charging_profile: Optional[Union[Dict, datatypes.ChargingProfile]] = None @dataclass @@ -153,20 +137,20 @@ class ReserveNow: @dataclass class Reset: - type: ResetType + type: enums.ResetType @dataclass class SendLocalList: list_version: int - update_type: UpdateType + update_type: enums.UpdateType local_authorization_list: List = field(default_factory=list) @dataclass class SetChargingProfile: connector_id: int - cs_charging_profiles: Union[ChargingProfile, Dict] + cs_charging_profiles: Union[datatypes.ChargingProfile, Dict] @dataclass @@ -179,7 +163,7 @@ class SignedUpdateFirmware: @dataclass class TriggerMessage: - requested_message: MessageTrigger + requested_message: enums.MessageTrigger connector_id: Optional[int] = None @@ -220,12 +204,12 @@ class BootNotification: @dataclass class DiagnosticsStatusNotification: - status: DiagnosticsStatus + status: enums.DiagnosticsStatus @dataclass class FirmwareStatusNotification: - status: FirmwareStatus + status: enums.FirmwareStatus @dataclass @@ -235,7 +219,7 @@ class Heartbeat: @dataclass class LogStatusNotification: - status: UploadLogStatus + status: enums.UploadLogStatus request_id: int @@ -260,7 +244,7 @@ class SignCertificate: @dataclass class SignedFirmwareStatusNotification: - status: FirmwareStatus + status: enums.FirmwareStatus request_id: int @@ -278,7 +262,7 @@ class StopTransaction: meter_stop: int timestamp: str transaction_id: int - reason: Optional[Reason] = None + reason: Optional[enums.Reason] = None id_tag: Optional[str] = None transaction_data: Optional[List] = None @@ -286,8 +270,8 @@ class StopTransaction: @dataclass class StatusNotification: connector_id: int - error_code: ChargePointErrorCode - status: ChargePointStatus + error_code: enums.ChargePointErrorCode + status: enums.ChargePointStatus timestamp: Optional[str] = None info: Optional[str] = None vendor_id: Optional[str] = None diff --git a/ocpp/v16/call_result.py b/ocpp/v16/call_result.py index cb76ec16a..135f1158f 100644 --- a/ocpp/v16/call_result.py +++ b/ocpp/v16/call_result.py @@ -2,31 +2,7 @@ from dataclasses import dataclass from typing import Dict, List, Optional -from ocpp.v16.datatypes import IdTagInfo -from ocpp.v16.enums import ( - AvailabilityStatus, - CancelReservationStatus, - CertificateSignedStatus, - CertificateStatus, - ChargingProfileStatus, - ClearCacheStatus, - ClearChargingProfileStatus, - ConfigurationStatus, - DataTransferStatus, - DeleteCertificateStatus, - GenericStatus, - GetCompositeScheduleStatus, - GetInstalledCertificateStatus, - LogStatus, - RegistrationStatus, - RemoteStartStopStatus, - ReservationStatus, - ResetStatus, - TriggerMessageStatus, - UnlockStatus, - UpdateFirmwareStatus, - UpdateStatus, -) +from ocpp.v16 import datatypes, enums # Most types of CALLRESULT messages can originate from only 1 source, either # from a Charge Point or Central System, but not from both. @@ -48,14 +24,14 @@ @dataclass class Authorize: - id_tag_info: IdTagInfo + id_tag_info: datatypes.IdTagInfo @dataclass class BootNotification: current_time: str interval: int - status: RegistrationStatus + status: enums.RegistrationStatus @dataclass @@ -85,7 +61,7 @@ class SecurityEventNotification: @dataclass class SignCertificate: - status: GenericStatus + status: enums.GenericStatus @dataclass @@ -96,7 +72,7 @@ class MeterValues: @dataclass class StartTransaction: transaction_id: int - id_tag_info: IdTagInfo + id_tag_info: datatypes.IdTagInfo @dataclass @@ -106,7 +82,7 @@ class StatusNotification: @dataclass class StopTransaction: - id_tag_info: Optional[IdTagInfo] = None + id_tag_info: Optional[datatypes.IdTagInfo] = None # The CALLRESULT messages that flow from Charge Point to Central System are @@ -115,53 +91,53 @@ class StopTransaction: @dataclass class CancelReservation: - status: CancelReservationStatus + status: enums.CancelReservationStatus @dataclass class CertificateSigned: - status: CertificateSignedStatus + status: enums.CertificateSignedStatus @dataclass class ChangeAvailability: - status: AvailabilityStatus + status: enums.AvailabilityStatus @dataclass class ChangeConfiguration: - status: ConfigurationStatus + status: enums.ConfigurationStatus @dataclass class ClearCache: - status: ClearCacheStatus + status: enums.ClearCacheStatus @dataclass class ClearChargingProfile: - status: ClearChargingProfileStatus + status: enums.ClearChargingProfileStatus @dataclass class DeleteCertificate: - status: DeleteCertificateStatus + status: enums.DeleteCertificateStatus @dataclass class ExtendedTriggerMessage: - status: TriggerMessageStatus + status: enums.TriggerMessageStatus @dataclass class GetInstalledCertificateIds: - status: GetInstalledCertificateStatus + status: enums.GetInstalledCertificateStatus certificate_hash_data: Optional[List] = None @dataclass class GetCompositeSchedule: - status: GetCompositeScheduleStatus + status: enums.GetCompositeScheduleStatus connector_id: Optional[int] = None schedule_start: Optional[str] = None charging_schedule: Optional[Dict] = None @@ -185,43 +161,43 @@ class GetLocalListVersion: @dataclass class GetLog: - status: LogStatus + status: enums.LogStatus filename: Optional[str] = None @dataclass class InstallCertificate: - status: CertificateStatus + status: enums.CertificateStatus @dataclass class RemoteStartTransaction: - status: RemoteStartStopStatus + status: enums.RemoteStartStopStatus @dataclass class RemoteStopTransaction: - status: RemoteStartStopStatus + status: enums.RemoteStartStopStatus @dataclass class ReserveNow: - status: ReservationStatus + status: enums.ReservationStatus @dataclass class Reset: - status: ResetStatus + status: enums.ResetStatus @dataclass class SendLocalList: - status: UpdateStatus + status: enums.UpdateStatus @dataclass class SetChargingProfile: - status: ChargingProfileStatus + status: enums.ChargingProfileStatus @dataclass @@ -231,17 +207,17 @@ class SignedFirmwareStatusNotification: @dataclass class SignedUpdateFirmware: - status: UpdateFirmwareStatus + status: enums.UpdateFirmwareStatus @dataclass class TriggerMessage: - status: TriggerMessageStatus + status: enums.TriggerMessageStatus @dataclass class UnlockConnector: - status: UnlockStatus + status: enums.UnlockStatus @dataclass @@ -255,7 +231,7 @@ class UpdateFirmware: @dataclass class DataTransfer: - status: DataTransferStatus + status: enums.DataTransferStatus data: Optional[str] = None diff --git a/ocpp/v16/datatypes.py b/ocpp/v16/datatypes.py index 36c751a7c..944f7c457 100644 --- a/ocpp/v16/datatypes.py +++ b/ocpp/v16/datatypes.py @@ -1,21 +1,7 @@ from dataclasses import dataclass from typing import List, Optional -from ocpp.v16.enums import ( - AuthorizationStatus, - ChargingProfileKindType, - ChargingProfilePurposeType, - ChargingRateUnitType, - CiStringType, - HashAlgorithm, - Location, - Measurand, - Phase, - ReadingContext, - RecurrencyKind, - UnitOfMeasure, - ValueFormat, -) +from ocpp.v16 import enums @dataclass @@ -27,7 +13,7 @@ class IdTagInfo: If expiryDate is not given, the status has no end date. """ - status: AuthorizationStatus + status: enums.AuthorizationStatus parent_id_tag: Optional[str] = None expiry_date: Optional[str] = None @@ -51,7 +37,7 @@ class ChargingSchedulePeriod: @dataclass class ChargingSchedule: - charging_rate_unit: ChargingRateUnitType + charging_rate_unit: enums.ChargingRateUnitType charging_schedule_period: List[ChargingSchedulePeriod] duration: Optional[int] = None start_schedule: Optional[str] = None @@ -67,11 +53,11 @@ class ChargingProfile: charging_profile_id: int stack_level: int - charging_profile_purpose: ChargingProfilePurposeType - charging_profile_kind: ChargingProfileKindType + charging_profile_purpose: enums.ChargingProfilePurposeType + charging_profile_kind: enums.ChargingProfileKindType charging_schedule: ChargingSchedule transaction_id: Optional[int] = None - recurrency_kind: Optional[RecurrencyKind] = None + recurrency_kind: Optional[enums.RecurrencyKind] = None valid_from: Optional[str] = None valid_to: Optional[str] = None @@ -88,11 +74,11 @@ class KeyValue: value: Optional[str] = None def __post_init__(self): - if len(self.key) > CiStringType.ci_string_50: + if len(self.key) > enums.CiStringType.ci_string_50: msg = "Field key is longer than 50 characters" raise ValueError(msg) - if self.value and len(self.value) > CiStringType.ci_string_500: + if self.value and len(self.value) > enums.CiStringType.ci_string_500: msg = "Field key is longer than 500 characters" raise ValueError(msg) @@ -105,12 +91,12 @@ class SampledValue: """ value: str - context: Optional[ReadingContext] = None - format: Optional[ValueFormat] = None - measurand: Optional[Measurand] = None - phase: Optional[Phase] = None - location: Optional[Location] = None - unit: Optional[UnitOfMeasure] = None + context: Optional[enums.ReadingContext] = None + format: Optional[enums.ValueFormat] = None + measurand: Optional[enums.Measurand] = None + phase: Optional[enums.Phase] = None + location: Optional[enums.Location] = None + unit: Optional[enums.UnitOfMeasure] = None @dataclass @@ -134,7 +120,7 @@ class CertificateHashData: DeleteCertificate.req, GetInstalledCertificateIds.conf """ - hash_algorithm: HashAlgorithm + hash_algorithm: enums.HashAlgorithm issuer_name_hash: str issuer_key_hash: str serial_number: str