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
184 changes: 184 additions & 0 deletions ocpp/v16/datatypes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
from dataclasses import dataclass
from typing import List, Optional

from ocpp.v16.enums import (
AvailabilityStatus,
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: AvailabilityStatus
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: 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 CiString20Type:
"""Generic used case insensitive string of 20 characters."""

ci_string_20: str

def __post_init__(self):
if len(self.ci_string_20) > 20:
msg = "Field ci_string_20 is longer than 20 characters"
raise ValueError(msg)


@dataclass
class CiString25Type:
"""Generic used case insensitive string of 25 characters."""

ci_string_25: str

def __post_init__(self):
if len(self.ci_string_25) > 25:
msg = "Field ci_string_25 is longer than 25 characters"
raise ValueError(msg)


@dataclass
class CiString50Type:
"""Generic used case insensitive string of 50 characters."""

ci_string_50: str

def __post_init__(self):
if len(self.ci_string_50) > 50:
msg = "Field ci_string_50 is longer than 50 characters"
raise ValueError(msg)


@dataclass
class CiString255Type:
"""Generic used case insensitive string of 255 characters."""

ci_string_255: str

def __post_init__(self):
if len(self.ci_string_255) > 255:
msg = "Field ci_string_255 is longer than 255 characters"
raise ValueError(msg)


@dataclass
class CiString500Type:
"""Generic used case insensitive string of 500 characters."""

ci_string_500: str

def __post_init__(self):
if len(self.ci_string_500) > 500:
msg = "Field ci_string_500 is longer than 500 characters"
raise ValueError(msg)


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

key: CiString50Type
readonly: bool
value: Optional[CiString500Type] = None


@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]