s2-python 0.0.1__py3-none-any.whl → 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. {s2_python-0.0.1.dist-info → s2_python-0.2.0.dist-info}/METADATA +22 -4
  2. s2_python-0.2.0.dist-info/RECORD +54 -0
  3. {s2_python-0.0.1.dist-info → s2_python-0.2.0.dist-info}/WHEEL +1 -1
  4. s2python/__init__.py +1 -1
  5. s2python/common/__init__.py +1 -1
  6. s2python/common/duration.py +5 -5
  7. s2python/common/handshake.py +5 -5
  8. s2python/common/handshake_response.py +5 -5
  9. s2python/common/instruction_status_update.py +6 -10
  10. s2python/common/number_range.py +17 -21
  11. s2python/common/power_forecast.py +7 -9
  12. s2python/common/power_forecast_element.py +9 -10
  13. s2python/common/power_forecast_value.py +4 -6
  14. s2python/common/power_measurement.py +7 -7
  15. s2python/common/power_range.py +11 -13
  16. s2python/common/power_value.py +4 -4
  17. s2python/common/reception_status.py +5 -7
  18. s2python/common/resource_manager_details.py +11 -12
  19. s2python/common/revoke_object.py +6 -6
  20. s2python/common/role.py +4 -4
  21. s2python/common/select_control_type.py +5 -5
  22. s2python/common/session_request.py +5 -5
  23. s2python/common/support.py +6 -4
  24. s2python/common/timer.py +6 -6
  25. s2python/common/transition.py +12 -14
  26. s2python/frbc/frbc_actuator_description.py +53 -74
  27. s2python/frbc/frbc_actuator_status.py +10 -12
  28. s2python/frbc/frbc_fill_level_target_profile.py +10 -14
  29. s2python/frbc/frbc_fill_level_target_profile_element.py +7 -9
  30. s2python/frbc/frbc_instruction.py +8 -8
  31. s2python/frbc/frbc_leakage_behaviour.py +8 -10
  32. s2python/frbc/frbc_leakage_behaviour_element.py +6 -8
  33. s2python/frbc/frbc_operation_mode.py +19 -29
  34. s2python/frbc/frbc_operation_mode_element.py +11 -13
  35. s2python/frbc/frbc_storage_description.py +6 -8
  36. s2python/frbc/frbc_storage_status.py +5 -5
  37. s2python/frbc/frbc_system_description.py +10 -13
  38. s2python/frbc/frbc_timer_status.py +7 -7
  39. s2python/frbc/frbc_usage_forecast.py +7 -9
  40. s2python/frbc/frbc_usage_forecast_element.py +5 -7
  41. s2python/frbc/rm.py +0 -0
  42. s2python/generated/gen_s2.py +1150 -1130
  43. s2python/reception_status_awaiter.py +60 -0
  44. s2python/s2_connection.py +470 -0
  45. s2python/s2_control_type.py +56 -0
  46. s2python/s2_parser.py +113 -0
  47. s2python/s2_validation_error.py +7 -5
  48. s2python/utils.py +7 -2
  49. s2python/validate_values_mixin.py +32 -89
  50. s2python/version.py +2 -0
  51. s2_python-0.0.1.dist-info/RECORD +0 -49
  52. {s2_python-0.0.1.dist-info → s2_python-0.2.0.dist-info}/entry_points.txt +0 -0
  53. {s2_python-0.0.1.dist-info → s2_python-0.2.0.dist-info}/top_level.txt +0 -0
s2python/common/timer.py CHANGED
@@ -3,15 +3,15 @@ import uuid
3
3
  from s2python.common.duration import Duration
4
4
  from s2python.generated.gen_s2 import Timer as GenTimer
5
5
  from s2python.validate_values_mixin import (
6
- ValidateValuesMixin,
6
+ S2Message,
7
7
  catch_and_convert_exceptions,
8
8
  )
9
9
 
10
10
 
11
11
  @catch_and_convert_exceptions
12
- class Timer(GenTimer, ValidateValuesMixin["Timer"]):
13
- class Config(GenTimer.Config):
14
- validate_assignment = True
12
+ class Timer(GenTimer, S2Message["Timer"]):
13
+ model_config = GenTimer.model_config
14
+ model_config["validate_assignment"] = True
15
15
 
