Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions development_utilities/generate_s2_message_type_to_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
all_members.sort(key=lambda t: t[0])


print("""
print(
"""
from s2python.common import *
from s2python.frbc import *

TYPE_TO_MESSAGE_CLASS = {""")
TYPE_TO_MESSAGE_CLASS = {"""
)

for name, member in all_members:
if inspect.isclass(member) and hasattr(member, '__fields__') and ('message_type' in member.__fields__):
if (
inspect.isclass(member)
and hasattr(member, "__fields__")
and ("message_type" in member.__fields__)
):
print(f" '{member.__fields__['message_type'].default}': {name},")

print("}")
8 changes: 6 additions & 2 deletions development_utilities/get_all_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
all_members.sort(key=lambda t: t[0])

for name, member in all_members:
if inspect.isclass(member) and issubclass(member, BaseModel) and "message_type" in member.__fields__:
print(f"{name},")
if (
inspect.isclass(member)
and issubclass(member, BaseModel)
and "message_type" in member.__fields__
):
print(f"{name},")
5 changes: 4 additions & 1 deletion src/s2python/common/number_range.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from typing import Any

from s2python.validate_values_mixin import S2MessageComponent, catch_and_convert_exceptions
from s2python.validate_values_mixin import (
S2MessageComponent,
catch_and_convert_exceptions,
)
from s2python.generated.gen_s2 import NumberRange as GenNumberRange


Expand Down
4 changes: 3 additions & 1 deletion src/s2python/common/power_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class PowerRange(GenPowerRange, S2MessageComponent):
@model_validator(mode="after")
def validate_start_end_order(self) -> Self:
if self.start_of_range > self.end_of_range:
raise ValueError(self, "start_of_range should not be higher than end_of_range")
raise ValueError(
self, "start_of_range should not be higher than end_of_range"
)

return self
8 changes: 6 additions & 2 deletions src/s2python/frbc/frbc_actuator_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ def validate_timers_unique_ids(self) -> Self:
timer: Timer
for timer in self.timers:
if timer.id in ids:
raise ValueError(self, f"Id {timer.id} was found multiple times in 'timers'.")
raise ValueError(
self, f"Id {timer.id} was found multiple times in 'timers'."
)
ids.append(timer.id)

return self
Expand Down Expand Up @@ -113,7 +115,9 @@ def validate_operation_mode_elements_have_all_supported_commodities(self) -> Sel
power_ranges_for_commodity = [
power_range
for power_range in operation_mode_element.power_ranges
if commodity_has_quantity(commodity, power_range.commodity_quantity)
if commodity_has_quantity(
commodity, power_range.commodity_quantity
)
]

if len(power_ranges_for_commodity) > 1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
from s2python.generated.gen_s2 import (
FRBCFillLevelTargetProfileElement as GenFRBCFillLevelTargetProfileElement,
)
from s2python.validate_values_mixin import catch_and_convert_exceptions, S2MessageComponent
from s2python.validate_values_mixin import (
catch_and_convert_exceptions,
S2MessageComponent,
)


@catch_and_convert_exceptions
Expand Down
9 changes: 7 additions & 2 deletions src/s2python/frbc/frbc_leakage_behaviour_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
from typing_extensions import Self

from s2python.common import NumberRange
from s2python.generated.gen_s2 import FRBCLeakageBehaviourElement as GenFRBCLeakageBehaviourElement
from s2python.validate_values_mixin import catch_and_convert_exceptions, S2MessageComponent
from s2python.generated.gen_s2 import (
FRBCLeakageBehaviourElement as GenFRBCLeakageBehaviourElement,
)
from s2python.validate_values_mixin import (
catch_and_convert_exceptions,
S2MessageComponent,
)


@catch_and_convert_exceptions
Expand Down
9 changes: 7 additions & 2 deletions src/s2python/frbc/frbc_operation_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ def validate_contiguous_fill_levels_operation_mode_elements(self) -> Self:
sorted_fill_level_ranges = list(elements_by_fill_level_range.keys())
sorted_fill_level_ranges.sort(key=lambda r: r.start_of_range)

for current_fill_level_range, next_fill_level_range in pairwise(sorted_fill_level_ranges):
if current_fill_level_range.end_of_range != next_fill_level_range.start_of_range:
for current_fill_level_range, next_fill_level_range in pairwise(
sorted_fill_level_ranges
):
if (
current_fill_level_range.end_of_range
!= next_fill_level_range.start_of_range
):
raise ValueError(
self,
f"Elements with fill level ranges {current_fill_level_range} and "
Expand Down
13 changes: 12 additions & 1 deletion src/s2python/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
DDBCSystemDescription,
DDBCTimerStatus,
)
from s2python.ombc import (
OMBCInstruction,
OMBCOperationMode,
OMBCTimerStatus,
OMBCStatus,
OMBCSystemDescription,
)

from s2python.pebc import (
PEBCAllowedLimitRange,
Expand Down Expand Up @@ -82,6 +89,10 @@
FRBCSystemDescription,
FRBCTimerStatus,
FRBCUsageForecast,
OMBCSystemDescription,
OMBCStatus,
OMBCTimerStatus,
OMBCInstruction,
PEBCPowerConstraints,
PPBCEndInterruptionInstruction,
PPBCPowerProfileDefinition,
Expand All @@ -93,7 +104,6 @@
SelectControlType,
SessionRequest,
DDBCActuatorStatus,
FRBCInstruction,
PEBCEnergyConstraint,
PEBCInstruction,
Handshake,
Expand All @@ -115,6 +125,7 @@
FRBCOperationModeElement,
FRBCStorageDescription,
FRBCUsageForecastElement,
OMBCOperationMode,
PEBCAllowedLimitRange,
PEBCPowerEnvelope,
PEBCPowerEnvelopeElement,
Expand Down
5 changes: 5 additions & 0 deletions src/s2python/ombc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from s2python.ombc.ombc_instruction import OMBCInstruction
from s2python.ombc.ombc_operation_mode import OMBCOperationMode
from s2python.ombc.ombc_status import OMBCStatus
from s2python.ombc.ombc_system_description import OMBCSystemDescription
from s2python.ombc.ombc_timer_status import OMBCTimerStatus
19 changes: 19 additions & 0 deletions src/s2python/ombc/ombc_instruction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import uuid

from s2python.generated.gen_s2 import OMBCInstruction as GenOMBCInstruction
from s2python.validate_values_mixin import (
catch_and_convert_exceptions,
S2MessageComponent,
)


@catch_and_convert_exceptions
class OMBCInstruction(GenOMBCInstruction, S2MessageComponent):
model_config = GenOMBCInstruction.model_config
model_config["validate_assignment"] = True

id: uuid.UUID = GenOMBCInstruction.model_fields["id"] # type: ignore[assignment]
message_id: uuid.UUID = GenOMBCInstruction.model_fields["message_id"] # type: ignore[assignment]
abnormal_condition: bool = GenOMBCInstruction.model_fields["abnormal_condition"] # type: ignore[assignment]
operation_mode_factor: float = GenOMBCInstruction.model_fields["operation_mode_factor"] # type: ignore[assignment]
operation_mode_id: uuid.UUID = GenOMBCInstruction.model_fields["operation_mode_id"] # type: ignore[assignment]
25 changes: 25 additions & 0 deletions src/s2python/ombc/ombc_operation_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import List
import uuid

from s2python.generated.gen_s2 import OMBCOperationMode as GenOMBCOperationMode
from s2python.common.power_range import PowerRange


from s2python.validate_values_mixin import (
catch_and_convert_exceptions,
S2MessageComponent,
)


@catch_and_convert_exceptions
class OMBCOperationMode(GenOMBCOperationMode, S2MessageComponent):
model_config = GenOMBCOperationMode.model_config
model_config["validate_assignment"] = True

id: uuid.UUID = GenOMBCOperationMode.model_fields["id"] # type: ignore[assignment]
power_ranges: List[PowerRange] = GenOMBCOperationMode.model_fields[
"power_ranges"
] # type: ignore[assignment]
abnormal_condition_only: bool = GenOMBCOperationMode.model_fields[
"abnormal_condition_only"
] # type: ignore[assignment]
17 changes: 17 additions & 0 deletions src/s2python/ombc/ombc_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import uuid

from s2python.generated.gen_s2 import OMBCStatus as GenOMBCStatus

from s2python.validate_values_mixin import (
catch_and_convert_exceptions,
S2MessageComponent,
)


@catch_and_convert_exceptions
class OMBCStatus(GenOMBCStatus, S2MessageComponent):
model_config = GenOMBCStatus.model_config
model_config["validate_assignment"] = True

message_id: uuid.UUID = GenOMBCStatus.model_fields["message_id"] # type: ignore[assignment]
operation_mode_factor: float = GenOMBCStatus.model_fields["operation_mode_factor"] # type: ignore[assignment]
25 changes: 25 additions & 0 deletions src/s2python/ombc/ombc_system_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import List
import uuid

from s2python.generated.gen_s2 import OMBCSystemDescription as GenOMBCSystemDescription
from s2python.ombc.ombc_operation_mode import OMBCOperationMode
from s2python.common.transition import Transition
from s2python.common.timer import Timer

from s2python.validate_values_mixin import (
catch_and_convert_exceptions,
S2MessageComponent,
)


@catch_and_convert_exceptions
class OMBCSystemDescription(GenOMBCSystemDescription, S2MessageComponent):
model_config = GenOMBCSystemDescription.model_config
model_config["validate_assignment"] = True

message_id: uuid.UUID = GenOMBCSystemDescription.model_fields["message_id"] # type: ignore[assignment]
operation_modes: List[OMBCOperationMode] = GenOMBCSystemDescription.model_fields[
"operation_modes"
] # type: ignore[assignment]
transitions: List[Transition] = GenOMBCSystemDescription.model_fields["transitions"] # type: ignore[assignment]
timers: List[Timer] = GenOMBCSystemDescription.model_fields["timers"] # type: ignore[assignment]
17 changes: 17 additions & 0 deletions src/s2python/ombc/ombc_timer_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from uuid import UUID

from s2python.generated.gen_s2 import OMBCTimerStatus as GenOMBCTimerStatus

from s2python.validate_values_mixin import (
catch_and_convert_exceptions,
S2MessageComponent,
)


@catch_and_convert_exceptions
class OMBCTimerStatus(GenOMBCTimerStatus, S2MessageComponent):
model_config = GenOMBCTimerStatus.model_config
model_config["validate_assignment"] = True

message_id: UUID = GenOMBCTimerStatus.model_fields["message_id"] # type: ignore[assignment]
timer_id: UUID = GenOMBCTimerStatus.model_fields["timer_id"] # type: ignore[assignment]
Loading