Skip to content

Commit be4f57b

Browse files
authored
Add v1.6 data types (#250)
1 parent a3dc3c8 commit be4f57b

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed

ocpp/v16/datatypes.py

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
from dataclasses import dataclass
2+
from typing import List, Optional
3+
4+
from ocpp.v16.enums import (
5+
AuthorizationStatus,
6+
CiStringType,
7+
ChargingRateUnitType,
8+
ChargingProfilePurposeType,
9+
ChargingProfileKindType,
10+
Location,
11+
RecurrencyKind,
12+
ReadingContext,
13+
UnitOfMeasure,
14+
ValueFormat,
15+
Measurand,
16+
Phase
17+
)
18+
19+
20+
@dataclass
21+
class IdToken:
22+
"""
23+
Contains the identifier to use for authorization. It is a case
24+
insensitive string. In future releases this may become a complex type to
25+
support multiple forms of identifiers.
26+
"""
27+
28+
id_token: str
29+
30+
31+
@dataclass
32+
class IdTagInfo:
33+
"""
34+
Contains status information about an identifier. It is returned in
35+
Authorize, Start Transaction and Stop Transaction responses.
36+
37+
If expiryDate is not given, the status has no end date.
38+
"""
39+
40+
status: AuthorizationStatus
41+
parent_id_tag: Optional[IdToken] = None
42+
expiry_date: Optional[str] = None
43+
44+
45+
@dataclass
46+
class AuthorizationData:
47+
"""
48+
Elements that constitute an entry of a Local Authorization List update.
49+
"""
50+
51+
id_tag: IdToken
52+
id_tag_info: Optional[IdTagInfo]
53+
54+
55+
@dataclass
56+
class ChargingSchedulePeriod:
57+
start_period: int
58+
limit: float
59+
number_phases: Optional[int] = None
60+
61+
62+
@dataclass
63+
class ChargingSchedule:
64+
charging_rate_unit: ChargingRateUnitType
65+
charging_schedule_period: List[ChargingSchedulePeriod]
66+
duration: Optional[int] = None
67+
start_schedule: Optional[str] = None
68+
min_charging_rate: Optional[float] = None
69+
70+
71+
@dataclass
72+
class ChargingProfile:
73+
"""
74+
A ChargingProfile consists of a ChargingSchedule, describing the
75+
amount of power or current that can be delivered per time interval.
76+
"""
77+
78+
charging_profile_id: int
79+
stack_level: int
80+
charging_profile_purpose: ChargingProfilePurposeType
81+
charging_profile_kind: ChargingProfileKindType
82+
charging_schedule: ChargingSchedule
83+
transaction_id: Optional[int] = None
84+
recurrency_kind: Optional[RecurrencyKind] = None
85+
valid_from: Optional[str] = None
86+
valid_to: Optional[str] = None
87+
88+
89+
@dataclass
90+
class KeyValue:
91+
"""
92+
Contains information about a specific configuration key.
93+
It is returned in GetConfiguration.conf.
94+
"""
95+
96+
key: str
97+
readonly: bool
98+
value: Optional[str] = None
99+
100+
def __post_init__(self):
101+
if len(self.key) > CiStringType.ci_string_50:
102+
msg = "Field key is longer than 50 characters"
103+
raise ValueError(msg)
104+
105+
if self.value and len(self.value) > CiStringType.ci_string_500:
106+
msg = "Field key is longer than 500 characters"
107+
raise ValueError(msg)
108+
109+
110+
@dataclass
111+
class SampledValue:
112+
"""
113+
Single sampled value in MeterValues. Each value can be accompanied by
114+
optional fields.
115+
"""
116+
117+
value: str
118+
context: ReadingContext
119+
format: Optional[ValueFormat] = None
120+
measurand: Optional[Measurand] = None
121+
phase: Optional[Phase] = None
122+
location: Optional[Location] = None
123+
unit: Optional[UnitOfMeasure] = None
124+
125+
126+
@dataclass
127+
class MeterValue:
128+
"""
129+
Collection of one or more sampled values in MeterValues.req.
130+
All sampled values in a MeterValue are sampled at the same point in time.
131+
"""
132+
133+
timestamp: str
134+
sampled_value: List[SampledValue]

ocpp/v16/enums.py

+12
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,18 @@ class ChargingRateUnitType(str, Enum):
263263
amps = "A"
264264

265265

266+
class CiStringType(int):
267+
"""
268+
Generic used case insensitive string of X characters
269+
"""
270+
271+
ci_string_20 = 20
272+
ci_string_25 = 25
273+
ci_string_50 = 50
274+
ci_string_255 = 255
275+
ci_string_500 = 500
276+
277+
266278
class ClearCacheStatus(str, Enum):
267279
"""
268280
Status returned in response to ClearCache.req.

0 commit comments

Comments
 (0)