16
- id: uuid.UUID = GenTimer.__fields__["id"].field_info # type: ignore[assignment]
17
- duration: Duration = GenTimer.__fields__["duration"].field_info # type: ignore[assignment]
16
+ id: uuid.UUID = GenTimer.model_fields["id"] # type: ignore[assignment]
17
+ duration: Duration = GenTimer.model_fields["duration"] # type: ignore[assignment]
@@ -1,26 +1,24 @@
1
1
  import uuid
2
2
  from typing import Optional, List
3
3
 
4
- from s2python.common import Duration
4
+ from s2python.common.duration import Duration
5
5
  from s2python.generated.gen_s2 import Transition as GenTransition
6
6
  from s2python.validate_values_mixin import (
7
- ValidateValuesMixin,
7
+ S2Message,
8
8
  catch_and_convert_exceptions,
9
9
  )
10
10
 
11
11
 
12
12
  @catch_and_convert_exceptions
13
- class Transition(GenTransition, ValidateValuesMixin["Transition"]):
14
- class Config(GenTransition.Config):
15
- validate_assignment = True
13
+ class Transition(GenTransition, S2Message["Transition"]):
14
+ model_config = GenTransition.model_config
15
+ model_config["validate_assignment"] = True
16
16
 
17
- id: uuid.UUID = GenTransition.__fields__["id"].field_info # type: ignore[assignment]
18
- from_: uuid.UUID = GenTransition.__fields__["from_"].field_info # type: ignore[assignment]
19
- to: uuid.UUID = GenTransition.__fields__["to"].field_info # type: ignore[assignment]
20
- start_timers: List[uuid.UUID] = GenTransition.__fields__["start_timers"].field_info # type: ignore[assignment]
21
- blocking_timers: List[uuid.UUID] = GenTransition.__fields__[
22
- "blocking_timers"
23
- ].field_info # type: ignore[assignment]
24
- transition_duration: Optional[Duration] = GenTransition.__fields__[
17
+ id: uuid.UUID = GenTransition.model_fields["id"] # type: ignore[assignment]
18
+ from_: uuid.UUID = GenTransition.model_fields["from_"] # type: ignore[assignment]
19
+ to: uuid.UUID = GenTransition.model_fields["to"] # type: ignore[assignment]
20
+ start_timers: List[uuid.UUID] = GenTransition.model_fields["start_timers"] # type: ignore[assignment]
21
+ blocking_timers: List[uuid.UUID] = GenTransition.model_fields["blocking_timers"] # type: ignore[assignment]
22
+ transition_duration: Optional[Duration] = GenTransition.model_fields[
25
23
  "transition_duration"
26
- ].field_info # type: ignore[assignment]
24
+ ] # type: ignore[assignment]
@@ -1,50 +1,46 @@
1
1
  import uuid
2
2
 
3
- from typing import List, Any, Dict
3
+ from typing import List
4
+ from typing_extensions import Self
4
5
 
5
- from pydantic import root_validator
6
+ from pydantic import model_validator
6
7
 
7
8
  from s2python.common import Transition, Timer, Commodity
8
9
  from s2python.common.support import commodity_has_quantity
9
- from s2python.frbc import FRBCOperationMode
10
+ from s2python.frbc.frbc_operation_mode import FRBCOperationMode
10
11
  from s2python.generated.gen_s2 import (
11
12
  FRBCActuatorDescription as GenFRBCActuatorDescription,
12
- CommodityQuantity,
13
13
  )
14
14
  from s2python.validate_values_mixin import (
15
- ValidateValuesMixin,
15
+ S2Message,
16
16
  catch_and_convert_exceptions,
17
17
  )
18
18
 
19
19
 
20
20
  @catch_and_convert_exceptions
