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
use chrono::{NaiveDate, NaiveTime, TimeDelta};
use crate::{tariff, Ampere, Kw, Kwh, Weekday};
impl tariff::v221::Restrictions {
/// Return the restrictions split into time and energy categories.
pub(super) fn restrictions_by_category(&self) -> (TimeRestrictions, EnergyRestrictions) {
let tariff::v221::Restrictions {
start_time,
end_time,
start_date,
end_date,
min_kwh,
max_kwh,
min_current,
max_current,
min_power,
max_power,
min_duration,
max_duration,
day_of_week,
} = self;
let time = TimeRestrictions {
start_time: *start_time,
end_time: *end_time,
start_date: *start_date,
end_date: *end_date,
min_duration: *min_duration,
max_duration: *max_duration,
weekdays: WeekdaySet(day_of_week.clone()),
};
let energy = EnergyRestrictions {
min_kwh: *min_kwh,
max_kwh: *max_kwh,
min_current: *min_current,
max_current: *max_current,
min_power: *min_power,
max_power: *max_power,
};
(time, energy)
}
}
#[derive(Debug)]
#[cfg_attr(test, derive(Default))]
pub(super) struct EnergyRestrictions {
/// Minimum consumed energy in kWh, for example 20, valid from this amount of energy (inclusive) being used.
pub min_kwh: Option<Kwh>,
/// Maximum consumed energy in kWh, for example 50, valid until this amount of energy (exclusive) being used.
pub max_kwh: Option<Kwh>,
/// If the charging current is equal to or lower than this value, the associated `TariffElement` becomes inactive.
pub min_current: Option<Ampere>,
/// If the charging current is equal to or higher than this value, the associated `TariffElement` becomes inactive.
pub max_current: Option<Ampere>,
/// If the charging power is equal to or lower than this value, the associated `TariffElement` becomes inactive.
pub min_power: Option<Kw>,
/// If the charging power is equal to or higher than this value, the associated `TariffElement` becomes inactive.
pub max_power: Option<Kw>,
}
#[derive(Debug)]
#[cfg_attr(test, derive(Default))]
pub(super) struct TimeRestrictions {
/// The `Element` is valid from this time of day in local time.
pub start_time: Option<NaiveTime>,
/// The `Element` is valid until this time of day in local time.
pub end_time: Option<NaiveTime>,
/// The `Element` is valid from this date (inclusive) in local time.
pub start_date: Option<NaiveDate>,
/// The `Element` is valid until this date (exclusive) in local time.
pub end_date: Option<NaiveDate>,
/// Minimum duration in seconds the Charging Session MUST last (inclusive).
///
/// When the duration of a Charging Session is longer than the defined value, this `TariffElement` is or becomes active.
/// Before that moment, this `TariffElement` is not yet active.
pub min_duration: Option<TimeDelta>,
/// Maximum duration in seconds the Charging Session MUST last (exclusive).
///
/// When the duration of a Charging Session is shorter than the defined value, this `TariffElement` is or becomes active.
/// After that moment, this `TariffElement` is no longer active.
pub max_duration: Option<TimeDelta>,
/// Which day(s) of the week this `TariffElement` is active.
pub weekdays: WeekdaySet,
}
#[derive(Debug, Default)]
pub(crate) struct WeekdaySet(pub Option<Vec<Weekday>>);
impl WeekdaySet {
/// Returns true if there are no `Weekday`s listed or the given weekday is in the list.
pub(super) fn contains(&self, weekday: chrono::Weekday) -> bool {
let Some(weekdays) = &self.0 else {
return true;
};
weekdays.contains(&weekday.into())
}
}