ocpp_rs 0.2.5

Protocol implementation for Open Charge Point Protocol (OCPP) in Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
//! # Call
//!
//! This module contains the `Call` struct and its variants, which are the actions that can be sent to the Charge Point.
//! //! ## Example
//! Receiving a payload from a client:
//! ```rust
//! use ocpp_rs::v16::parse::{self, Message};
//! use ocpp_rs::v16::call::{Action, Call};
//!
//! // Example incoming message
//! let incoming_json = "[2, \"19223201\", \"BootNotification\", { \"chargePointVendor\": \"VendorX\", \"chargePointModel\": \"SingleSocketCharger\" }]";
//! let incoming_message = parse::deserialize_to_message(incoming_json);
//!
//! // Handle incoming message (Check the type of the message)
//! if let Ok(Message::Call(call)) = incoming_message {
//!     match call.payload {
//!         Action::BootNotification(boot_notification) => {
//!            // Do something with boot_notification
//!         },
//!         _ => {
//!           // Handle other actions
//!         }
//!    }
//! }
//! ```
use core::fmt::Formatter;

use super::data_types::{DateTimeWrapper, MeterValue};
use super::enums::{
    AvailabilityType, CertificateUse, ChargePointErrorCode, ChargePointStatus,
    ChargingProfilePurposeType, ChargingRateUnitType, DiagnosticsStatus, FirmwareStatus, Log,
    MessageTrigger, Reason, ResetType, UpdateType, UploadLogStatus,
};

use super::utils::{iso8601_date_time, iso8601_date_time_optional};
use alloc::collections::btree_map::BTreeMap;
use alloc::string::String;
use alloc::vec::Vec;
use serde::Deserializer;
use serde::de::SeqAccess;
use serde::{Deserialize, Serialize};
use serde_tuple::Serialize_tuple;

use crate::alloc::string::ToString;
use strum_macros::AsRefStr;

/// Call action enum that contains all the possible actions that can be sent to the Charge Point.\\
/// Please look at the OCPP 1.6 specification for more information    
#[derive(AsRefStr, Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[serde(untagged)]
pub enum Action {
    Authorize(Authorize),
    BootNotification(BootNotification),
    CancelReservation(CancelReservation),
    CertificateSigned(CertificateSigned),
    ChangeAvailability(ChangeAvailability),
    ChangeConfiguration(ChangeConfiguration),
    ClearCache(ClearCache),
    ClearChargingProfile(ClearChargingProfile),
    DataTransfer(DataTransfer),
    DeleteCertificate(DeleteCertificate),
    DiagnosticsStatusNotification(DiagnosticsStatusNotification),
    ExtendedTriggerMessage(ExtendedTriggerMessage),
    FirmwareStatusNotification(FirmwareStatusNotification),
    GetCompositeSchedule(GetCompositeSchedule),
    GetConfiguration(GetConfiguration),
    GetDiagnostics(GetDiagnostics),
    GetInstalledCertificateIds(GetInstalledCertificateIds),
    GetLocalListVersion(GetLocalListVersion),
    GetLog(GetLog),
    Heartbeat(Heartbeat),
    InstallCertificate(InstallCertificate),
    LogStatusNotification(LogStatusNotification),
    MeterValues(MeterValues),
    RemoteStartTransaction(RemoteStartTransaction),
    RemoteStopTransaction(RemoteStopTransaction),
    ReserveNow(ReserveNow),
    Reset(Reset),
    SecurityEventNotification(SecurityEventNotification),
    SendLocalList(SendLocalList),
    SetChargingProfile(SetChargingProfile),
    SignCertificate(SignCertificate),
    SignedFirmwareStatusNotification(SignedFirmwareStatusNotification),
    SignedUpdateFirmware(SignedUpdateFirmware),
    StartTransaction(StartTransaction),
    StatusNotification(StatusNotification),
    StopTransaction(StopTransaction),
    TriggerMessage(TriggerMessage),
    UnlockConnector(UnlockConnector),
    UpdateFirmware(UpdateFirmware),
}

#[derive(Debug, PartialEq, Eq, Serialize_tuple, Clone)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Call {
    pub(super) message_id: i32,
    pub unique_id: String,
    pub(crate) action: String,
    pub payload: Action,
}