21
- class FRBCActuatorDescription(
22
- GenFRBCActuatorDescription, ValidateValuesMixin["FRBCActuatorDescription"]
23
- ):
24
- class Config(GenFRBCActuatorDescription.Config):
25
- validate_assignment = True
26
-
27
- id: uuid.UUID = GenFRBCActuatorDescription.__fields__["id"].field_info # type: ignore[assignment]
28
- operation_modes: List[FRBCOperationMode] = GenFRBCActuatorDescription.__fields__[
21
+ class FRBCActuatorDescription(GenFRBCActuatorDescription, S2Message["FRBCActuatorDescription"]):
22
+ model_config = GenFRBCActuatorDescription.model_config
23
+ model_config["validate_assignment"] = True
24
+
25
+ id: uuid.UUID = GenFRBCActuatorDescription.model_fields["id"] # type: ignore[assignment]
26
+ operation_modes: List[FRBCOperationMode] = GenFRBCActuatorDescription.model_fields[
29
27
  "operation_modes"
30
- ].field_info # type: ignore[assignment]
31
- transitions: List[Transition] = GenFRBCActuatorDescription.__fields__[
32
- "transitions"
33
- ].field_info # type: ignore[assignment]
34
- timers: List[Timer] = GenFRBCActuatorDescription.__fields__["timers"].field_info # type: ignore[assignment]
35
- supported_commodities: List[Commodity] = GenFRBCActuatorDescription.__fields__[
28
+ ] # type: ignore[assignment]
29
+ transitions: List[Transition] = GenFRBCActuatorDescription.model_fields["transitions"] # type: ignore[assignment]
30
+ timers: List[Timer] = GenFRBCActuatorDescription.model_fields["timers"] # type: ignore[assignment]
31
+ supported_commodities: List[Commodity] = GenFRBCActuatorDescription.model_fields[
36
32
  "supported_commodities"
37
- ].field_info # type: ignore[assignment]
33
+ ] # type: ignore[assignment]
38
34
 
39
- @root_validator(pre=False)
40
- def validate_timers_in_transitions(cls, values: Dict[str, Any]) -> Dict[str, Any]:
41
- timers_by_id = {timer.id: timer for timer in values.get("timers", {})}
35
+ @model_validator(mode="after")
36
+ def validate_timers_in_transitions(self) -> Self:
37
+ timers_by_id = {timer.id: timer for timer in self.timers}
42
38
  transition: Transition
43
- for transition in values.get("transitions", []):
39
+ for transition in self.transitions:
44
40
  for start_timer_id in transition.start_timers:
45
41
  if start_timer_id not in timers_by_id:
46
42
  raise ValueError(
47
- cls,
43
+ self,
48
44
  f"{start_timer_id} was referenced as start timer in transition "
49
45
  f"{transition.id} but was not defined in 'timers'.",
50
46
  )
