| 1 |
import json |
| 2 |
from dataclasses import asdict, dataclass |
| 3 |
from typing import TypeVar |
| 4 |
|
| 5 |
from ocpp.v201.datatypes import ( |
| 6 |
ACChargingParametersType, |
| 7 |
AdditionalInfoType, |
| 8 |
APNType, |
| 9 |
AuthorizationData, |
| 10 |
CertificateHashDataChainType, |
| 11 |
CertificateHashDataType, |
| 12 |
ChargingLimitType, |
| 13 |
ChargingNeedsType, |
| 14 |
ChargingProfileCriterionType, |
| 15 |
ChargingProfileType, |
| 16 |
ChargingSchedulePeriodType, |
| 17 |
ChargingScheduleType, |
| 18 |
ChargingStationType, |
| 19 |
ClearChargingProfileType, |
| 20 |
ClearMonitoringResultType, |
| 21 |
ComponentType, |
| 22 |
ComponentVariableType, |
| 23 |
CompositeScheduleType, |
| 24 |
ConsumptionCostType, |
| 25 |
CostType, |
| 26 |
DCChargingParametersType, |
| 27 |
EventDataType, |
| 28 |
EVSEType, |
| 29 |
FirmwareType, |
| 30 |
GetVariableDataType, |
| 31 |
GetVariableResultType, |
| 32 |
IdTokenInfoType, |
| 33 |
IdTokenType, |
| 34 |
LogParametersType, |
| 35 |
MessageContentType, |
| 36 |
MessageInfoType, |
| 37 |
MeterValueType, |
| 38 |
ModemType, |
| 39 |
MonitoringDataType, |
| 40 |
NetworkConnectionProfileType, |
| 41 |
OCSPRequestDataType, |
| 42 |
RelativeTimeIntervalType, |
| 43 |
ReportDataType, |
| 44 |
SalesTariffEntryType, |
| 45 |
SampledValueType, |
| 46 |
SetMonitoringDataType, |
| 47 |
SetMonitoringResultType, |
| 48 |
SetVariableResultType, |
| 49 |
StatusInfoType, |
| 50 |
UnitOfMeasureType, |
| 51 |
VariableAttributeType, |
| 52 |
VariableCharacteristicsType, |
| 53 |
VariableMonitoringType, |
| 54 |
VariableType, |
| 55 |
) |
| 56 |
from ocpp.v201.enums import ( |
| 57 |
APNAuthenticationEnumType, |
| 58 |
AttributeEnumType, |
| 59 |
AuthorizationStatusEnumType, |
| 60 |
ChargingProfileKindEnumType, |
| 61 |
ChargingProfilePurposeEnumType, |
| 62 |
ChargingRateUnitEnumType, |
| 63 |
ChargingStateEnumType, |
| 64 |
ClearMonitoringStatusEnumType, |
| 65 |
CostKindEnumType, |
| 66 |
DataEnumType, |
| 67 |
EnergyTransferModeEnumType, |
| 68 |
EventNotificationEnumType, |
| 69 |
EventTriggerEnumType, |
| 70 |
HashAlgorithmEnumType, |
| 71 |
IdTokenEnumType, |
| 72 |
LocationEnumType, |
| 73 |
MeasurandEnumType, |
| 74 |
MessageFormatEnumType, |
| 75 |
MonitorEnumType, |
| 76 |
MutabilityEnumType, |
| 77 |
OCPPInterfaceEnumType, |
| 78 |
OCPPTransportEnumType, |
| 79 |
OCPPVersionEnumType, |
| 80 |
PhaseEnumType, |
| 81 |
ReadingContextEnumType, |
| 82 |
ReasonEnumType, |
| 83 |
SetMonitoringStatusEnumType, |
| 84 |
SetVariableStatusEnumType, |
| 85 |
StandardizedUnitsOfMeasureType, |
| 86 |
VPNEnumType, |
| 87 |
) |
| 88 |
|
| 89 |
T = TypeVar("T", bound="dataclass") |
| 90 |
|
| 91 |
|
| 92 |
def to_datatype(cls, dc: T): |
| 93 |
to_dict = asdict(dc) |
| 94 |
to_json = json.dumps(to_dict) |
| 95 |
from_json = json.loads(to_json) |
| 96 |
return cls(**from_json) |
| 97 |
|
| 98 |
|
| 99 |
def test_ac_charging_parameters_type(): |
| 100 |
acpt = ACChargingParametersType( |
| 101 |
energy_amount=20.5, ev_min_current=10.0, ev_max_current=32.0, ev_max_voltage=400 |
| 102 |
) |
| 103 |
|
| 104 |
new_acpt = to_datatype(ACChargingParametersType, acpt) |
| 105 |
|
| 106 |
assert new_acpt.energy_amount == acpt.energy_amount |
| 107 |
assert new_acpt.ev_min_current == acpt.ev_min_current |
| 108 |
assert new_acpt.ev_max_current == acpt.ev_max_current |
| 109 |
assert new_acpt.ev_max_voltage == acpt.ev_max_voltage |
| 110 |
|
| 111 |
|
| 112 |
def test_additional_info_type(): |
| 113 |
ait = AdditionalInfoType( |
| 114 |
additional_id_token="additional_token123", type="type_value" |
| 115 |
) |
| 116 |
|
| 117 |
new_ait = to_datatype(AdditionalInfoType, ait) |
| 118 |
|
| 119 |
assert new_ait.additional_id_token == ait.additional_id_token |
| 120 |
assert new_ait.type == ait.type |
| 121 |
|
| 122 |
|
| 123 |
def test_apn_type(): |
| 124 |
at = APNType( |
| 125 |
apn="internet.example.com", |
| 126 |
apn_authentication=APNAuthenticationEnumType.auto, |
| 127 |
apn_user_name="username", |
| 128 |
apn_password="password", |
| 129 |
sim_pin=1234, |
| 130 |
preferred_network="preferred", |
| 131 |
use_only_preferred_network=True, |
| 132 |
) |
| 133 |
|
| 134 |
new_at = to_datatype(APNType, at) |
| 135 |
|
| 136 |
assert new_at.apn == at.apn |
| 137 |
assert new_at.apn_authentication == at.apn_authentication |
| 138 |
assert new_at.apn_user_name == at.apn_user_name |
| 139 |
assert new_at.apn_password == at.apn_password |
| 140 |
assert new_at.sim_pin == at.sim_pin |
| 141 |
assert new_at.preferred_network == at.preferred_network |
| 142 |
assert new_at.use_only_preferred_network == at.use_only_preferred_network |
| 143 |
|
| 144 |
|
| 145 |
def test_authorization_data(): |
| 146 |
ad = AuthorizationData( |
| 147 |
id_token_info=IdTokenInfoType( |
| 148 |
status=AuthorizationStatusEnumType.accepted, |
| 149 |
cache_expiry_date_time="2024-01-01T10:00:00Z", |
| 150 |
charging_priority=1, |
| 151 |
language_1="en", |
| 152 |
language_2="fr", |
| 153 |
group_id_token=IdTokenType( |
| 154 |
type=IdTokenEnumType.central, |
| 155 |
id_token="1234567890", |
| 156 |
), |
| 157 |
), |
| 158 |
id_token=IdTokenEnumType.central, |
| 159 |
) |
| 160 |
|
| 161 |
new_ad = to_datatype(AuthorizationData, ad) |
| 162 |
|
| 163 |
assert isinstance(new_ad.id_token_info, dict) |
| 164 |
assert new_ad.id_token_info["status"] == ad.id_token_info.status |
| 165 |
assert ( |
| 166 |
new_ad.id_token_info["cache_expiry_date_time"] |
| 167 |
== ad.id_token_info.cache_expiry_date_time |
| 168 |
) |
| 169 |
assert ( |
| 170 |
new_ad.id_token_info["charging_priority"] == ad.id_token_info.charging_priority |
| 171 |
) |
| 172 |
assert new_ad.id_token_info["language_1"] == ad.id_token_info.language_1 |
| 173 |
assert new_ad.id_token_info["language_2"] == ad.id_token_info.language_2 |
| 174 |
assert isinstance(new_ad.id_token, str) |
| 175 |
assert new_ad.id_token == ad.id_token |
| 176 |
|
| 177 |
|
| 178 |
def test_certificate_hash_data_chain_type(): |
| 179 |
chdct = CertificateHashDataChainType( |
| 180 |
certificate_type="V2G", |
| 181 |
certificate_hash_data=CertificateHashDataType( |
| 182 |
hash_algorithm="SHA256", |
| 183 |
issuer_name_hash="issuer_hash", |
| 184 |
issuer_key_hash="key_hash", |
| 185 |
serial_number="serial123", |
| 186 |
), |
| 187 |
child_certificate_hash_data=[ |
| 188 |
CertificateHashDataType( |
| 189 |
hash_algorithm="SHA256", |
| 190 |
issuer_name_hash="child_issuer_hash", |
| 191 |
issuer_key_hash="child_key_hash", |
| 192 |
serial_number="child_serial123", |
| 193 |
) |
| 194 |
], |
| 195 |
) |
| 196 |
|
| 197 |
new_chdct = to_datatype(CertificateHashDataChainType, chdct) |
| 198 |
|
| 199 |
assert new_chdct.certificate_type == chdct.certificate_type |
| 200 |
assert isinstance(new_chdct.certificate_hash_data, dict) |
| 201 |
assert ( |
| 202 |
new_chdct.certificate_hash_data["hash_algorithm"] |
| 203 |
== chdct.certificate_hash_data.hash_algorithm |
| 204 |
) |
| 205 |
assert ( |
| 206 |
new_chdct.certificate_hash_data["issuer_name_hash"] |
| 207 |
== chdct.certificate_hash_data.issuer_name_hash |
| 208 |
) |
| 209 |
assert ( |
| 210 |
new_chdct.certificate_hash_data["issuer_key_hash"] |
| 211 |
== chdct.certificate_hash_data.issuer_key_hash |
| 212 |
) |
| 213 |
assert ( |
| 214 |
new_chdct.certificate_hash_data["serial_number"] |
| 215 |
== chdct.certificate_hash_data.serial_number |
| 216 |
) |
| 217 |
assert isinstance(new_chdct.child_certificate_hash_data[0], dict) |
| 218 |
assert ( |
| 219 |
new_chdct.child_certificate_hash_data[0]["hash_algorithm"] |
| 220 |
== chdct.child_certificate_hash_data[0].hash_algorithm |
| 221 |
) |
| 222 |
|
| 223 |
|
| 224 |
def test_certificate_hash_data_type(): |
| 225 |
chdt = CertificateHashDataType( |
| 226 |
hash_algorithm="SHA256", |
| 227 |
issuer_name_hash="issuer_hash", |
| 228 |
issuer_key_hash="key_hash", |
| 229 |
serial_number="serial123", |
| 230 |
) |
| 231 |
|
| 232 |
new_chdt = to_datatype(CertificateHashDataType, chdt) |
| 233 |
|
| 234 |
assert new_chdt.hash_algorithm == chdt.hash_algorithm |
| 235 |
assert new_chdt.issuer_name_hash == chdt.issuer_name_hash |
| 236 |
assert new_chdt.issuer_key_hash == chdt.issuer_key_hash |
| 237 |
assert new_chdt.serial_number == chdt.serial_number |
| 238 |
|
| 239 |
|
| 240 |
def test_charging_limit_type(): |
| 241 |
clt = ChargingLimitType(charging_limit_source="EMS", is_grid_critical=True) |
| 242 |
|
| 243 |
new_clt = to_datatype(ChargingLimitType, clt) |
| 244 |
|
| 245 |
assert new_clt.charging_limit_source == clt.charging_limit_source |
| 246 |
assert new_clt.is_grid_critical == clt.is_grid_critical |
| 247 |
|
| 248 |
|
| 249 |
def test_charging_needs_type(): |
| 250 |
cnt = ChargingNeedsType( |
| 251 |
requested_energy_transfer=EnergyTransferModeEnumType.dc, |
| 252 |
departure_time="2024-01-01T10:00:00Z", |
| 253 |
ac_charging_parameters=ACChargingParametersType( |
| 254 |
energy_amount=20, ev_min_current=10, ev_max_current=32, ev_max_voltage=400 |
| 255 |
), |
| 256 |
dc_charging_parameters=DCChargingParametersType( |
| 257 |
ev_max_current=100, |
| 258 |
ev_max_voltage=500, |
| 259 |
energy_amount=50, |
| 260 |
ev_max_power=50000, |
| 261 |
state_of_charge=80, |
| 262 |
), |
| 263 |
) |
| 264 |
|
| 265 |
new_cnt = to_datatype(ChargingNeedsType, cnt) |
| 266 |
|
| 267 |
assert new_cnt.requested_energy_transfer == cnt.requested_energy_transfer |
| 268 |
assert new_cnt.departure_time == cnt.departure_time |
| 269 |
assert isinstance(new_cnt.ac_charging_parameters, dict) |
| 270 |
assert ( |
| 271 |
new_cnt.ac_charging_parameters["energy_amount"] |
| 272 |
== cnt.ac_charging_parameters.energy_amount |
| 273 |
) |
| 274 |
assert ( |
| 275 |
new_cnt.ac_charging_parameters["ev_min_current"] |
| 276 |
== cnt.ac_charging_parameters.ev_min_current |
| 277 |
) |
| 278 |
assert isinstance(new_cnt.dc_charging_parameters, dict) |
| 279 |
assert ( |
| 280 |
new_cnt.dc_charging_parameters["ev_max_current"] |
| 281 |
== cnt.dc_charging_parameters.ev_max_current |
| 282 |
) |
| 283 |
assert ( |
| 284 |
new_cnt.dc_charging_parameters["state_of_charge"] |
| 285 |
== cnt.dc_charging_parameters.state_of_charge |
| 286 |
) |
| 287 |
|
| 288 |
|
| 289 |
def test_charging_profile_criterion_type(): |
| 290 |
cpct = ChargingProfileCriterionType( |
| 291 |
charging_profile_purpose=ChargingProfilePurposeEnumType.tx_default_profile, |
| 292 |
stack_level=0, |
| 293 |
charging_profile_id=[1, 2, 3], |
| 294 |
) |
| 295 |
|
| 296 |
new_cpct = to_datatype(ChargingProfileCriterionType, cpct) |
| 297 |
|
| 298 |
assert new_cpct.charging_profile_purpose == cpct.charging_profile_purpose |
| 299 |
assert new_cpct.stack_level == cpct.stack_level |
| 300 |
assert new_cpct.charging_profile_id == cpct.charging_profile_id |
| 301 |
|
| 302 |
|
| 303 |
def test_charging_profile_type(): |
| 304 |
cpt = ChargingProfileType( |
| 305 |
id=1, |
| 306 |
stack_level=0, |
| 307 |
charging_profile_purpose=ChargingProfilePurposeEnumType.tx_default_profile, |
| 308 |
charging_profile_kind=ChargingProfileKindEnumType.absolute, |
| 309 |
charging_schedule=[ |
| 310 |
ChargingScheduleType( |
| 311 |
id=1, |
| 312 |
charging_rate_unit=ChargingRateUnitEnumType.watts, |
| 313 |
charging_schedule_period=[ |
| 314 |
ChargingSchedulePeriodType( |
| 315 |
start_period=0, limit=11000.0, number_phases=3 |
| 316 |
) |
| 317 |
], |
| 318 |
start_schedule="2024-01-01T10:00:00Z", |
| 319 |
duration=3600, |
| 320 |
) |
| 321 |
], |
| 322 |
valid_from="2024-01-01T00:00:00Z", |
| 323 |
valid_to="2024-12-31T23:59:59Z", |
| 324 |
) |
| 325 |
|
| 326 |
new_cpt = to_datatype(ChargingProfileType, cpt) |
| 327 |
|
| 328 |
assert new_cpt.id == cpt.id |
| 329 |
assert new_cpt.stack_level == cpt.stack_level |
| 330 |
assert new_cpt.charging_profile_purpose == cpt.charging_profile_purpose |
| 331 |
assert new_cpt.charging_profile_kind == cpt.charging_profile_kind |
| 332 |
assert isinstance(new_cpt.charging_schedule[0], dict) |
| 333 |
assert new_cpt.charging_schedule[0]["id"] == cpt.charging_schedule[0].id |
| 334 |
assert new_cpt.valid_from == cpt.valid_from |
| 335 |
assert new_cpt.valid_to == cpt.valid_to |
| 336 |
|
| 337 |
|
| 338 |
def test_charging_schedule_period_type(): |
| 339 |
cspt = ChargingSchedulePeriodType( |
| 340 |
start_period=0, limit=32.0, number_phases=3, phase_to_use=1 |
| 341 |
) |
| 342 |
|
| 343 |
new_cspt = to_datatype(ChargingSchedulePeriodType, cspt) |
| 344 |
|
| 345 |
assert new_cspt.start_period == cspt.start_period |
| 346 |
assert new_cspt.limit == cspt.limit |
| 347 |
assert new_cspt.number_phases == cspt.number_phases |
| 348 |
assert new_cspt.phase_to_use == cspt.phase_to_use |
| 349 |
|
| 350 |
|
| 351 |
def test_charging_station_type(): |
| 352 |
cst = ChargingStationType( |
| 353 |
model="Station Model X", |
| 354 |
vendor_name="Vendor ABC", |
| 355 |
serial_number="SN123456", |
| 356 |
modem=ModemType(iccid="89001234567890123456", imsi="123456789012345"), |
| 357 |
firmware_version="1.2.3", |
| 358 |
) |
| 359 |
|
| 360 |
new_cst = to_datatype(ChargingStationType, cst) |
| 361 |
|
| 362 |
assert new_cst.model == cst.model |
| 363 |
assert new_cst.vendor_name == cst.vendor_name |
| 364 |
assert new_cst.serial_number == cst.serial_number |
| 365 |
assert isinstance(new_cst.modem, dict) |
| 366 |
assert new_cst.modem["iccid"] == cst.modem.iccid |
| 367 |
assert new_cst.modem["imsi"] == cst.modem.imsi |
| 368 |
assert new_cst.firmware_version == cst.firmware_version |
| 369 |
|
| 370 |
|
| 371 |
def test_clear_charging_profile_type(): |
| 372 |
ccpt = ClearChargingProfileType( |
| 373 |
evse_id=1, |
| 374 |
charging_profile_purpose=ChargingProfilePurposeEnumType.tx_default_profile, |
| 375 |
stack_level=0, |
| 376 |
) |
| 377 |
|
| 378 |
new_ccpt = to_datatype(ClearChargingProfileType, ccpt) |
| 379 |
|
| 380 |
assert new_ccpt.evse_id == ccpt.evse_id |
| 381 |
assert new_ccpt.charging_profile_purpose == ccpt.charging_profile_purpose |
| 382 |
assert new_ccpt.stack_level == ccpt.stack_level |
| 383 |
|
| 384 |
|
| 385 |
def test_clear_monitoring_result_type(): |
| 386 |
cmrt = ClearMonitoringResultType( |
| 387 |
status=ClearMonitoringStatusEnumType.accepted, |
| 388 |
id=123, |
| 389 |
status_info=StatusInfoType( |
| 390 |
reason_code=ReasonEnumType.other, |
| 391 |
additional_info="Successfully cleared monitoring", |
| 392 |
), |
| 393 |
) |
| 394 |
|
| 395 |
new_cmrt = to_datatype(ClearMonitoringResultType, cmrt) |
| 396 |
|
| 397 |
assert new_cmrt.status == cmrt.status |
| 398 |
assert new_cmrt.id == cmrt.id |
| 399 |
assert isinstance(new_cmrt.status_info, dict) |
| 400 |
assert new_cmrt.status_info["reason_code"] == cmrt.status_info.reason_code |
| 401 |
assert new_cmrt.status_info["additional_info"] == cmrt.status_info.additional_info |
| 402 |
|
| 403 |
|
| 404 |
def test_component_type(): |
| 405 |
ct = ComponentType( |
| 406 |
name="MainController", instance="instance1", evse=EVSEType(id=1, connector_id=2) |
| 407 |
) |
| 408 |
|
| 409 |
new_ct = to_datatype(ComponentType, ct) |
| 410 |
|
| 411 |
assert new_ct.name == ct.name |
| 412 |
assert new_ct.instance == ct.instance |
| 413 |
assert isinstance(new_ct.evse, dict) |
| 414 |
assert new_ct.evse["id"] == ct.evse.id |
| 415 |
assert new_ct.evse["connector_id"] == ct.evse.connector_id |
| 416 |
|
| 417 |
|
| 418 |
def test_component_variable_type(): |
| 419 |
cvt = ComponentVariableType( |
| 420 |
component=ComponentType(name="MainController", instance="instance1"), |
| 421 |
variable=VariableType(name="CurrentLimit", instance="instance1"), |
| 422 |
) |
| 423 |
|
| 424 |
new_cvt = to_datatype(ComponentVariableType, cvt) |
| 425 |
|
| 426 |
assert isinstance(new_cvt.component, dict) |
| 427 |
assert new_cvt.component["name"] == cvt.component.name |
| 428 |
assert new_cvt.component["instance"] == cvt.component.instance |
| 429 |
assert isinstance(new_cvt.variable, dict) |
| 430 |
assert new_cvt.variable["name"] == cvt.variable.name |
| 431 |
assert new_cvt.variable["instance"] == cvt.variable.instance |
| 432 |
|
| 433 |
|
| 434 |
def test_composite_schedule_type(): |
| 435 |
cst = CompositeScheduleType( |
| 436 |
evse_id=1, |
| 437 |
duration=3600, |
| 438 |
schedule_start="2024-01-01T10:00:00Z", |
| 439 |
charging_rate_unit=ChargingRateUnitEnumType.watts, |
| 440 |
charging_schedule_period=[ |
| 441 |
ChargingSchedulePeriodType(start_period=0, limit=11000.0, number_phases=3) |
| 442 |
], |
| 443 |
) |
| 444 |
|
| 445 |
new_cst = to_datatype(CompositeScheduleType, cst) |
| 446 |
|
| 447 |
assert new_cst.evse_id == cst.evse_id |
| 448 |
assert new_cst.duration == cst.duration |
| 449 |
assert new_cst.schedule_start == cst.schedule_start |
| 450 |
assert new_cst.charging_rate_unit == cst.charging_rate_unit |
| 451 |
assert isinstance(new_cst.charging_schedule_period[0], dict) |
| 452 |
assert ( |
| 453 |
new_cst.charging_schedule_period[0]["start_period"] |
| 454 |
== cst.charging_schedule_period[0].start_period |
| 455 |
) |
| 456 |
assert ( |
| 457 |
new_cst.charging_schedule_period[0]["limit"] |
| 458 |
== cst.charging_schedule_period[0].limit |
| 459 |
) |
| 460 |
|
| 461 |
|
| 462 |
def test_consumption_cost_type(): |
| 463 |
cct = ConsumptionCostType( |
| 464 |
start_value=0.0, |
| 465 |
cost=[CostType(cost_kind="RelativePrice", amount=1.0, amount_multiplier=0)], |
| 466 |
) |
| 467 |
|
| 468 |
new_cct = to_datatype(ConsumptionCostType, cct) |
| 469 |
|
| 470 |
assert new_cct.start_value == cct.start_value |
| 471 |
assert isinstance(new_cct.cost[0], dict) |
| 472 |
assert new_cct.cost[0]["cost_kind"] == cct.cost[0].cost_kind |
| 473 |
assert new_cct.cost[0]["amount"] == cct.cost[0].amount |
| 474 |
assert new_cct.cost[0]["amount_multiplier"] == cct.cost[0].amount_multiplier |
| 475 |
|
| 476 |
|
| 477 |
def test_cost_type(): |
| 478 |
ct = CostType( |
| 479 |
cost_kind=CostKindEnumType.carbon_dioxide_emission, |
| 480 |
amount=1.0, |
| 481 |
amount_multiplier=0, |
| 482 |
) |
| 483 |
|
| 484 |
new_ct = to_datatype(CostType, ct) |
| 485 |
|
| 486 |
assert new_ct.cost_kind == ct.cost_kind |
| 487 |
assert new_ct.amount == ct.amount |
| 488 |
assert new_ct.amount_multiplier == ct.amount_multiplier |
| 489 |
|
| 490 |
|
| 491 |
def test_event_data_type(): |
| 492 |
edt = EventDataType( |
| 493 |
event_id=1, |
| 494 |
timestamp="2024-01-01T10:00:00Z", |
| 495 |
trigger=EventTriggerEnumType.alerting, |
| 496 |
actual_value="High Temperature", |
| 497 |
tech_code="TC001", |
| 498 |
tech_info="Temperature sensor reading high", |
| 499 |
cleared=False, |
| 500 |
transaction_id="TX001", |
| 501 |
variable_monitoring_id=1, |
| 502 |
event_notification_type=EventNotificationEnumType.hard_wired_notification, |
| 503 |
component=ComponentType(name="MainController", instance="instance1"), |
| 504 |
variable=VariableType(name="Temperature", instance="instance1"), |
| 505 |
) |
| 506 |
|
| 507 |
new_edt = to_datatype(EventDataType, edt) |
| 508 |
|
| 509 |
assert new_edt.event_id == edt.event_id |
| 510 |
assert new_edt.timestamp == edt.timestamp |
| 511 |
assert new_edt.trigger == edt.trigger |
| 512 |
assert new_edt.actual_value == edt.actual_value |
| 513 |
assert new_edt.tech_code == edt.tech_code |
| 514 |
assert new_edt.tech_info == edt.tech_info |
| 515 |
assert new_edt.cleared == edt.cleared |
| 516 |
assert new_edt.transaction_id == edt.transaction_id |
| 517 |
assert new_edt.variable_monitoring_id == edt.variable_monitoring_id |
| 518 |
assert new_edt.event_notification_type == edt.event_notification_type |
| 519 |
assert isinstance(new_edt.component, dict) |
| 520 |
assert new_edt.component["name"] == edt.component.name |
| 521 |
assert isinstance(new_edt.variable, dict) |
| 522 |
assert new_edt.variable["name"] == edt.variable.name |
| 523 |
|
| 524 |
|
| 525 |
def test_firmware_type(): |
| 526 |
ft = FirmwareType( |
| 527 |
location="https://firmware.example.com/v1.2.3", |
| 528 |
retrieve_date_time="2024-01-01T10:00:00Z", |
| 529 |
install_date_time="2024-01-01T11:00:00Z", |
| 530 |
signing_certificate="MIIB...", |
| 531 |
signature="SHA256...", |
| 532 |
) |
| 533 |
|
| 534 |
new_ft = to_datatype(FirmwareType, ft) |
| 535 |
|
| 536 |
assert new_ft.location == ft.location |
| 537 |
assert new_ft.retrieve_date_time == ft.retrieve_date_time |
| 538 |
assert new_ft.install_date_time == ft.install_date_time |
| 539 |
assert new_ft.signing_certificate == ft.signing_certificate |
| 540 |
assert new_ft.signature == ft.signature |
| 541 |
|
| 542 |
|
| 543 |
def test_get_variable_data_type(): |
| 544 |
gvdt = GetVariableDataType( |
| 545 |
component=ComponentType(name="MainController", instance="instance1"), |
| 546 |
variable=VariableType(name="CurrentLimit", instance="instance1"), |
| 547 |
attribute_type=AttributeEnumType.actual, |
| 548 |
) |
| 549 |
|
| 550 |
new_gvdt = to_datatype(GetVariableDataType, gvdt) |
| 551 |
|
| 552 |
assert isinstance(new_gvdt.component, dict) |
| 553 |
assert new_gvdt.component["name"] == gvdt.component.name |
| 554 |
assert new_gvdt.component["instance"] == gvdt.component.instance |
| 555 |
assert isinstance(new_gvdt.variable, dict) |
| 556 |
assert new_gvdt.variable["name"] == gvdt.variable.name |
| 557 |
assert new_gvdt.variable["instance"] == gvdt.variable.instance |
| 558 |
assert new_gvdt.attribute_type == gvdt.attribute_type |
| 559 |
|
| 560 |
|
| 561 |
def test_get_variable_result_type(): |
| 562 |
gvrt = GetVariableResultType( |
| 563 |
attribute_status="Accepted", |
| 564 |
attribute_type=AttributeEnumType.actual, |
| 565 |
attribute_value="100", |
| 566 |
component=ComponentType(name="MainController", instance="instance1"), |
| 567 |
variable=VariableType(name="CurrentLimit", instance="instance1"), |
| 568 |
) |
| 569 |
|
| 570 |
new_gvrt = to_datatype(GetVariableResultType, gvrt) |
| 571 |
|
| 572 |
assert new_gvrt.attribute_status == gvrt.attribute_status |
| 573 |
assert new_gvrt.attribute_type == gvrt.attribute_type |
| 574 |
assert new_gvrt.attribute_value == gvrt.attribute_value |
| 575 |
assert isinstance(new_gvrt.component, dict) |
| 576 |
assert new_gvrt.component["name"] == gvrt.component.name |
| 577 |
assert isinstance(new_gvrt.variable, dict) |
| 578 |
assert new_gvrt.variable["name"] == gvrt.variable.name |
| 579 |
|
| 580 |
|
| 581 |
def test_id_token_info_type(): |
| 582 |
itit = IdTokenInfoType( |
| 583 |
status="Accepted", |
| 584 |
cache_expiry_date_time="2024-01-01T10:00:00Z", |
| 585 |
charging_priority=1, |
| 586 |
language_1="en", |
| 587 |
language_2="fr", |
| 588 |
group_id_token=IdTokenEnumType.central, |
| 589 |
personal_message=MessageContentType( |
| 590 |
format=MessageFormatEnumType.ascii, content="Welcome back!", language="en" |
| 591 |
), |
| 592 |
) |
| 593 |
|
| 594 |
new_itit = to_datatype(IdTokenInfoType, itit) |
| 595 |
|
| 596 |
assert new_itit.status == itit.status |
| 597 |
assert new_itit.cache_expiry_date_time == itit.cache_expiry_date_time |
| 598 |
assert new_itit.charging_priority == itit.charging_priority |
| 599 |
assert new_itit.language_1 == itit.language_1 |
| 600 |
assert new_itit.language_2 == itit.language_2 |
| 601 |
assert isinstance(new_itit.group_id_token, str) |
| 602 |
assert new_itit.group_id_token == itit.group_id_token |
| 603 |
assert isinstance(new_itit.personal_message, dict) |
| 604 |
assert new_itit.personal_message["content"] == itit.personal_message.content |
| 605 |
|
| 606 |
|
| 607 |
def test_log_parameters_type(): |
| 608 |
lpt = LogParametersType( |
| 609 |
remote_location="https://logs.example.com", |
| 610 |
oldest_timestamp="2024-01-01T00:00:00Z", |
| 611 |
latest_timestamp="2024-01-01T23:59:59Z", |
| 612 |
) |
| 613 |
|
| 614 |
new_lpt = to_datatype(LogParametersType, lpt) |
| 615 |
|
| 616 |
assert new_lpt.remote_location == lpt.remote_location |
| 617 |
assert new_lpt.oldest_timestamp == lpt.oldest_timestamp |
| 618 |
assert new_lpt.latest_timestamp == lpt.latest_timestamp |
| 619 |
|
| 620 |
|
| 621 |
def test_message_info_type(): |
| 622 |
mit = MessageInfoType( |
| 623 |
id=1, |
| 624 |
priority=1, |
| 625 |
message=MessageContentType( |
| 626 |
format=MessageFormatEnumType.ascii, |
| 627 |
content="Important notice", |
| 628 |
language="en", |
| 629 |
), |
| 630 |
display=ComponentType(name="MainDisplay", instance="instance1"), |
| 631 |
state=ChargingStateEnumType.charging, |
| 632 |
) |
| 633 |
|
| 634 |
new_mit = to_datatype(MessageInfoType, mit) |
| 635 |
|
| 636 |
assert new_mit.id == mit.id |
| 637 |
assert new_mit.priority == mit.priority |
| 638 |
assert isinstance(new_mit.message, dict) |
| 639 |
assert new_mit.message["content"] == mit.message.content |
| 640 |
assert isinstance(new_mit.display, dict) |
| 641 |
assert new_mit.display["name"] == mit.display.name |
| 642 |
assert new_mit.state == mit.state |
| 643 |
|
| 644 |
|
| 645 |
def test_meter_value_type(): |
| 646 |
mvt = MeterValueType( |
| 647 |
timestamp="2024-01-01T10:00:00Z", |
| 648 |
sampled_value=[ |
| 649 |
SampledValueType( |
| 650 |
value=230.0, |
| 651 |
context=ReadingContextEnumType.sample_periodic, |
| 652 |
measurand=MeasurandEnumType.voltage, |
| 653 |
phase=PhaseEnumType.l1, |
| 654 |
location=LocationEnumType.outlet, |
| 655 |
) |
| 656 |
], |
| 657 |
) |
| 658 |
|
| 659 |
new_mvt = to_datatype(MeterValueType, mvt) |
| 660 |
|
| 661 |
assert new_mvt.timestamp == mvt.timestamp |
| 662 |
assert isinstance(new_mvt.sampled_value[0], dict) |
| 663 |
assert new_mvt.sampled_value[0]["value"] == mvt.sampled_value[0].value |
| 664 |
assert new_mvt.sampled_value[0]["context"] == mvt.sampled_value[0].context |
| 665 |
assert new_mvt.sampled_value[0]["measurand"] == mvt.sampled_value[0].measurand |
| 666 |
assert new_mvt.sampled_value[0]["phase"] == mvt.sampled_value[0].phase |
| 667 |
assert new_mvt.sampled_value[0]["location"] == mvt.sampled_value[0].location |
| 668 |
|
| 669 |
|
| 670 |
def test_modem_type(): |
| 671 |
mt = ModemType(iccid="89012345678901234567", imsi="123456789012345") |
| 672 |
|
| 673 |
new_mt = to_datatype(ModemType, mt) |
| 674 |
|
| 675 |
assert new_mt.iccid == mt.iccid |
| 676 |
assert new_mt.imsi == mt.imsi |
| 677 |
|
| 678 |
|
| 679 |
def test_monitoring_data_type(): |
| 680 |
mdt = MonitoringDataType( |
| 681 |
component=ComponentType(name="MainController", instance="instance1"), |
| 682 |
variable=VariableType(name="Temperature", instance="instance1"), |
| 683 |
variable_monitoring=VariableMonitoringType( |
| 684 |
id=1, |
| 685 |
transaction=True, |
| 686 |
value=100.0, |
| 687 |
type=MonitorEnumType.upper_threshold, |
| 688 |
severity=1, |
| 689 |
), |
| 690 |
) |
| 691 |
|
| 692 |
new_mdt = to_datatype(MonitoringDataType, mdt) |
| 693 |
|
| 694 |
assert isinstance(new_mdt.component, dict) |
| 695 |
assert new_mdt.component["name"] == mdt.component.name |
| 696 |
assert isinstance(new_mdt.variable, dict) |
| 697 |
assert new_mdt.variable["name"] == mdt.variable.name |
| 698 |
assert isinstance(new_mdt.variable_monitoring, dict) |
| 699 |
assert new_mdt.variable_monitoring["id"] == mdt.variable_monitoring.id |
| 700 |
assert new_mdt.variable_monitoring["value"] == mdt.variable_monitoring.value |
| 701 |
|
| 702 |
|
| 703 |
def test_network_connection_profile_type(): |
| 704 |
ncpt = NetworkConnectionProfileType( |
| 705 |
ocpp_version=OCPPVersionEnumType.ocpp20, |
| 706 |
ocpp_transport=OCPPTransportEnumType.json, |
| 707 |
ocpp_csms_url="wss://example.com/ocpp", |
| 708 |
message_timeout=30, |
| 709 |
security_profile=1, |
| 710 |
ocpp_interface=OCPPInterfaceEnumType.wired0, |
| 711 |
vpn=VPNEnumType.ikev2, |
| 712 |
) |
| 713 |
|
| 714 |
new_ncpt = to_datatype(NetworkConnectionProfileType, ncpt) |
| 715 |
|
| 716 |
assert new_ncpt.ocpp_version == ncpt.ocpp_version |
| 717 |
assert new_ncpt.ocpp_transport == ncpt.ocpp_transport |
| 718 |
assert new_ncpt.ocpp_csms_url == ncpt.ocpp_csms_url |
| 719 |
assert new_ncpt.message_timeout == ncpt.message_timeout |
| 720 |
assert new_ncpt.security_profile == ncpt.security_profile |
| 721 |
assert new_ncpt.ocpp_interface == ncpt.ocpp_interface |
| 722 |
assert new_ncpt.vpn == ncpt.vpn |
| 723 |
|
| 724 |
|
| 725 |
def test_ocsp_request_data_type(): |
| 726 |
ordt = OCSPRequestDataType( |
| 727 |
hash_algorithm=HashAlgorithmEnumType.sha256, |
| 728 |
issuer_name_hash="issuer_hash_value", |
| 729 |
issuer_key_hash="issuer_key_hash_value", |
| 730 |
serial_number="serial123", |
| 731 |
responder_url="https://ocsp.example.com", |
| 732 |
) |
| 733 |
|
| 734 |
new_ordt = to_datatype(OCSPRequestDataType, ordt) |
| 735 |
|
| 736 |
assert new_ordt.hash_algorithm == ordt.hash_algorithm |
| 737 |
assert new_ordt.issuer_name_hash == ordt.issuer_name_hash |
| 738 |
assert new_ordt.issuer_key_hash == ordt.issuer_key_hash |
| 739 |
assert new_ordt.serial_number == ordt.serial_number |
| 740 |
assert new_ordt.responder_url == ordt.responder_url |
| 741 |
|
| 742 |
|
| 743 |
def test_relative_time_interval_type(): |
| 744 |
rtit = RelativeTimeIntervalType(start=0, duration=3600) |
| 745 |
|
| 746 |
new_rtit = to_datatype(RelativeTimeIntervalType, rtit) |
| 747 |
|
| 748 |
assert new_rtit.start == rtit.start |
| 749 |
assert new_rtit.duration == rtit.duration |
| 750 |
|
| 751 |
|
| 752 |
def test_report_data_type(): |
| 753 |
rdt = ReportDataType( |
| 754 |
component=ComponentType(name="MainController", instance="instance1"), |
| 755 |
variable=VariableType(name="Temperature", instance="instance1"), |
| 756 |
variable_attribute=[ |
| 757 |
VariableAttributeType( |
| 758 |
type=AttributeEnumType.actual, |
| 759 |
value="25.5", |
| 760 |
mutability="ReadWrite", |
| 761 |
persistent=True, |
| 762 |
constant=False, |
| 763 |
) |
| 764 |
], |
| 765 |
variable_characteristics=VariableCharacteristicsType( |
| 766 |
unit="Celsius", |
| 767 |
data_type=DataEnumType.decimal, |
| 768 |
min_limit="-20", |
| 769 |
max_limit="50", |
| 770 |
values_list=["10", "20", "30"], |
| 771 |
supports_monitoring=True, |
| 772 |
), |
| 773 |
) |
| 774 |
|
| 775 |
new_rdt = to_datatype(ReportDataType, rdt) |
| 776 |
|
| 777 |
assert isinstance(new_rdt.component, dict) |
| 778 |
assert new_rdt.component["name"] == rdt.component.name |
| 779 |
assert isinstance(new_rdt.variable, dict) |
| 780 |
assert new_rdt.variable["name"] == rdt.variable.name |
| 781 |
assert isinstance(new_rdt.variable_attribute[0], dict) |
| 782 |
assert new_rdt.variable_attribute[0]["type"] == rdt.variable_attribute[0].type |
| 783 |
assert new_rdt.variable_attribute[0]["value"] == rdt.variable_attribute[0].value |
| 784 |
assert isinstance(new_rdt.variable_characteristics, dict) |
| 785 |
assert new_rdt.variable_characteristics["unit"] == rdt.variable_characteristics.unit |
| 786 |
assert ( |
| 787 |
new_rdt.variable_characteristics["data_type"] |
| 788 |
== rdt.variable_characteristics.data_type |
| 789 |
) |
| 790 |
assert ( |
| 791 |
new_rdt.variable_characteristics["supports_monitoring"] |
| 792 |
== rdt.variable_characteristics.supports_monitoring |
| 793 |
) |
| 794 |
|
| 795 |
|
| 796 |
def test_sales_tariff_entry_type(): |
| 797 |
stet = SalesTariffEntryType( |
| 798 |
e_price_level=1, |
| 799 |
relative_time_interval=RelativeTimeIntervalType(start=0, duration=3600), |
| 800 |
consumption_cost=[ |
| 801 |
ConsumptionCostType( |
| 802 |
start_value=0.0, |
| 803 |
cost=[ |
| 804 |
CostType(cost_kind="RelativePrice", amount=1.0, amount_multiplier=0) |
| 805 |
], |
| 806 |
) |
| 807 |
], |
| 808 |
) |
| 809 |
|
| 810 |
new_stet = to_datatype(SalesTariffEntryType, stet) |
| 811 |
|
| 812 |
assert new_stet.e_price_level == stet.e_price_level |
| 813 |
assert isinstance(new_stet.relative_time_interval, dict) |
| 814 |
assert new_stet.relative_time_interval["start"] == stet.relative_time_interval.start |
| 815 |
assert ( |
| 816 |
new_stet.relative_time_interval["duration"] |
| 817 |
== stet.relative_time_interval.duration |
| 818 |
) |
| 819 |
assert isinstance(new_stet.consumption_cost[0], dict) |
| 820 |
assert ( |
| 821 |
new_stet.consumption_cost[0]["start_value"] |
| 822 |
== stet.consumption_cost[0].start_value |
| 823 |
) |
| 824 |
assert isinstance(new_stet.consumption_cost[0]["cost"][0], dict) |
| 825 |
assert ( |
| 826 |
new_stet.consumption_cost[0]["cost"][0]["cost_kind"] |
| 827 |
== stet.consumption_cost[0].cost[0].cost_kind |
| 828 |
) |
| 829 |
assert ( |
| 830 |
new_stet.consumption_cost[0]["cost"][0]["amount"] |
| 831 |
== stet.consumption_cost[0].cost[0].amount |
| 832 |
) |
| 833 |
assert ( |
| 834 |
new_stet.consumption_cost[0]["cost"][0]["amount_multiplier"] |
| 835 |
== stet.consumption_cost[0].cost[0].amount_multiplier |
| 836 |
) |
| 837 |
|
| 838 |
|
| 839 |
def test_sampled_value_type(): |
| 840 |
svt = SampledValueType( |
| 841 |
value=230.0, |
| 842 |
context=ReadingContextEnumType.sample_periodic, |
| 843 |
measurand=MeasurandEnumType.voltage, |
| 844 |
phase=PhaseEnumType.l1, |
| 845 |
location=LocationEnumType.outlet, |
| 846 |
unit_of_measure=UnitOfMeasureType( |
| 847 |
unit=StandardizedUnitsOfMeasureType.v, multiplier=0 |
| 848 |
), |
| 849 |
) |
| 850 |
|
| 851 |
new_svt = to_datatype(SampledValueType, svt) |
| 852 |
|
| 853 |
assert new_svt.value == svt.value |
| 854 |
assert new_svt.context == svt.context |
| 855 |
assert new_svt.measurand == svt.measurand |
| 856 |
assert new_svt.phase == svt.phase |
| 857 |
assert new_svt.location == svt.location |
| 858 |
assert isinstance(new_svt.unit_of_measure, dict) |
| 859 |
assert new_svt.unit_of_measure["unit"] == svt.unit_of_measure.unit |
| 860 |
assert new_svt.unit_of_measure["multiplier"] == svt.unit_of_measure.multiplier |
| 861 |
|
| 862 |
|
| 863 |
def test_set_monitoring_data_type(): |
| 864 |
smdt = SetMonitoringDataType( |
| 865 |
value=100.0, |
| 866 |
type=MonitorEnumType.upper_threshold, |
| 867 |
severity=1, |
| 868 |
component=ComponentType(name="MainController", instance="instance1"), |
| 869 |
variable=VariableType(name="Temperature", instance="instance1"), |
| 870 |
id=123456, |
| 871 |
) |
| 872 |
|
| 873 |
new_smdt = to_datatype(SetMonitoringDataType, smdt) |
| 874 |
|
| 875 |
assert new_smdt.value == smdt.value |
| 876 |
assert new_smdt.type == smdt.type |
| 877 |
assert new_smdt.severity == smdt.severity |
| 878 |
assert isinstance(new_smdt.component, dict) |
| 879 |
assert new_smdt.component["name"] == smdt.component.name |
| 880 |
assert new_smdt.component["instance"] == smdt.component.instance |
| 881 |
assert isinstance(new_smdt.variable, dict) |
| 882 |
assert new_smdt.variable["name"] == smdt.variable.name |
| 883 |
assert new_smdt.variable["instance"] == smdt.variable.instance |
| 884 |
assert new_smdt.id == smdt.id |
| 885 |
|
| 886 |
|
| 887 |
def test_set_monitoring_result_type(): |
| 888 |
smrt = SetMonitoringResultType( |
| 889 |
status=SetMonitoringStatusEnumType.accepted, |
| 890 |
id=123, |
| 891 |
status_info=StatusInfoType( |
| 892 |
reason_code=ReasonEnumType.other, |
| 893 |
additional_info="Successfully set monitoring", |
| 894 |
), |
| 895 |
type=MonitorEnumType.upper_threshold, |
| 896 |
severity=1, |
| 897 |
component=ComponentType(name="MainController", instance="instance1"), |
| 898 |
variable=VariableType(name="Temperature", instance="instance1"), |
| 899 |
) |
| 900 |
|
| 901 |
new_smrt = to_datatype(SetMonitoringResultType, smrt) |
| 902 |
|
| 903 |
assert new_smrt.status == smrt.status |
| 904 |
assert new_smrt.id == smrt.id |
| 905 |
assert isinstance(new_smrt.status_info, dict) |
| 906 |
assert new_smrt.status_info["reason_code"] == smrt.status_info.reason_code |
| 907 |
assert new_smrt.status_info["additional_info"] == smrt.status_info.additional_info |
| 908 |
assert new_smrt.type == smrt.type |
| 909 |
assert new_smrt.severity == smrt.severity |
| 910 |
assert isinstance(new_smrt.component, dict) |
| 911 |
assert new_smrt.component["name"] == smrt.component.name |
| 912 |
assert new_smrt.component["instance"] == smrt.component.instance |
| 913 |
assert isinstance(new_smrt.variable, dict) |
| 914 |
assert new_smrt.variable["name"] == smrt.variable.name |
| 915 |
assert new_smrt.variable["instance"] == smrt.variable.instance |
| 916 |
|
| 917 |
|
| 918 |
def test_set_variable_result_type(): |
| 919 |
svrt = SetVariableResultType( |
| 920 |
attribute_type=AttributeEnumType.actual, |
| 921 |
attribute_status=SetVariableStatusEnumType.accepted, |
| 922 |
component=ComponentType(name="MainController", instance="instance1"), |
| 923 |
variable=VariableType(name="CurrentLimit", instance="instance1"), |
| 924 |
attribute_status_info=StatusInfoType( |
| 925 |
reason_code=ReasonEnumType.other, |
| 926 |
additional_info="Successfully set variable", |
| 927 |
), |
| 928 |
) |
| 929 |
|
| 930 |
new_svrt = to_datatype(SetVariableResultType, svrt) |
| 931 |
|
| 932 |
assert new_svrt.attribute_type == svrt.attribute_type |
| 933 |
assert new_svrt.attribute_status == svrt.attribute_status |
| 934 |
assert isinstance(new_svrt.component, dict) |
| 935 |
assert new_svrt.component["name"] == svrt.component.name |
| 936 |
assert new_svrt.component["instance"] == svrt.component.instance |
| 937 |
assert isinstance(new_svrt.variable, dict) |
| 938 |
assert new_svrt.variable["name"] == svrt.variable.name |
| 939 |
assert new_svrt.variable["instance"] == svrt.variable.instance |
| 940 |
assert isinstance(new_svrt.attribute_status_info, dict) |
| 941 |
assert ( |
| 942 |
new_svrt.attribute_status_info["reason_code"] |
| 943 |
== svrt.attribute_status_info.reason_code |
| 944 |
) |
| 945 |
assert ( |
| 946 |
new_svrt.attribute_status_info["additional_info"] |
| 947 |
== svrt.attribute_status_info.additional_info |
| 948 |
) |
| 949 |
|
| 950 |
|
| 951 |
def test_unit_of_measure_type(): |
| 952 |
uomt = UnitOfMeasureType( |
| 953 |
# unit=UnitOfMeasureType.w, |
| 954 |
multiplier=1 |
| 955 |
) |
| 956 |
|
| 957 |
new_uomt = to_datatype(UnitOfMeasureType, uomt) |
| 958 |
|
| 959 |
assert new_uomt.unit == uomt.unit |
| 960 |
assert new_uomt.multiplier == uomt.multiplier |
| 961 |
|
| 962 |
|
| 963 |
def test_variable_attribute_type(): |
| 964 |
vat = VariableAttributeType( |
| 965 |
type=AttributeEnumType.actual, |
| 966 |
value="25.5", |
| 967 |
mutability=MutabilityEnumType.read_write, |
| 968 |
persistent=True, |
| 969 |
constant=False, |
| 970 |
) |
| 971 |
|
| 972 |
new_vat = to_datatype(VariableAttributeType, vat) |
| 973 |
|
| 974 |
assert new_vat.type == vat.type |
| 975 |
assert new_vat.value == vat.value |
| 976 |
assert new_vat.mutability == vat.mutability |
| 977 |
assert new_vat.persistent == vat.persistent |
| 978 |
assert new_vat.constant == vat.constant |
| 979 |
|
| 980 |
|
| 981 |
def test_variable_characteristics_type(): |
| 982 |
vct = VariableCharacteristicsType( |
| 983 |
unit="Celsius", |
| 984 |
data_type=DataEnumType.decimal, |
| 985 |
min_limit="-20", |
| 986 |
max_limit="50", |
| 987 |
values_list=["10", "20", "30"], |
| 988 |
supports_monitoring=True, |
| 989 |
) |
| 990 |
|
| 991 |
new_vct = to_datatype(VariableCharacteristicsType, vct) |
| 992 |
|
| 993 |
assert new_vct.unit == vct.unit |
| 994 |
assert new_vct.data_type == vct.data_type |
| 995 |
assert new_vct.min_limit == vct.min_limit |
| 996 |
assert new_vct.max_limit == vct.max_limit |
| 997 |
assert new_vct.values_list == vct.values_list |
| 998 |
assert new_vct.supports_monitoring == vct.supports_monitoring |
| 999 |
|
| 1000 |
|
| 1001 |
def test_variable_monitoring_type(): |
| 1002 |
vmt = VariableMonitoringType( |
| 1003 |
id=1, |
| 1004 |
transaction=True, |
| 1005 |
value=100.0, |
| 1006 |
type=MonitorEnumType.upper_threshold, |
| 1007 |
severity=1, |
| 1008 |
) |
| 1009 |
|
| 1010 |
new_vmt = to_datatype(VariableMonitoringType, vmt) |
| 1011 |
|
| 1012 |
assert new_vmt.id == vmt.id |
| 1013 |
assert new_vmt.transaction == vmt.transaction |
| 1014 |
assert new_vmt.value == vmt.value |
| 1015 |
assert new_vmt.type == vmt.type |
| 1016 |
assert new_vmt.severity == vmt.severity |