Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add v1.6 data types #250

Merged
merged 10 commits into from
Nov 25, 2021
Merged
134 changes: 134 additions & 0 deletions ocpp/v16/datatypes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
from dataclasses import dataclass
from typing import List, Optional

from ocpp.v16.enums import (
AuthorizationStatus,
CiStringType,
ChargingRateUnitType,
ChargingProfilePurposeType,
ChargingProfileKindType,
Location,
RecurrencyKind,
ReadingContext,
UnitOfMeasure,
ValueFormat,
Measurand,
Phase
)


@dataclass
class IdToken:
"""
Contains the identifier to use for authorization. It is a case
insensitive string. In future releases this may become a complex type to
support multiple forms of identifiers.
"""

id_token: str


@dataclass
class IdTagInfo:
"""
Contains status information about an identifier. It is returned in
Authorize, Start Transaction and Stop Transaction responses.

If expiryDate is not given, the status has no end date.
"""

status: AuthorizationStatus
parent_id_tag: Optional[IdToken] = None
expiry_date: Optional[str] = None


@dataclass
class AuthorizationData:
"""
Elements that constitute an entry of a Local Authorization List update.
"""

id_tag: IdToken
id_tag_info: Optional[IdTagInfo]


@dataclass
class ChargingSchedulePeriod:
start_period: int
limit: float
number_phases: Optional[int] = None


@dataclass
class ChargingSchedule:
charging_rate_unit: ChargingRateUnitType
charging_schedule_period: List[ChargingSchedulePeriod]
duration: Optional[int] = None
start_schedule: Optional[str] = None
min_charging_rate: Optional[float] = None


@dataclass
class ChargingProfile:
"""
A ChargingProfile consists of a ChargingSchedule, describing the
amount of power or current that can be delivered per time interval.
"""

charging_profile_id: int
stack_level: int
charging_profile_purpose: ChargingProfilePurposeType
charging_profile_kind: ChargingProfileKindType
charging_schedule: ChargingSchedule
transaction_id: Optional[int] = None
recurrency_kind: Optional[RecurrencyKind] = None
valid_from: Optional[str] = None
valid_to: Optional[str] = None


@dataclass
class KeyValue:
"""
Contains information about a specific configuration key.
It is returned in GetConfiguration.conf.
"""

key: str
readonly: bool
value: Optional[str] = None

def __post_init__(self):
if len(self.key) > 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:
msg = "Field key is longer than 500 characters"
raise ValueError(msg)


@dataclass
class SampledValue:
"""
Single sampled value in MeterValues. Each value can be accompanied by
optional fields.
"""

value: str
context: ReadingContext
format: Optional[ValueFormat] = None
measurand: Optional[Measurand] = None
phase: Optional[Phase] = None
location: Optional[Location] = None
unit: Optional[UnitOfMeasure] = None


@dataclass
class MeterValue:
"""
Collection of one or more sampled values in MeterValues.req.
All sampled values in a MeterValue are sampled at the same point in time.
"""

timestamp: str
sampled_value: List[SampledValue]
12 changes: 12 additions & 0 deletions ocpp/v16/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,18 @@ class ChargingRateUnitType(str, Enum):
amps = "A"


class CiStringType(int):
"""
Generic used case insensitive string of X characters
"""

ci_string_20 = 20
ci_string_25 = 25
ci_string_50 = 50
ci_string_255 = 255
ci_string_500 = 500


class ClearCacheStatus(str, Enum):
"""
Status returned in response to ClearCache.req.
Expand Down