@@ -52,113 +48,96 @@ class FRBCActuatorDescription(
52
48
  for blocking_timer_id in transition.blocking_timers:
53
49
  if blocking_timer_id not in timers_by_id:
54
50
  raise ValueError(
55
- cls,
51
+ self,
56
52
  f"{blocking_timer_id} was referenced as blocking timer in transition "
57
53
  f"{transition.id} but was not defined in 'timers'.",
58
54
  )
59
55
 
60
- return values
56
+ return self
61
57
 
62
- @root_validator(pre=False)
63
- def validate_timers_unique_ids(cls, values: Dict[str, Any]) -> Dict[str, Any]:
58
+ @model_validator(mode="after")
59
+ def validate_timers_unique_ids(self) -> Self:
64
60
  ids = []
65
61
  timer: Timer
66
- for timer in values.get("timers", []):
62
+ for timer in self.timers:
67
63
  if timer.id in ids:
68
- raise ValueError(
69
- cls, f"Id {timer.id} was found multiple times in 'timers'."
70
- )
64
+ raise ValueError(self, f"Id {timer.id} was found multiple times in 'timers'.")
71
65
  ids.append(timer.id)
72
66
 
73
- return values
67
+ return self
74
68
 
75
- @root_validator(pre=False)
76
- def validate_operation_modes_in_transitions(
77
- cls, values: Dict[str, Any]
78
- ) -> Dict[str, Any]:
79
- operation_mode_by_id = {
80
- operation_mode.id: operation_mode
81
- for operation_mode in values.get("operation_modes", [])
82
- }
69
+ @model_validator(mode="after")
70
+ def validate_operation_modes_in_transitions(self) -> Self:
71
+ operation_mode_by_id = {operation_mode.id: operation_mode for operation_mode in self.operation_modes}
83
72
  transition: Transition
84
- for transition in values.get("transitions", []):
73
+ for transition in self.transitions:
85
74
  if transition.from_ not in operation_mode_by_id:
86
75
  raise ValueError(
87
- cls,
76
+ self,
88
77
  f"Operation mode {transition.from_} was referenced as 'from' in transition "
89
78
  f"{transition.id} but was not defined in 'operation_modes'.",
90
79
  )
91
80
 
92
81
  if transition.to not in operation_mode_by_id:
93
82
  raise ValueError(
94
- cls,
83
+ self,
95
84
  f"Operation mode {transition.to} was referenced as 'to' in transition "
96
85
  f"{transition.id} but was not defined in 'operation_modes'.",
97
86
  )
98
87
 
99
- return values
88
+ return self
100
89
 
101
- @root_validator(pre=False)
102
- def validate_operation_modes_unique_ids(
103
- cls, values: Dict[str, Any]
104
- ) -> Dict[str, Any]:
90
+ @model_validator(mode="after")
91
+ def validate_operation_modes_unique_ids(self) -> Self:
105
92
  ids = []
106
93
  operation_mode: FRBCOperationMode
107
- for operation_mode in values.get("operation_modes", []):
94
+ for operation_mode in self.operation_modes:
108
95
  if operation_mode.id in ids:
109
96
  raise ValueError(
110
- cls,
97
+ self,
111
98
  f"Id {operation_mode.id} was found multiple times in 'operation_modes'.",
112
99
  )
113
100
  ids.append(operation_mode.id)
114
101
 
115
- return values
102
+ return self
116
103
 
117
- @root_validator(pre=False)
118
- def validate_operation_mode_elements_have_all_supported_commodities(
119
- cls, values: Dict[str, Any]
120
- ) -> Dict[str, Any]:
121
- supported_commodities = values.get("supported_commodities", [])
104
+ @model_validator(mode="after")
105
+ def validate_operation_mode_elements_have_all_supported_commodities(self) -> Self:
106
+ supported_commodities = self.supported_commodities
122
107
  operation_mode: FRBCOperationMode
123
- for operation_mode in values.get("operation_modes", []):
108
+ for operation_mode in self.operation_modes:
124
109
  for operation_mode_element in operation_mode.elements:
125
110
  for commodity in supported_commodities:
126
111
  power_ranges_for_commodity = [
127
112
  power_range
128
113
  for power_range in operation_mode_element.power_ranges
129
- if commodity_has_quantity(
130
- commodity, power_range.commodity_quantity
131
- )
114
+ if commodity_has_quantity(commodity, power_range.commodity_quantity)
132
115
  ]
133
116
 
134
117
  if len(power_ranges_for_commodity) > 1:
135
118
  raise ValueError(
136
- cls,
119
+ self,
137
120
  f"Multiple power ranges defined for commodity {commodity} in operation "
138
121
  f"mode {operation_mode.id} and element with fill_level_range "
139
122
  f"{operation_mode_element.fill_level_range}",
140
123
  )
141
124
  if not power_ranges_for_commodity:
142
125
  raise ValueError(
143
- cls,
126
+ self,
144
127
  f"No power ranges defined for commodity {commodity} in operation "
145
128
  f"mode {operation_mode.id} and element with fill_level_range "
146
129
  f"{operation_mode_element.fill_level_range}",
147
130
  )
148
- return values
131
+ return self
149
132
 
150
- @root_validator(pre=False)
151
- def validate_unique_supported_commodities(
152
- cls, values: Dict[str, Any]
153
- ) -> Dict[str, Any]:
154
- supported_commodities: list[CommodityQuantity] = values.get(
155
- "supported_commodities", []
156
- )
133
+ @model_validator(mode="after")
134
+ def validate_unique_supported_commodities(self) -> Self:
135
+ supported_commodities: List[Commodity] = self.supported_commodities
157
136
 
158
137
  for supported_commodity in supported_commodities:
159
138
  if supported_commodities.count(supported_commodity) > 1:
160
139
  raise ValueError(
161
- cls,
140
+ self,
162
141
  f"Found duplicate {supported_commodity} commodity in 'supported_commodities'",
163
142
  )
164
- return values
143
+ return self
@@ -4,22 +4,20 @@ import uuid
4
4
  from s2python.generated.gen_s2 import FRBCActuatorStatus as GenFRBCActuatorStatus
5
5
  from s2python.validate_values_mixin import (
6
6
  catch_and_convert_exceptions,
7
- ValidateValuesMixin,
7
+ S2Message,
8
8
  )
9
9
 
10
10
 
11
11
  @catch_and_convert_exceptions
12
- class FRBCActuatorStatus(
13
- GenFRBCActuatorStatus, ValidateValuesMixin["FRBCActuatorStatus"]
14
- ):
15
- class Config(GenFRBCActuatorStatus.Config):
16
- validate_assignment = True
12
+ class FRBCActuatorStatus(GenFRBCActuatorStatus, S2Message["FRBCActuatorStatus"]):
13
+ model_config = GenFRBCActuatorStatus.model_config
14
+ model_config["validate_assignment"] = True
17
15
 
18
- active_operation_mode_id: uuid.UUID = GenFRBCActuatorStatus.__fields__[
16
+ active_operation_mode_id: uuid.UUID = GenFRBCActuatorStatus.model_fields[
19
17
  "active_operation_mode_id"
20
- ].field_info # type: ignore[assignment]
21
- actuator_id: uuid.UUID = GenFRBCActuatorStatus.__fields__["actuator_id"].field_info # type: ignore[assignment]
22
- message_id: uuid.UUID = GenFRBCActuatorStatus.__fields__["message_id"].field_info # type: ignore[assignment]
23
- previous_operation_mode_id: Optional[uuid.UUID] = GenFRBCActuatorStatus.__fields__[
18
+ ] # type: ignore[assignment]
19
+ actuator_id: uuid.UUID = GenFRBCActuatorStatus.model_fields["actuator_id"] # type: ignore[assignment]
20
+ message_id: uuid.UUID = GenFRBCActuatorStatus.model_fields["message_id"] # type: ignore[assignment]
21
+ previous_operation_mode_id: Optional[uuid.UUID] = GenFRBCActuatorStatus.model_fields[
24
22
  "previous_operation_mode_id"
25
- ].field_info # type: ignore[assignment]
23
+ ] # type: ignore[assignment]
@@ -1,28 +1,24 @@
1
1
  from typing import List
2
2
  import uuid
3
3
 
4
- from s2python.frbc import FRBCFillLevelTargetProfileElement
4
+ from s2python.frbc.frbc_fill_level_target_profile_element import (
5
+ FRBCFillLevelTargetProfileElement,
6
+ )
5
7
  from s2python.generated.gen_s2 import (
6
8
  FRBCFillLevelTargetProfile as GenFRBCFillLevelTargetProfile,
7
9
  )
8
10
  from s2python.validate_values_mixin import (
9
11
  catch_and_convert_exceptions,
10
- ValidateValuesMixin,
12
+ S2Message,
11
13
  )
12
14
 
13
15
 
14
16
  @catch_and_convert_exceptions
15
- class FRBCFillLevelTargetProfile(
16
- GenFRBCFillLevelTargetProfile, ValidateValuesMixin["FRBCFillLevelTargetProfile"]
17
- ):
18
- class Config(GenFRBCFillLevelTargetProfile.Config):
19
- validate_assignment = True
17
+ class FRBCFillLevelTargetProfile(GenFRBCFillLevelTargetProfile, S2Message["FRBCFillLevelTargetProfile"]):
18
+ model_config = GenFRBCFillLevelTargetProfile.model_config
19
+ model_config["validate_assignment"] = True
20
20
 
21
- elements: List[
22
- FRBCFillLevelTargetProfileElement
23
- ] = GenFRBCFillLevelTargetProfile.__fields__[
21
+ elements: List[FRBCFillLevelTargetProfileElement] = GenFRBCFillLevelTargetProfile.model_fields[
24
22
  "elements"
25
- ].field_info # type: ignore[assignment]
26
- message_id: uuid.UUID = GenFRBCFillLevelTargetProfile.__fields__[
27
- "message_id"
28
- ].field_info # type: ignore[assignment]
23
+ ] # type: ignore[assignment]
24
+ message_id: uuid.UUID = GenFRBCFillLevelTargetProfile.model_fields["message_id"] # type: ignore[assignment]
@@ -5,21 +5,19 @@ from s2python.generated.gen_s2 import (
5
5
  )
6
6
  from s2python.validate_values_mixin import (
7
7
  catch_and_convert_exceptions,
8
- ValidateValuesMixin,
8
+ S2Message,
9
9
  )
10
10
 
11
11
 
12
12
  @catch_and_convert_exceptions
13
13
  class FRBCFillLevelTargetProfileElement(
14
14
  GenFRBCFillLevelTargetProfileElement,
15
- ValidateValuesMixin["FRBCFillLevelTargetProfileElement"],
15
+ S2Message["FRBCFillLevelTargetProfileElement"],
16
16
  ):
17
- class Config(GenFRBCFillLevelTargetProfileElement.Config):
18
- validate_assignment = True
17
+ model_config = GenFRBCFillLevelTargetProfileElement.model_config
18
+ model_config["validate_assignment"] = True
19
19
 
20
- duration: Duration = GenFRBCFillLevelTargetProfileElement.__fields__[
21
- "duration"
22
- ].field_info # type: ignore[assignment]
23
- fill_level_range: NumberRange = GenFRBCFillLevelTargetProfileElement.__fields__[
20
+ duration: Duration = GenFRBCFillLevelTargetProfileElement.model_fields["duration"] # type: ignore[assignment]
21
+ fill_level_range: NumberRange = GenFRBCFillLevelTargetProfileElement.model_fields[
24
22
  "fill_level_range"
25
- ].field_info # type: ignore[assignment]
23
+ ] # type: ignore[assignment]
@@ -3,16 +3,16 @@ import uuid
3
3
  from s2python.generated.gen_s2 import FRBCInstruction as GenFRBCInstruction
4
4
  from s2python.validate_values_mixin import (
5
5
  catch_and_convert_exceptions,
6
- ValidateValuesMixin,
6
+ S2Message,
7
7
  )
8
8
 
9
9
 
10
10
  @catch_and_convert_exceptions
11
- class FRBCInstruction(GenFRBCInstruction, ValidateValuesMixin["FRBCInstruction"]):
12
- class Config(GenFRBCInstruction.Config):
13
- validate_assignment = True
11
+ class FRBCInstruction(GenFRBCInstruction, S2Message["FRBCInstruction"]):
12
+ model_config = GenFRBCInstruction.model_config
13
+ model_config["validate_assignment"] = True
14
14
 
15
- actuator_id: uuid.UUID = GenFRBCInstruction.__fields__["actuator_id"].field_info # type: ignore[assignment]
16
- id: uuid.UUID = GenFRBCInstruction.__fields__["id"].field_info # type: ignore[assignment]
17
- message_id: uuid.UUID = GenFRBCInstruction.__fields__["message_id"].field_info # type: ignore[assignment]
18
- operation_mode: uuid.UUID = GenFRBCInstruction.__fields__["operation_mode"].field_info # type: ignore[assignment]
15
+ actuator_id: uuid.UUID = GenFRBCInstruction.model_fields["actuator_id"] # type: ignore[assignment]
16
+ id: uuid.UUID = GenFRBCInstruction.model_fields["id"] # type: ignore[assignment]
17
+ message_id: uuid.UUID = GenFRBCInstruction.model_fields["message_id"] # type: ignore[assignment]
18
+ operation_mode: uuid.UUID = GenFRBCInstruction.model_fields["operation_mode"] # type: ignore[assignment]
@@ -1,22 +1,20 @@
1
1
  from typing import List
2
2
  import uuid
3
3
 
4
- from s2python.frbc import FRBCLeakageBehaviourElement
4
+ from s2python.frbc.frbc_leakage_behaviour_element import FRBCLeakageBehaviourElement
5
5
  from s2python.generated.gen_s2 import FRBCLeakageBehaviour as GenFRBCLeakageBehaviour
6
6
  from s2python.validate_values_mixin import (
7
7
  catch_and_convert_exceptions,
8
- ValidateValuesMixin,
8
+ S2Message,
9
9
  )
10
10
 
11
11
 
12
12
  @catch_and_convert_exceptions
13
- class FRBCLeakageBehaviour(
14
- GenFRBCLeakageBehaviour, ValidateValuesMixin["FRBCLeakageBehaviour"]
15
- ):
16
- class Config(GenFRBCLeakageBehaviour.Config):
17
- validate_assignment = True
13
+ class FRBCLeakageBehaviour(GenFRBCLeakageBehaviour, S2Message["FRBCLeakageBehaviour"]):
14
+ model_config = GenFRBCLeakageBehaviour.model_config
15
+ model_config["validate_assignment"] = True
18
16
 
19
- elements: List[FRBCLeakageBehaviourElement] = GenFRBCLeakageBehaviour.__fields__[
17
+ elements: List[FRBCLeakageBehaviourElement] = GenFRBCLeakageBehaviour.model_fields[
20
18
  "elements"
21
- ].field_info # type: ignore[assignment]
22
- message_id: uuid.UUID = GenFRBCLeakageBehaviour.__fields__["message_id"].field_info # type: ignore[assignment]
19
+ ] # type: ignore[assignment]
20
+ message_id: uuid.UUID = GenFRBCLeakageBehaviour.model_fields["message_id"] # type: ignore[assignment]
@@ -4,17 +4,15 @@ from s2python.generated.gen_s2 import (
4
4
  )
5
5
  from s2python.validate_values_mixin import (
6
6
  catch_and_convert_exceptions,
7
- ValidateValuesMixin,
7
+ S2Message,
8
8
  )
9
9
 
10
10
 
11
11
  @catch_and_convert_exceptions
12
- class FRBCLeakageBehaviourElement(
13
- GenFRBCLeakageBehaviourElement, ValidateValuesMixin["FRBCLeakageBehaviourElement"]
14
- ):
15
- class Config(GenFRBCLeakageBehaviourElement.Config):
16
- validate_assignment = True
12
+ class FRBCLeakageBehaviourElement(GenFRBCLeakageBehaviourElement, S2Message["FRBCLeakageBehaviourElement"]):
13
+ model_config = GenFRBCLeakageBehaviourElement.model_config
14
+ model_config["validate_assignment"] = True
17
15
 
18
- fill_level_range: NumberRange = GenFRBCLeakageBehaviourElement.__fields__[
16
+ fill_level_range: NumberRange = GenFRBCLeakageBehaviourElement.model_fields[
19
17
  "fill_level_range"
20
- ].field_info # type: ignore[assignment]
18
+ ] # type: ignore[assignment]
@@ -1,52 +1,42 @@
1
1
  # from itertools import pairwise
2
2
  import uuid
3
- from typing import List, Dict, Any, Generator, Tuple
3
+ from typing import List, Dict
4
+ from typing_extensions import Self
4
5
 
5
- from pydantic import root_validator
6
+ from pydantic import model_validator
6
7
 
7
8
  from s2python.common import NumberRange
8
- from s2python.frbc import FRBCOperationModeElement
9
+ from s2python.frbc.frbc_operation_mode_element import FRBCOperationModeElement
9
10
  from s2python.generated.gen_s2 import FRBCOperationMode as GenFRBCOperationMode
10
11
  from s2python.validate_values_mixin import (
11
- ValidateValuesMixin,
12
+ S2Message,
12
13
  catch_and_convert_exceptions,
13
14
  )
14
15
  from s2python.utils import pairwise
15
16
 
16
17
 
17
18
  @catch_and_convert_exceptions
18
- class FRBCOperationMode(GenFRBCOperationMode, ValidateValuesMixin["FRBCOperationMode"]):
19
- class Config(GenFRBCOperationMode.Config):
20
- validate_assignment = True
21
-
22
- id: uuid.UUID = GenFRBCOperationMode.__fields__["id"].field_info # type: ignore[assignment]
23
- elements: List[FRBCOperationModeElement] = GenFRBCOperationMode.__fields__[
24
- "elements"
25
- ].field_info # type: ignore[assignment]
26
-
27
- @root_validator(pre=False)
28
- def validate_contiguous_fill_levels_operation_mode_elements(
29
- cls, values: Dict[str, Any]
30
- ) -> Dict[str, Any]:
19
+ class FRBCOperationMode(GenFRBCOperationMode, S2Message["FRBCOperationMode"]):
20
+ model_config = GenFRBCOperationMode.model_config
21
+ model_config["validate_assignment"] = True
22
+
23
+ id: uuid.UUID = GenFRBCOperationMode.model_fields["id"] # type: ignore[assignment]
24
+ elements: List[FRBCOperationModeElement] = GenFRBCOperationMode.model_fields["elements"] # type: ignore[assignment]
25
+
26
+ @model_validator(mode="after")
27
+ def validate_contiguous_fill_levels_operation_mode_elements(self) -> Self:
31
28
  elements_by_fill_level_range: Dict[NumberRange, FRBCOperationModeElement]
32
- elements_by_fill_level_range = {
33
- element.fill_level_range: element for element in values.get("elements", [])
34
- }
29
+ elements_by_fill_level_range = {element.fill_level_range: element for element in self.elements}
35
30
 
36
31
  sorted_fill_level_ranges: List[NumberRange]
37
32
  sorted_fill_level_ranges = list(elements_by_fill_level_range.keys())
38
33
  sorted_fill_level_ranges.sort(key=lambda r: r.start_of_range)
39
34
 
40
- for current_fill_level_range, next_fill_level_range in pairwise(
41
- sorted_fill_level_ranges
42
- ):
43
- if (
44
- current_fill_level_range.end_of_range
45
- != next_fill_level_range.start_of_range
46
- ):
35
+ for current_fill_level_range, next_fill_level_range in pairwise(sorted_fill_level_ranges):
36
+ if current_fill_level_range.end_of_range != next_fill_level_range.start_of_range:
47
37
  raise ValueError(
48
- cls,
38
+ self,
49
39
  f"Elements with fill level ranges {current_fill_level_range} and "
50
40
  f"{next_fill_level_range} are closest match to each other but not contiguous.",
51
41
  )
52
- return values
42
+ return self
@@ -5,25 +5,23 @@ from s2python.generated.gen_s2 import (
5
5
  FRBCOperationModeElement as GenFRBCOperationModeElement,
6
6
  )
7
7
  from s2python.validate_values_mixin import (
8
- ValidateValuesMixin,
8
+ S2Message,
9
9
  catch_and_convert_exceptions,
10
10
  )
11
11
 
12
12
 
13
13
  @catch_and_convert_exceptions
14
- class FRBCOperationModeElement(
15
- GenFRBCOperationModeElement, ValidateValuesMixin["FRBCOperationModeElement"]
16
- ):
17
- class Config(GenFRBCOperationModeElement.Config):
18
- validate_assignment = True
14
+ class FRBCOperationModeElement(GenFRBCOperationModeElement, S2Message["FRBCOperationModeElement"]):
15
+ model_config = GenFRBCOperationModeElement.model_config
16
+ model_config["validate_assignment"] = True
19
17
 
20
- fill_level_range: NumberRange = GenFRBCOperationModeElement.__fields__[
18
+ fill_level_range: NumberRange = GenFRBCOperationModeElement.model_fields[
21
19
  "fill_level_range"
22
- ].field_info # type: ignore[assignment]
23
- fill_rate: NumberRange = GenFRBCOperationModeElement.__fields__["fill_rate"].field_info # type: ignore[assignment]
24
- power_ranges: List[PowerRange] = GenFRBCOperationModeElement.__fields__[
20
+ ] # type: ignore[assignment]
21
+ fill_rate: NumberRange = GenFRBCOperationModeElement.model_fields["fill_rate"] # type: ignore[assignment]
22
+ power_ranges: List[PowerRange] = GenFRBCOperationModeElement.model_fields[
25
23
  "power_ranges"
26
- ].field_info # type: ignore[assignment]
27
- running_costs: Optional[NumberRange] = GenFRBCOperationModeElement.__fields__[
24
+ ] # type: ignore[assignment]
25
+ running_costs: Optional[NumberRange] = GenFRBCOperationModeElement.model_fields[
28
26
  "running_costs"
29
- ].field_info # type: ignore[assignment]
27
+ ] # type: ignore[assignment]
@@ -4,17 +4,15 @@ from s2python.generated.gen_s2 import (
4
4
  )
5
5
  from s2python.validate_values_mixin import (
6
6
  catch_and_convert_exceptions,
7
- ValidateValuesMixin,
7
+ S2Message,
8
8
  )
9
9
 
10
10
 
11
11
  @catch_and_convert_exceptions
12
- class FRBCStorageDescription(
13
- GenFRBCStorageDescription, ValidateValuesMixin["FRBCStorageDescription"]
14
- ):
15
- class Config(GenFRBCStorageDescription.Config):
16
- validate_assignment = True
12
+ class FRBCStorageDescription(GenFRBCStorageDescription, S2Message["FRBCStorageDescription"]):
13
+ model_config = GenFRBCStorageDescription.model_config
14
+ model_config["validate_assignment"] = True
17
15
 
18
- fill_level_range: NumberRange = GenFRBCStorageDescription.__fields__[
16
+ fill_level_range: NumberRange = GenFRBCStorageDescription.model_fields[
19
17
  "fill_level_range"
20
- ].field_info # type: ignore[assignment]
18
+ ] # type: ignore[assignment]
@@ -3,13 +3,13 @@ import uuid
3
3
  from s2python.generated.gen_s2 import FRBCStorageStatus as GenFRBCStorageStatus
4
4
  from s2python.validate_values_mixin import (
5
5
  catch_and_convert_exceptions,
6
- ValidateValuesMixin,
6
+ S2Message,
7
7
  )
8
8
 
9
9
 
10
10
  @catch_and_convert_exceptions
11
- class FRBCStorageStatus(GenFRBCStorageStatus, ValidateValuesMixin["FRBCStorageStatus"]):
12
- class Config(GenFRBCStorageStatus.Config):
13
- validate_assignment = True
11
+ class FRBCStorageStatus(GenFRBCStorageStatus, S2Message["FRBCStorageStatus"]):
12
+ model_config = GenFRBCStorageStatus.model_config
13
+ model_config["validate_assignment"] = True
14
14
 
15
- message_id: uuid.UUID = GenFRBCStorageStatus.__fields__["message_id"].field_info # type: ignore[assignment]
15
+ message_id: uuid.UUID = GenFRBCStorageStatus.model_fields["message_id"] # type: ignore[assignment]