impl Call {
    #[must_use]
    /// Create a new Call struct
    /// # Arguments
    /// * `unique_id` - A unique positive integer string identifier for the call
    /// * `payload` - The payload of the call
    ///
    pub fn new(unique_id: String, payload: Action) -> Self {
        Self {
            message_id: 2,
            unique_id,
            action: payload.as_ref().to_string(),
            payload,
        }
    }
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct CancelReservation {
    pub reservation_id: i32,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct CertificateSigned {
    pub certificate_chain: String,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct ChangeAvailability {
    pub connector_id: u32,
    #[serde(rename = "type")]
    pub availability_type: AvailabilityType,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct ChangeConfiguration {
    pub key: String,
    pub value: String,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct ClearCache {}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct ClearChargingProfile {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<i32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub connector_id: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub charging_profile_purpose: Option<ChargingProfilePurposeType>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub stack_level: Option<i32>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct DeleteCertificate {
    pub certificate_hash_data: BTreeMap<String, String>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct ExtendedTriggerMessage {
    pub requested_message: MessageTrigger,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub connector_id: Option<u32>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct GetCompositeSchedule {
    pub connector_id: u32,
    pub duration: i32,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub charging_rate_unit: Option<ChargingRateUnitType>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct GetConfiguration {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub key: Option<Vec<String>>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct GetDiagnostics {
    pub location: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub retries: Option<i32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub retry_interval: Option<i32>,
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(with = "iso8601_date_time_optional")]
    pub start_time: Option<DateTimeWrapper>,
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(with = "iso8601_date_time_optional")]
    pub stop_time: Option<DateTimeWrapper>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct GetInstalledCertificateIds {
    pub certificate_type: CertificateUse,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct GetLocalListVersion {}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct GetLog {
    pub log: BTreeMap<String, String>,
    pub log_type: Log,
    pub request_id: i32,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub retries: Option<i32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub retry_interval: Option<i32>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct InstallCertificate {
    pub certificate_type: CertificateUse,
    pub certificate: String,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct RemoteStartTransaction {
    pub id_tag: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub connector_id: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub charging_profile: Option<BTreeMap<String, String>>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct RemoteStopTransaction {
    pub transaction_id: i32,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct ReserveNow {
    pub connector_id: u32,
    #[serde(with = "iso8601_date_time")]
    pub expiry_date: DateTimeWrapper,
    pub id_tag: String,
    pub reservation_id: i32,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub parent_id_tag: Option<String>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Reset {
    #[serde(rename = "type")]
    pub reset_type: ResetType,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct SendLocalList {
    pub list_version: i32,
    pub update_type: UpdateType,
    pub local_authorization_list: Vec<String>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct SetChargingProfile {
    pub connector_id: u32,
    pub cs_charging_profiles: BTreeMap<String, String>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct SignedUpdateFirmware {
    pub request_id: i32,
    pub firmware: BTreeMap<String, String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub retries: Option<i32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub retry_interval: Option<i32>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct TriggerMessage {
    pub requested_message: MessageTrigger,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub connector_id: Option<u32>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct UnlockConnector {
    pub connector_id: u32,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct UpdateFirmware {
    pub location: String,
    #[serde(with = "iso8601_date_time")]
    pub retrieve_date: DateTimeWrapper,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub retries: Option<i32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub retry_interval: Option<i32>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Authorize {
    pub id_tag: String,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct BootNotification {
    pub charge_point_model: String,
    pub charge_point_vendor: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub charge_box_serial_number: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub charge_point_serial_number: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub firmware_version: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub iccid: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub imsi: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub meter_serial_number: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub meter_type: Option<String>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct DiagnosticsStatusNotification {
    pub status: DiagnosticsStatus,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct FirmwareStatusNotification {
    pub status: FirmwareStatus,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Heartbeat {}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct LogStatusNotification {
    pub status: UploadLogStatus,
    pub request_id: i32,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct MeterValues {
    pub connector_id: u32,
    pub meter_value: Vec<MeterValue>,
    pub transaction_id: Option<i32>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct SecurityEventNotification {
    #[serde(rename = "type")]
    pub event_type: String,
    #[serde(with = "iso8601_date_time")]
    pub timestamp: DateTimeWrapper,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tech_info: Option<String>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct SignCertificate {
    pub csr: String,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct SignedFirmwareStatusNotification {
    pub status: FirmwareStatus,
    pub request_id: i32,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct StartTransaction {
    pub connector_id: u32,
    pub id_tag: String,
    pub meter_start: u64,
    #[serde(with = "iso8601_date_time")]
    pub timestamp: DateTimeWrapper,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reservation_id: Option<i32>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct StopTransaction {
    pub meter_stop: u64,
    #[serde(with = "iso8601_date_time")]
    pub timestamp: DateTimeWrapper,
    pub transaction_id: i32,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reason: Option<Reason>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id_tag: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub transaction_data: Option<Vec<MeterValue>>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct StatusNotification {
    pub connector_id: u32,
    pub error_code: ChargePointErrorCode,
    pub status: ChargePointStatus,
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(with = "iso8601_date_time_optional")]
    pub timestamp: Option<DateTimeWrapper>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub info: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub vendor_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub vendor_error_code: Option<String>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct DataTransfer {
    pub vendor_id: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub data: Option<String>,
}

impl<'de> Deserialize<'de> for Call {
    /// We need to manually implement the deserialization of the Call struct because the payload\\
    /// which has some variant types cannot be deserialized automatically, like `Heartbeat` and `ClearCache` which are empty structs.    
    #[allow(clippy::too_many_lines)]
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: Deserializer<'de>,
    {
        struct CallVisitor;

        impl<'de> serde::de::Visitor<'de> for CallVisitor {
            type Value = Call;

            fn expecting(&self, formatter: &mut Formatter) -> core::fmt::Result {
                formatter.write_str("a sequence with at least two elements")
            }

            fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
            where
                A: SeqAccess<'de>,
            {
                let _message_id: i32 = seq
                    .next_element()?
                    .ok_or_else(|| serde::de::Error::invalid_length(0, &self))?;
                let unique_id: String = seq
                    .next_element()?
                    .ok_or_else(|| serde::de::Error::invalid_length(1, &self))?;
                let action: String = seq
                    .next_element()?
                    .ok_or_else(|| serde::de::Error::invalid_length(2, &self))?;

                match action.as_str() {
                    "Authorize" => {
                        let data: Authorize = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::Authorize(data)))
                    }
                    "BootNotification" => {
                        let data: BootNotification = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::BootNotification(data)))
                    }
                    "CancelReservation" => {
                        let data: CancelReservation = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::CancelReservation(data)))
                    }
                    "CertificateSigned" => {
                        let data: CertificateSigned = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::CertificateSigned(data)))
                    }
                    "ChangeAvailability" => {
                        let data: ChangeAvailability = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::ChangeAvailability(data)))
                    }
                    "ChangeConfiguration" => {
                        let data: ChangeConfiguration = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::ChangeConfiguration(data)))
                    }
                    "ClearCache" => {
                        let data: ClearCache = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::ClearCache(data)))
                    }
                    "ClearChargingProfile" => {
                        let data: ClearChargingProfile = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::ClearChargingProfile(data)))
                    }
                    "DataTransfer" => {
                        let data: DataTransfer = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::DataTransfer(data)))
                    }
                    "DeleteCertificate" => {
                        let data: DeleteCertificate = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::DeleteCertificate(data)))
                    }
                    "DiagnosticsStatusNotification" => {
                        let data: DiagnosticsStatusNotification = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(
                            unique_id,
                            Action::DiagnosticsStatusNotification(data),
                        ))
                    }
                    "ExtendedTriggerMessage" => {
                        let data: ExtendedTriggerMessage = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::ExtendedTriggerMessage(data)))
                    }
                    "FirmwareStatusNotification" => {
                        let data: FirmwareStatusNotification = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(
                            unique_id,
                            Action::FirmwareStatusNotification(data),
                        ))
                    }
                    "GetCompositeSchedule" => {
                        let data: GetCompositeSchedule = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::GetCompositeSchedule(data)))
                    }
                    "GetConfiguration" => {
                        let data: GetConfiguration = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::GetConfiguration(data)))
                    }
                    "GetDiagnostics" => {
                        let data: GetDiagnostics = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::GetDiagnostics(data)))
                    }
                    "GetInstalledCertificateIds" => {
                        let data: GetInstalledCertificateIds = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(
                            unique_id,
                            Action::GetInstalledCertificateIds(data),
                        ))
                    }
                    "GetLocalListVersion" => {
                        let data: GetLocalListVersion = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::GetLocalListVersion(data)))
                    }
                    "GetLog" => {
                        let data: GetLog = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::GetLog(data)))
                    }
                    "Heartbeat" => {
                        let data: Heartbeat = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::Heartbeat(data)))
                    }
                    "InstallCertificate" => {
                        let data: InstallCertificate = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::InstallCertificate(data)))
                    }
                    "LogStatusNotification" => {
                        let data: LogStatusNotification = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::LogStatusNotification(data)))
                    }
                    "MeterValues" => {
                        let data: MeterValues = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::MeterValues(data)))
                    }
                    "RemoteStartTransaction" => {
                        let data: RemoteStartTransaction = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::RemoteStartTransaction(data)))
                    }
                    "RemoteStopTransaction" => {
                        let data: RemoteStopTransaction = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::RemoteStopTransaction(data)))
                    }
                    "ReserveNow" => {
                        let data: ReserveNow = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::ReserveNow(data)))
                    }
                    "Reset" => {
                        let data: Reset = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::Reset(data)))
                    }
                    "SecurityEventNotification" => {
                        let data: SecurityEventNotification = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(
                            unique_id,
                            Action::SecurityEventNotification(data),
                        ))
                    }
                    "SendLocalList" => {
                        let data: SendLocalList = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::SendLocalList(data)))
                    }
                    "SetChargingProfile" => {
                        let data: SetChargingProfile = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::SetChargingProfile(data)))
                    }
                    "SignCertificate" => {
                        let data: SignCertificate = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::SignCertificate(data)))
                    }
                    "SignedFirmwareStatusNotification" => {
                        let data: SignedFirmwareStatusNotification = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(
                            unique_id,
                            Action::SignedFirmwareStatusNotification(data),
                        ))
                    }
                    "SignedUpdateFirmware" => {
                        let data: SignedUpdateFirmware = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::SignedUpdateFirmware(data)))
                    }
                    "StartTransaction" => {
                        let data: StartTransaction = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::StartTransaction(data)))
                    }
                    "StatusNotification" => {
                        let data: StatusNotification = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::StatusNotification(data)))
                    }
                    "StopTransaction" => {
                        let data: StopTransaction = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::StopTransaction(data)))
                    }
                    "TriggerMessage" => {
                        let data: TriggerMessage = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::TriggerMessage(data)))
                    }
                    "UnlockConnector" => {
                        let data: UnlockConnector = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::UnlockConnector(data)))
                    }
                    "UpdateFirmware" => {
                        let data: UpdateFirmware = seq
                            .next_element()?
                            .ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
                        Ok(Call::new(unique_id, Action::UpdateFirmware(data)))
                    }

                    _ => Err(serde::de::Error::unknown_variant(
                        &action,
                        &[
                            "Authorize",
                            "BootNotification",
                            "CancelReservation",
                            "CertificateSigned",
                            "ChangeAvailability",
                            "ChangeConfiguration",
                            "ClearCache",
                            "ClearChargingProfile",
                            "DataTransfer",
                            "DeleteCertificate",
                            "DiagnosticsStatusNotification",
                            "ExtendedTriggerMessage",
                            "FirmwareStatusNotification",
                            "GetCompositeSchedule",
                            "GetConfiguration",
                            "GetDiagnostics",
                            "GetInstalledCertificateIds",
                            "GetLocalListVersion",
                            "GetLog",
                            "Heartbeat",
                            "InstallCertificate",
                            "LogStatusNotification",
                            "MeterValues",
                            "RemoteStartTransaction",
                            "RemoteStopTransaction",
                            "ReserveNow",
                            "Reset",
                            "SecurityEventNotification",
                            "SendLocalList",
                            "SetChargingProfile",
                            "SignCertificate",
                            "SignedFirmwareStatusNotification",
                            "SignedUpdateFirmware",
                            "StartTransaction",
                            "StatusNotification",
                            "StopTransaction",
                            "TriggerMessage",
                            "UnlockConnector",
                            "UpdateFirmware",
                        ],
                    )),
                }
            }
        }

        deserializer.deserialize_seq(CallVisitor)
    }
}