From f5e401da202cc435a75566ec1d4bbb93ad836cc3 Mon Sep 17 00:00:00 2001 From: Victor Garcia Reolid Date: Thu, 21 Mar 2024 10:46:05 +0100 Subject: [PATCH 01/16] add S2 Message Union type Signed-off-by: Victor Garcia Reolid --- development_utilities/get_all_messages.py | 12 ++++ src/s2python/generated/gen_s2.py | 72 +++++++++++------------ src/s2python/message.py | 47 +++++++++++++++ 3 files changed, 95 insertions(+), 36 deletions(-) create mode 100644 development_utilities/get_all_messages.py create mode 100644 src/s2python/message.py diff --git a/development_utilities/get_all_messages.py b/development_utilities/get_all_messages.py new file mode 100644 index 0000000..4135eaa --- /dev/null +++ b/development_utilities/get_all_messages.py @@ -0,0 +1,12 @@ +import inspect +import s2python.frbc as frbc +import s2python.common as common + +from pydantic import BaseModel + +all_members = inspect.getmembers(frbc) + inspect.getmembers(common) +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},") \ No newline at end of file diff --git a/src/s2python/generated/gen_s2.py b/src/s2python/generated/gen_s2.py index 9c26dfe..397e031 100644 --- a/src/s2python/generated/gen_s2.py +++ b/src/s2python/generated/gen_s2.py @@ -6,7 +6,7 @@ from datetime import datetime from enum import Enum -from typing import List, Optional +from typing import List, Optional, Literal from pydantic import BaseModel, Extra, Field, conint, constr @@ -214,7 +214,7 @@ class Config: ..., description="ID of this instruction (as provided by the CEM) " ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("InstructionStatusUpdate", const=True) + message_type: Literal["InstructionStatusUpdate"] = Field(default="InstructionStatusUpdate") status_type: InstructionStatus = Field( ..., description="Present status of this instruction." ) @@ -251,7 +251,7 @@ class Config: description="ID of the instruction. Must be unique in the scope of the Resource Manager, for at least the duration of the session between Resource Manager and CEM.", ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("OMBC.Instruction", const=True) + message_type: Literal["OMBC.Instruction"] = Field(default="OMBC.Instruction") operation_mode_factor: float = Field( ..., description="The number indicates the factor with which the OMBC.OperationMode should be configured. The factor should be greater than or equal than 0 and less or equal to 1.", @@ -269,7 +269,7 @@ class Config: ..., description="ID of the active OMBC.OperationMode." ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("OMBC.Status", const=True) + message_type: Literal["OMBC.Status"] = Field(default="OMBC.Status") operation_mode_factor: float = Field( ..., description="The number indicates the factor with which the OMBC.OperationMode should be configured. The factor should be greater than or equal than 0 and less or equal to 1.", @@ -293,7 +293,7 @@ class Config: description="Indicates when the Timer will be finished. If the DateTimeStamp is in the future, the timer is not yet finished. If the DateTimeStamp is in the past, the timer is finished. If the timer was never started, the value can be an arbitrary DateTimeStamp in the past.", ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("OMBC.TimerStatus", const=True) + message_type: Literal["OMBC.TimerStatus"] = Field(default="OMBC.TimerStatus") timer_id: ID = Field(..., description="The ID of the timer this message refers to") @@ -314,7 +314,7 @@ class Config: description="Lower average power within the time period given by valid_from and valid_until. If the duration is multiplied with this power value, then the associated lower energy content can be derived. This is the lowest amount of energy the resource will consume during that period of time. ", ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("PEBC.EnergyConstraint", const=True) + message_type: Literal["PEBC.EnergyConstraint"] = Field(default="PEBC.EnergyConstraint") upper_average_power: float = Field( ..., description="Upper average power within the time period given by valid_from and valid_until. If the duration is multiplied with this power value, then the associated upper energy content can be derived. This is the highest amount of energy the resource will consume during that period of time.", @@ -370,7 +370,7 @@ class Config: description="ID of the Instruction. Must be unique in the scope of the Resource Manager, for at least the duration of the session between Resource Manager and CEM.", ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("PPBC.EndInterruptionInstruction", const=True) + message_type: Literal["PPBC.EndInterruptionInstruction"] = Field(default="PPBC.EndInterruptionInstruction") power_profile_id: ID = Field( ..., description="ID of the PPBC.PowerProfileDefinition of which the PPBC.PowerSequence interruption is being ended by the CEM.", @@ -410,7 +410,7 @@ class Config: description="ID of the Instruction. Must be unique in the scope of the Resource Manager, for at least the duration of the session between Resource Manager and CEM.", ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("PPBC.ScheduleInstruction", const=True) + message_type: Literal["PPBC.ScheduleInstruction"] = Field(default="PPBC.ScheduleInstruction") power_profile_id: ID = Field( ..., description="ID of the PPBC.PowerProfileDefinition of which the PPBC.PowerSequence is being selected and scheduled by the CEM.", @@ -441,7 +441,7 @@ class Config: description="ID of the Instruction. Must be unique in the scope of the Resource Manager, for at least the duration of the session between Resource Manager and CEM.", ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("PPBC.StartInterruptionInstruction", const=True) + message_type: Literal["PPBC.StartInterruptionInstruction"] = Field(default="PPBC.StartInterruptionInstruction") power_profile_id: ID = Field( ..., description="ID of the PPBC.PowerProfileDefinition of which the PPBC.PowerSequence is being interrupted by the CEM.", @@ -547,7 +547,7 @@ class Config: extra = Extra.forbid message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("RevokeObject", const=True) + message_type: Literal["RevokeObject"] = Field(default="RevokeObject") object_id: ID = Field(..., description="The ID of object that needs to be revoked") object_type: RevokableObjects = Field( ..., description="The type of object that needs to be revoked" @@ -569,7 +569,7 @@ class Config: description="The ControlType to activate. Must be one of the available ControlTypes as defined in the ResourceManagerDetails", ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("SelectControlType", const=True) + message_type: Literal["SelectControlType"] = Field(default="SelectControlType") class SessionRequestType(Enum): @@ -650,7 +650,7 @@ class Config: ..., description="ID of the actuator this messages refers to" ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("DDBC.ActuatorStatus", const=True) + message_type: Literal["DDBC.ActuatorStatus"] = Field(default="DDBC.ActuatorStatus") operation_mode_factor: float = Field( ..., description="The number indicates the factor with which the DDBC.OperationMode is configured. The factor should be greater than or equal to 0 and less or equal to 1.", @@ -720,7 +720,7 @@ class Config: description="Identifier of this DDBC.Instruction. Must be unique in the scope of the Resource Manager, for at least the duration of the session between Resource Manager and CEM.", ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("DDBC.Instruction", const=True) + message_type: Literal["DDBC.Instruction"] = Field(default="DDBC.Instruction") operation_mode_factor: float = Field( ..., description="The number indicates the factor with which the OMBC.OperationMode should be configured. The factor should be greater than or equal to 0 and less or equal to 1.", @@ -772,7 +772,7 @@ class Config: description="Indicates when the Timer will be finished. If the DateTimeStamp is in the future, the timer is not yet finished. If the DateTimeStamp is in the past, the timer is finished. If the timer was never started, the value can be an arbitrary DateTimeStamp in the past.", ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("DDBC.TimerStatus", const=True) + message_type: Literal["DDBC.TimerStatus"] = Field(default="DDBC.TimerStatus") timer_id: ID = Field(..., description="The ID of the timer this message refers to") @@ -787,7 +787,7 @@ class Config: ..., description="ID of the actuator this messages refers to" ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("FRBC.ActuatorStatus", const=True) + message_type: Literal["FRBC.ActuatorStatus"] = Field(default="FRBC.ActuatorStatus") operation_mode_factor: float = Field( ..., description="The number indicates the factor with which the FRBC.OperationMode is configured. The factor should be greater than or equal than 0 and less or equal to 1.", @@ -832,7 +832,7 @@ class Config: description="ID of the instruction. Must be unique in the scope of the Resource Manager, for at least the duration of the session between Resource Manager and CEM.", ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("FRBC.Instruction", const=True) + message_type: Literal["FRBC.Instruction"] = Field(default="FRBC.Instruction") operation_mode: ID = Field( ..., description="ID of the FRBC.OperationMode that should be activated." ) @@ -915,7 +915,7 @@ class Config: extra = Extra.forbid message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("FRBC.StorageStatus", const=True) + message_type: Literal["FRBC.StorageStatus"] = Field(default="FRBC.StorageStatus") present_fill_level: float = Field( ..., description="Present fill level of the Storage" ) @@ -933,7 +933,7 @@ class Config: description="Indicates when the Timer will be finished. If the DateTimeStamp is in the future, the timer is not yet finished. If the DateTimeStamp is in the past, the timer is finished. If the timer was never started, the value can be an arbitrary DateTimeStamp in the past.", ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("FRBC.TimerStatus", const=True) + message_type: Literal["FRBC.TimerStatus"] = Field(default="FRBC.TimerStatus") timer_id: ID = Field(..., description="The ID of the timer this message refers to") @@ -948,7 +948,7 @@ class Config: min_items=1, ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("FRBC.UsageForecast", const=True) + message_type: Literal["FRBC.UsageForecast"] = Field(default="FRBC.UsageForecast") start_time: datetime = Field( ..., description="Time at which the FRBC.UsageForecast starts." ) @@ -959,7 +959,7 @@ class Config: extra = Extra.forbid message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("Handshake", const=True) + message_type: Literal["Handshake"] = Field(default="Handshake") role: EnergyManagementRole = Field( ..., description="The role of the sender of this message" ) @@ -975,7 +975,7 @@ class Config: extra = Extra.forbid message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("HandshakeResponse", const=True) + message_type: Literal["HandshakeResponse"] = Field(default="HandshakeResponse") selected_protocol_version: str = Field( ..., description="The protocol version the CEM selected for this session" ) @@ -1014,7 +1014,7 @@ class Config: extra = Extra.forbid message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("OMBC.SystemDescription", const=True) + message_type: Literal["OMBC.SystemDescription"] = Field(default="OMBC.SystemDescription") operation_modes: List[OMBCOperationMode] = Field( ..., description="OMBC.OperationModes available for the CEM in order to coordinate the device behaviour.", @@ -1078,7 +1078,7 @@ class Config: description="Identifier of this PEBC.PowerConstraints. Must be unique in the scope of the Resource Manager, for at least the duration of the session between Resource Manager and CEM.", ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("PEBC.PowerConstraints", const=True) + message_type: Literal["PEBC.PowerConstraints"] = Field(default="PEBC.PowerConstraints") valid_from: datetime = Field( ..., description="Moment this PEBC.PowerConstraints start to be valid" ) @@ -1168,7 +1168,7 @@ class Config: ..., description="Timestamp when PowerValues were measured." ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("PowerMeasurement", const=True) + message_type: Literal["PowerMeasurement"] = Field(default="PowerMeasurement") values: List[PowerValue] = Field( ..., description="Array of measured PowerValues. Must contain at least one item and at most one item per ‘commodity_quantity’ (defined inside the PowerValue).", @@ -1185,7 +1185,7 @@ class Config: None, description="Diagnostic label that can be used to provide additional information for debugging. However, not for HMI purposes.", ) - message_type: str = Field("ReceptionStatus", const=True) + message_type: Literal["ReceptionStatus"] = Field(default="ReceptionStatus") status: ReceptionStatusValues = Field( ..., description="Enumeration of status values" ) @@ -1213,7 +1213,7 @@ class Config: description="Optional field for a human readible descirption for debugging purposes", ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("SessionRequest", const=True) + message_type: Literal["SessionRequest"] = Field(default="SessionRequest") request: SessionRequestType = Field(..., description="The type of request") @@ -1266,7 +1266,7 @@ class Config: min_items=1, ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("DDBC.AverageDemandRateForecast", const=True) + message_type: Literal["DDBC.AverageDemandRateForecast"] = Field(default="DDBC.AverageDemandRateForecast") start_time: datetime = Field(..., description="Start time of the profile.") @@ -1281,7 +1281,7 @@ class Config: min_items=1, ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("DDBC.SystemDescription", const=True) + message_type: Literal["DDBC.SystemDescription"] = Field(default="DDBC.SystemDescription") present_demand_rate: NumberRange = Field( ..., description="Present demand rate that needs to be satisfied by the system" ) @@ -1306,7 +1306,7 @@ class Config: min_items=1, ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("FRBC.FillLevelTargetProfile", const=True) + message_type: Literal["FRBC.FillLevelTargetProfile"] = Field(default="FRBC.FillLevelTargetProfile") start_time: datetime = Field( ..., description="Time at which the FRBC.FillLevelTargetProfile starts." ) @@ -1323,7 +1323,7 @@ class Config: min_items=1, ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("FRBC.LeakageBehaviour", const=True) + message_type: Literal["FRBC.LeakageBehaviour"] = Field(default="FRBC.LeakageBehaviour") valid_from: datetime = Field( ..., description="Moment this FRBC.LeakageBehaviour starts to be valid. If the FRBC.LeakageBehaviour is immediately valid, the DateTimeStamp should be now or in the past.", @@ -1371,7 +1371,7 @@ class Config: description="Identifier of this PEBC.Instruction. Must be unique in the scope of the Resource Manager, for at least the duration of the session between Resource Manager and CEM.", ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("PEBC.Instruction", const=True) + message_type: Literal["PEBC.Instruction"] = Field(default="PEBC.Instruction") power_constraints_id: ID = Field( ..., description="Identifier of the PEBC.PowerConstraints this PEBC.Instruction was based on.", @@ -1389,7 +1389,7 @@ class Config: extra = Extra.forbid message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("PPBC.PowerProfileStatus", const=True) + message_type: Literal["PPBC.PowerProfileStatus"] = Field(default="PPBC.PowerProfileStatus") sequence_container_status: List[PPBCPowerSequenceContainerStatus] = Field( ..., description="Array with status information for all PPBC.PowerSequenceContainers in the PPBC.PowerProfileDefinition.", @@ -1453,7 +1453,7 @@ class Config: min_items=1, ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("PowerForecast", const=True) + message_type: Literal["PowerForecast"] = Field(default="PowerForecast") start_time: datetime = Field( ..., description="Start time of time period that is covered by the profile." ) @@ -1483,7 +1483,7 @@ class Config: ) manufacturer: Optional[str] = Field(None, description="Name of Manufacturer") message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("ResourceManagerDetails", const=True) + message_type: Literal["ResourceManagerDetails"] = Field(default="ResourceManagerDetails") model: Optional[str] = Field( None, description="Name of the model of the device (provided by the manufacturer)", @@ -1557,7 +1557,7 @@ class Config: ..., description="Details of all Actuators.", max_items=10, min_items=1 ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("FRBC.SystemDescription", const=True) + message_type: Literal["FRBC.SystemDescription"] = Field(default="FRBC.SystemDescription") storage: FRBCStorageDescription = Field(..., description="Details of the storage.") valid_from: datetime = Field( ..., @@ -1578,7 +1578,7 @@ class Config: description="ID of the PPBC.PowerProfileDefinition. Must be unique in the scope of the Resource Manager, for at least the duration of the session between Resource Manager and CEM.", ) message_id: ID = Field(..., description="ID of this message") - message_type: str = Field("PPBC.PowerProfileDefinition", const=True) + message_type: Literal["PPBC.PowerProfileDefinition"] = Field(default="PPBC.PowerProfileDefinition") power_sequences_containers: List[PPBCPowerSequenceContainer] = Field( ..., description="The PPBC.PowerSequenceContainers that make up this PPBC.PowerProfileDefinition. There shall be at least one PPBC.PowerSequenceContainer that includes at least one PPBC.PowerSequence. PPBC.PowerSequenceContainers must be placed in chronological order.", diff --git a/src/s2python/message.py b/src/s2python/message.py new file mode 100644 index 0000000..cf73bbd --- /dev/null +++ b/src/s2python/message.py @@ -0,0 +1,47 @@ +from typing import Union +from pydantic import BaseModel + +from s2python.frbc import ( + FRBCActuatorStatus, + FRBCFillLevelTargetProfile, + FRBCInstruction, + FRBCLeakageBehaviour, + FRBCStorageStatus, + FRBCSystemDescription, + FRBCTimerStatus, + FRBCUsageForecast +) + +from s2python.common import ( + Handshake, + HandshakeResponse, + InstructionStatusUpdate, + PowerForecast, + PowerMeasurement, + ReceptionStatus, + ResourceManagerDetails, + RevokeObject, + SelectControlType, + SessionRequest +) + +S2Message = Union[ + FRBCActuatorStatus, + FRBCFillLevelTargetProfile, + FRBCInstruction, + FRBCLeakageBehaviour, + FRBCStorageStatus, + FRBCSystemDescription, + FRBCTimerStatus, + FRBCUsageForecast, + Handshake, + HandshakeResponse, + InstructionStatusUpdate, + PowerForecast, + PowerMeasurement, + ReceptionStatus, + ResourceManagerDetails, + RevokeObject, + SelectControlType, + SessionRequest, +] \ No newline at end of file From c2fede217cd4207f39378fac814bdaab0e5ffd38 Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Mon, 2 Dec 2024 15:58:07 +0100 Subject: [PATCH 02/16] chore: move to Literals as Pydantic 2 does --- src/s2python/common/handshake.py | 3 +++ src/s2python/common/handshake_response.py | 3 +++ src/s2python/common/instruction_status_update.py | 3 +++ src/s2python/common/number_range.py | 5 ++++- src/s2python/common/power_forecast.py | 4 +++- src/s2python/common/power_forecast_element.py | 4 +++- src/s2python/common/power_forecast_value.py | 4 ++++ src/s2python/common/power_measurement.py | 4 +++- src/s2python/common/power_range.py | 5 ++++- src/s2python/common/power_value.py | 5 +++++ src/s2python/common/reception_status.py | 3 +++ src/s2python/common/resource_manager_details.py | 4 +++- src/s2python/common/revoke_object.py | 3 +++ src/s2python/common/role.py | 5 +++++ src/s2python/common/select_control_type.py | 3 +++ src/s2python/common/session_request.py | 3 +++ src/s2python/common/timer.py | 3 +++ src/s2python/common/transition.py | 4 +++- src/s2python/frbc/frbc_actuator_description.py | 5 +++-- src/s2python/frbc/frbc_actuator_status.py | 4 +++- src/s2python/frbc/frbc_fill_level_target_profile.py | 4 +++- src/s2python/frbc/frbc_fill_level_target_profile_element.py | 4 ++++ src/s2python/frbc/frbc_instruction.py | 3 +++ src/s2python/frbc/frbc_leakage_behaviour.py | 4 +++- src/s2python/frbc/frbc_leakage_behaviour_element.py | 4 ++++ src/s2python/frbc/frbc_operation_mode.py | 4 +++- src/s2python/frbc/frbc_operation_mode_element.py | 4 +++- src/s2python/frbc/frbc_storage_description.py | 4 ++++ src/s2python/frbc/frbc_storage_status.py | 3 +++ src/s2python/frbc/frbc_system_description.py | 4 +++- src/s2python/frbc/frbc_timer_status.py | 3 +++ src/s2python/frbc/frbc_usage_forecast.py | 4 +++- src/s2python/frbc/frbc_usage_forecast_element.py | 4 ++++ 33 files changed, 110 insertions(+), 16 deletions(-) diff --git a/src/s2python/common/handshake.py b/src/s2python/common/handshake.py index 7c8f5a0..dabefa4 100644 --- a/src/s2python/common/handshake.py +++ b/src/s2python/common/handshake.py @@ -1,3 +1,5 @@ +from pydantic import Field +from typing import Literal import uuid from s2python.generated.gen_s2 import Handshake as GenHandshake @@ -13,3 +15,4 @@ class Config(GenHandshake.Config): validate_assignment = True message_id: uuid.UUID = GenHandshake.__fields__["message_id"].field_info # type: ignore[assignment] + message_type: Literal["Handshake"] = Field(default="Handshake") diff --git a/src/s2python/common/handshake_response.py b/src/s2python/common/handshake_response.py index 31340ff..846be2b 100644 --- a/src/s2python/common/handshake_response.py +++ b/src/s2python/common/handshake_response.py @@ -1,3 +1,5 @@ +from pydantic import Field +from typing import Literal import uuid from s2python.generated.gen_s2 import HandshakeResponse as GenHandshakeResponse @@ -13,3 +15,4 @@ class Config(GenHandshakeResponse.Config): validate_assignment = True message_id: uuid.UUID = GenHandshakeResponse.__fields__["message_id"].field_info # type: ignore[assignment] + message_type: Literal["HandshakeResponse"] = Field(default="HandshakeResponse") diff --git a/src/s2python/common/instruction_status_update.py b/src/s2python/common/instruction_status_update.py index bd39531..f45f81d 100644 --- a/src/s2python/common/instruction_status_update.py +++ b/src/s2python/common/instruction_status_update.py @@ -1,3 +1,5 @@ +from pydantic import Field +from typing import Literal import uuid from s2python.generated.gen_s2 import ( @@ -20,3 +22,4 @@ class Config(GenInstructionStatusUpdate.Config): instruction_id: uuid.UUID = GenInstructionStatusUpdate.__fields__[ "instruction_id" ].field_info # type: ignore[assignment] + message_type: Literal["InstructionStatusUpdate"] = Field(default="InstructionStatusUpdate") diff --git a/src/s2python/common/number_range.py b/src/s2python/common/number_range.py index 9af00ec..03e8ef9 100644 --- a/src/s2python/common/number_range.py +++ b/src/s2python/common/number_range.py @@ -1,4 +1,5 @@ -from typing import Any, Dict +from pydantic import Field +from typing import Any, Dict, Literal from pydantic import root_validator @@ -37,3 +38,5 @@ def __eq__(self, other: Any) -> bool: ) return False + + message_type: Literal["NumberRange"] = Field(default="NumberRange") \ No newline at end of file diff --git a/src/s2python/common/power_forecast.py b/src/s2python/common/power_forecast.py index c31d7ed..36a47e2 100644 --- a/src/s2python/common/power_forecast.py +++ b/src/s2python/common/power_forecast.py @@ -1,4 +1,5 @@ -from typing import List +from pydantic import Field +from typing import List, Literal import uuid from s2python.common.power_forecast_element import PowerForecastElement @@ -18,3 +19,4 @@ class Config(GenPowerForecast.Config): elements: List[PowerForecastElement] = GenPowerForecast.__fields__[ "elements" ].field_info # type: ignore[assignment] + message_type: Literal["PowerForecast"] = Field(default="PowerForecast") diff --git a/src/s2python/common/power_forecast_element.py b/src/s2python/common/power_forecast_element.py index 3749e0e..82ea0a3 100644 --- a/src/s2python/common/power_forecast_element.py +++ b/src/s2python/common/power_forecast_element.py @@ -1,4 +1,5 @@ -from typing import List +from pydantic import Field +from typing import List, Literal from s2python.generated.gen_s2 import PowerForecastElement as GenPowerForecastElement from s2python.validate_values_mixin import ( @@ -18,3 +19,4 @@ class Config(GenPowerForecastElement.Config): power_values: List[PowerForecastValue] = GenPowerForecastElement.__fields__[ "power_values" ].field_info # type: ignore[assignment] + message_type: Literal["NumberRange"] = Field(default="NumberRange") diff --git a/src/s2python/common/power_forecast_value.py b/src/s2python/common/power_forecast_value.py index 8b7b9c8..71d4d7b 100644 --- a/src/s2python/common/power_forecast_value.py +++ b/src/s2python/common/power_forecast_value.py @@ -1,3 +1,6 @@ +from pydantic import Field +from typing import Literal + from s2python.generated.gen_s2 import PowerForecastValue as GenPowerForecastValue from s2python.validate_values_mixin import ( catch_and_convert_exceptions, @@ -9,3 +12,4 @@ class PowerForecastValue(GenPowerForecastValue, S2Message["PowerForecastValue"]): class Config(GenPowerForecastValue.Config): validate_assignment = True + message_type: Literal["PowerMeasurement"] = Field(default="PowerMeasurement") diff --git a/src/s2python/common/power_measurement.py b/src/s2python/common/power_measurement.py index 013e85d..1828f55 100644 --- a/src/s2python/common/power_measurement.py +++ b/src/s2python/common/power_measurement.py @@ -1,4 +1,5 @@ -from typing import List +from pydantic import Field +from typing import List, Literal import uuid from s2python.common.power_value import PowerValue @@ -16,3 +17,4 @@ class Config(GenPowerMeasurement.Config): message_id: uuid.UUID = GenPowerMeasurement.__fields__["message_id"].field_info # type: ignore[assignment] values: List[PowerValue] = GenPowerMeasurement.__fields__["values"].field_info # type: ignore[assignment] + message_type: Literal["PowerMeasurement"] = Field(default="PowerMeasurement") diff --git a/src/s2python/common/power_range.py b/src/s2python/common/power_range.py index 5b3b4ed..cf1e539 100644 --- a/src/s2python/common/power_range.py +++ b/src/s2python/common/power_range.py @@ -1,4 +1,5 @@ -from typing import Any, Dict +from pydantic import Field +from typing import Any, Dict, Literal from pydantic import root_validator @@ -25,3 +26,5 @@ def validate_start_end_order( ) return values + + message_type: Literal["PowerRange"] = Field(default="PowerRange") diff --git a/src/s2python/common/power_value.py b/src/s2python/common/power_value.py index c00583e..90ee3b1 100644 --- a/src/s2python/common/power_value.py +++ b/src/s2python/common/power_value.py @@ -1,3 +1,6 @@ +from pydantic import Field +from typing import Literal + from s2python.generated.gen_s2 import PowerValue as GenPowerValue from s2python.validate_values_mixin import ( catch_and_convert_exceptions, @@ -9,3 +12,5 @@ class PowerValue(GenPowerValue, S2Message["PowerValue"]): class Config(GenPowerValue.Config): validate_assignment = True + + message_type: Literal["PowerValue"] = Field(default="PowerValue") diff --git a/src/s2python/common/reception_status.py b/src/s2python/common/reception_status.py index 69760d7..5d78301 100644 --- a/src/s2python/common/reception_status.py +++ b/src/s2python/common/reception_status.py @@ -1,3 +1,5 @@ +from pydantic import Field +from typing import Literal import uuid from s2python.generated.gen_s2 import ReceptionStatus as GenReceptionStatus @@ -15,3 +17,4 @@ class Config(GenReceptionStatus.Config): subject_message_id: uuid.UUID = GenReceptionStatus.__fields__[ "subject_message_id" ].field_info # type: ignore[assignment] + message_type: Literal["ReceptionStatus"] = Field(default="ReceptionStatus") diff --git a/src/s2python/common/resource_manager_details.py b/src/s2python/common/resource_manager_details.py index d261e2d..26ae73b 100644 --- a/src/s2python/common/resource_manager_details.py +++ b/src/s2python/common/resource_manager_details.py @@ -1,4 +1,5 @@ -from typing import List +from pydantic import Field +from typing import List, Literal import uuid from s2python.common.duration import Duration @@ -25,3 +26,4 @@ class Config(GenResourceManagerDetails.Config): message_id: uuid.UUID = GenResourceManagerDetails.__fields__["message_id"].field_info # type: ignore[assignment] resource_id: uuid.UUID = GenResourceManagerDetails.__fields__["resource_id"].field_info # type: ignore[assignment] roles: List[Role] = GenResourceManagerDetails.__fields__["roles"].field_info # type: ignore[assignment] + message_type: Literal["ResourceManagerDetails"] = Field(default="ResourceManagerDetails") diff --git a/src/s2python/common/revoke_object.py b/src/s2python/common/revoke_object.py index 4d1a579..734a08d 100644 --- a/src/s2python/common/revoke_object.py +++ b/src/s2python/common/revoke_object.py @@ -1,3 +1,5 @@ +from pydantic import Field +from typing import Literal import uuid from s2python.generated.gen_s2 import RevokeObject as GenRevokeObject @@ -14,3 +16,4 @@ class Config(GenRevokeObject.Config): message_id: uuid.UUID = GenRevokeObject.__fields__["message_id"].field_info # type: ignore[assignment] object_id: uuid.UUID = GenRevokeObject.__fields__["object_id"].field_info # type: ignore[assignment] + message_type: Literal["RevokeObject"] = Field(default="RevokeObject") diff --git a/src/s2python/common/role.py b/src/s2python/common/role.py index bac2732..e0b91f5 100644 --- a/src/s2python/common/role.py +++ b/src/s2python/common/role.py @@ -1,3 +1,6 @@ +from pydantic import Field +from typing import Literal + from s2python.generated.gen_s2 import Role as GenRole from s2python.validate_values_mixin import ( S2Message, @@ -9,3 +12,5 @@ class Role(GenRole, S2Message["Role"]): class Config(GenRole.Config): validate_assignment = True + + message_type: Literal["Role"] = Field(default="Role") diff --git a/src/s2python/common/select_control_type.py b/src/s2python/common/select_control_type.py index 6096f99..05b7e28 100644 --- a/src/s2python/common/select_control_type.py +++ b/src/s2python/common/select_control_type.py @@ -1,3 +1,5 @@ +from pydantic import Field +from typing import Literal import uuid from s2python.generated.gen_s2 import SelectControlType as GenSelectControlType @@ -13,3 +15,4 @@ class Config(GenSelectControlType.Config): validate_assignment = True message_id: uuid.UUID = GenSelectControlType.__fields__["message_id"].field_info # type: ignore[assignment] + message_type: Literal["SelectControlType"] = Field(default="SelectControlType") diff --git a/src/s2python/common/session_request.py b/src/s2python/common/session_request.py index 5606569..45a62b5 100644 --- a/src/s2python/common/session_request.py +++ b/src/s2python/common/session_request.py @@ -1,3 +1,5 @@ +from pydantic import Field +from typing import Literal import uuid from s2python.generated.gen_s2 import SessionRequest as GenSessionRequest @@ -13,3 +15,4 @@ class Config(GenSessionRequest.Config): validate_assignment = True message_id: uuid.UUID = GenSessionRequest.__fields__["message_id"].field_info # type: ignore[assignment] + message_type: Literal["SessionRequest"] = Field(default="SessionRequest") diff --git a/src/s2python/common/timer.py b/src/s2python/common/timer.py index 94f1bae..e233089 100644 --- a/src/s2python/common/timer.py +++ b/src/s2python/common/timer.py @@ -1,3 +1,5 @@ +from pydantic import Field +from typing import Literal import uuid from s2python.common.duration import Duration @@ -15,3 +17,4 @@ class Config(GenTimer.Config): id: uuid.UUID = GenTimer.__fields__["id"].field_info # type: ignore[assignment] duration: Duration = GenTimer.__fields__["duration"].field_info # type: ignore[assignment] + message_type: Literal["Timer"] = Field(default="Timer") diff --git a/src/s2python/common/transition.py b/src/s2python/common/transition.py index af657b6..4e80a39 100644 --- a/src/s2python/common/transition.py +++ b/src/s2python/common/transition.py @@ -1,5 +1,6 @@ +from pydantic import Field import uuid -from typing import Optional, List +from typing import Optional, List, Literal from s2python.common.duration import Duration from s2python.generated.gen_s2 import Transition as GenTransition @@ -24,3 +25,4 @@ class Config(GenTransition.Config): transition_duration: Optional[Duration] = GenTransition.__fields__[ "transition_duration" ].field_info # type: ignore[assignment] + message_type: Literal["Transition"] = Field(default="Transition") diff --git a/src/s2python/frbc/frbc_actuator_description.py b/src/s2python/frbc/frbc_actuator_description.py index f45083e..22471c4 100644 --- a/src/s2python/frbc/frbc_actuator_description.py +++ b/src/s2python/frbc/frbc_actuator_description.py @@ -1,6 +1,6 @@ import uuid - -from typing import List, Any, Dict +from pydantic import Field +from typing import List, Any, Dict, Literal from pydantic import root_validator @@ -35,6 +35,7 @@ class Config(GenFRBCActuatorDescription.Config): supported_commodities: List[Commodity] = GenFRBCActuatorDescription.__fields__[ "supported_commodities" ].field_info # type: ignore[assignment] + message_type: Literal["FRBCActuatorDescription"] = Field(default="FRBCActuatorDescription") @root_validator(pre=False) @classmethod diff --git a/src/s2python/frbc/frbc_actuator_status.py b/src/s2python/frbc/frbc_actuator_status.py index db3cb58..40e06c5 100644 --- a/src/s2python/frbc/frbc_actuator_status.py +++ b/src/s2python/frbc/frbc_actuator_status.py @@ -1,4 +1,5 @@ -from typing import Optional +from pydantic import Field +from typing import Literal, Optional import uuid from s2python.generated.gen_s2 import FRBCActuatorStatus as GenFRBCActuatorStatus @@ -21,3 +22,4 @@ class Config(GenFRBCActuatorStatus.Config): previous_operation_mode_id: Optional[uuid.UUID] = GenFRBCActuatorStatus.__fields__[ "previous_operation_mode_id" ].field_info # type: ignore[assignment] + message_type: Literal["FRBCActuatorStatus"] = Field(default="FRBCActuatorStatus") diff --git a/src/s2python/frbc/frbc_fill_level_target_profile.py b/src/s2python/frbc/frbc_fill_level_target_profile.py index 20fdc4a..d4e1fcc 100644 --- a/src/s2python/frbc/frbc_fill_level_target_profile.py +++ b/src/s2python/frbc/frbc_fill_level_target_profile.py @@ -1,4 +1,5 @@ -from typing import List +from pydantic import Field +from typing import List, Literal import uuid from s2python.frbc.frbc_fill_level_target_profile_element import ( @@ -28,3 +29,4 @@ class Config(GenFRBCFillLevelTargetProfile.Config): message_id: uuid.UUID = GenFRBCFillLevelTargetProfile.__fields__[ "message_id" ].field_info # type: ignore[assignment] + message_type: Literal["FRBCFillLevelTargetProfile"] = Field(default="FRBCFillLevelTargetProfile") diff --git a/src/s2python/frbc/frbc_fill_level_target_profile_element.py b/src/s2python/frbc/frbc_fill_level_target_profile_element.py index c6d2e22..33e4d98 100644 --- a/src/s2python/frbc/frbc_fill_level_target_profile_element.py +++ b/src/s2python/frbc/frbc_fill_level_target_profile_element.py @@ -1,3 +1,6 @@ +from pydantic import Field +from typing import Literal + from s2python.common import Duration, NumberRange from s2python.generated.gen_s2 import ( @@ -23,3 +26,4 @@ class Config(GenFRBCFillLevelTargetProfileElement.Config): fill_level_range: NumberRange = GenFRBCFillLevelTargetProfileElement.__fields__[ "fill_level_range" ].field_info # type: ignore[assignment] + message_type: Literal["FRBCFillLevelTargetProfileElement"] = Field(default="FRBCFillLevelTargetProfileElement") diff --git a/src/s2python/frbc/frbc_instruction.py b/src/s2python/frbc/frbc_instruction.py index 6bd173d..a89fd54 100644 --- a/src/s2python/frbc/frbc_instruction.py +++ b/src/s2python/frbc/frbc_instruction.py @@ -1,3 +1,5 @@ +from pydantic import Field +from typing import Literal import uuid from s2python.generated.gen_s2 import FRBCInstruction as GenFRBCInstruction @@ -16,3 +18,4 @@ class Config(GenFRBCInstruction.Config): id: uuid.UUID = GenFRBCInstruction.__fields__["id"].field_info # type: ignore[assignment] message_id: uuid.UUID = GenFRBCInstruction.__fields__["message_id"].field_info # type: ignore[assignment] operation_mode: uuid.UUID = GenFRBCInstruction.__fields__["operation_mode"].field_info # type: ignore[assignment] + message_type: Literal["FRBCInstruction"] = Field(default="FRBCInstruction") diff --git a/src/s2python/frbc/frbc_leakage_behaviour.py b/src/s2python/frbc/frbc_leakage_behaviour.py index 5543b6d..61f4017 100644 --- a/src/s2python/frbc/frbc_leakage_behaviour.py +++ b/src/s2python/frbc/frbc_leakage_behaviour.py @@ -1,4 +1,5 @@ -from typing import List +from pydantic import Field +from typing import List, Literal import uuid from s2python.frbc.frbc_leakage_behaviour_element import FRBCLeakageBehaviourElement @@ -18,3 +19,4 @@ class Config(GenFRBCLeakageBehaviour.Config): "elements" ].field_info # type: ignore[assignment] message_id: uuid.UUID = GenFRBCLeakageBehaviour.__fields__["message_id"].field_info # type: ignore[assignment] + message_type: Literal["FRBCLeakageBehaviour"] = Field(default="FRBCLeakageBehaviour") diff --git a/src/s2python/frbc/frbc_leakage_behaviour_element.py b/src/s2python/frbc/frbc_leakage_behaviour_element.py index 4866045..633b9b9 100644 --- a/src/s2python/frbc/frbc_leakage_behaviour_element.py +++ b/src/s2python/frbc/frbc_leakage_behaviour_element.py @@ -1,3 +1,6 @@ +from pydantic import Field +from typing import Literal + from s2python.common import NumberRange from s2python.generated.gen_s2 import ( FRBCLeakageBehaviourElement as GenFRBCLeakageBehaviourElement, @@ -18,3 +21,4 @@ class Config(GenFRBCLeakageBehaviourElement.Config): fill_level_range: NumberRange = GenFRBCLeakageBehaviourElement.__fields__[ "fill_level_range" ].field_info # type: ignore[assignment] + message_type: Literal["FRBCLeakageBehaviourElement"] = Field(default="FRBCLeakageBehaviourElement") diff --git a/src/s2python/frbc/frbc_operation_mode.py b/src/s2python/frbc/frbc_operation_mode.py index 5713763..49bf894 100644 --- a/src/s2python/frbc/frbc_operation_mode.py +++ b/src/s2python/frbc/frbc_operation_mode.py @@ -1,6 +1,7 @@ # from itertools import pairwise import uuid -from typing import List, Dict, Any +from pydantic import Field +from typing import List, Dict, Any, Literal from pydantic import root_validator @@ -23,6 +24,7 @@ class Config(GenFRBCOperationMode.Config): elements: List[FRBCOperationModeElement] = GenFRBCOperationMode.__fields__[ "elements" ].field_info # type: ignore[assignment] + message_type: Literal["FRBCOperationMode"] = Field(default="FRBCOperationMode") @root_validator(pre=False) @classmethod diff --git a/src/s2python/frbc/frbc_operation_mode_element.py b/src/s2python/frbc/frbc_operation_mode_element.py index f4d657e..ffa4bd6 100644 --- a/src/s2python/frbc/frbc_operation_mode_element.py +++ b/src/s2python/frbc/frbc_operation_mode_element.py @@ -1,4 +1,5 @@ -from typing import Optional, List +from pydantic import Field +from typing import Optional, List, Literal from s2python.common import NumberRange, PowerRange from s2python.generated.gen_s2 import ( @@ -27,3 +28,4 @@ class Config(GenFRBCOperationModeElement.Config): running_costs: Optional[NumberRange] = GenFRBCOperationModeElement.__fields__[ "running_costs" ].field_info # type: ignore[assignment] + message_type: Literal["FRBCOperationModeElement"] = Field(default="FRBCOperationModeElement") diff --git a/src/s2python/frbc/frbc_storage_description.py b/src/s2python/frbc/frbc_storage_description.py index 77f413b..c5de7f3 100644 --- a/src/s2python/frbc/frbc_storage_description.py +++ b/src/s2python/frbc/frbc_storage_description.py @@ -1,3 +1,6 @@ +from pydantic import Field +from typing import Literal + from s2python.common import NumberRange from s2python.generated.gen_s2 import ( FRBCStorageDescription as GenFRBCStorageDescription, @@ -18,3 +21,4 @@ class Config(GenFRBCStorageDescription.Config): fill_level_range: NumberRange = GenFRBCStorageDescription.__fields__[ "fill_level_range" ].field_info # type: ignore[assignment] + message_type: Literal["FRBCStorageDescription"] = Field(default="FRBCStorageDescription") diff --git a/src/s2python/frbc/frbc_storage_status.py b/src/s2python/frbc/frbc_storage_status.py index 2feca7d..96b683d 100644 --- a/src/s2python/frbc/frbc_storage_status.py +++ b/src/s2python/frbc/frbc_storage_status.py @@ -1,3 +1,5 @@ +from pydantic import Field +from typing import Literal import uuid from s2python.generated.gen_s2 import FRBCStorageStatus as GenFRBCStorageStatus @@ -13,3 +15,4 @@ class Config(GenFRBCStorageStatus.Config): validate_assignment = True message_id: uuid.UUID = GenFRBCStorageStatus.__fields__["message_id"].field_info # type: ignore[assignment] + message_type: Literal["FRBCStorageStatus"] = Field(default="FRBCStorageStatus") diff --git a/src/s2python/frbc/frbc_system_description.py b/src/s2python/frbc/frbc_system_description.py index 7b1a8ac..ddac09c 100644 --- a/src/s2python/frbc/frbc_system_description.py +++ b/src/s2python/frbc/frbc_system_description.py @@ -1,4 +1,5 @@ -from typing import List +from pydantic import Field +from typing import List, Literal import uuid from s2python.generated.gen_s2 import FRBCSystemDescription as GenFRBCSystemDescription @@ -24,3 +25,4 @@ class Config(GenFRBCSystemDescription.Config): storage: FRBCStorageDescription = GenFRBCSystemDescription.__fields__[ "storage" ].field_info # type: ignore[assignment] + message_type: Literal["FRBCSystemDescription"] = Field(default="FRBCSystemDescription") diff --git a/src/s2python/frbc/frbc_timer_status.py b/src/s2python/frbc/frbc_timer_status.py index dc06787..e1cb607 100644 --- a/src/s2python/frbc/frbc_timer_status.py +++ b/src/s2python/frbc/frbc_timer_status.py @@ -1,3 +1,5 @@ +from pydantic import Field +from typing import Literal import uuid from s2python.generated.gen_s2 import FRBCTimerStatus as GenFRBCTimerStatus @@ -15,3 +17,4 @@ class Config(GenFRBCTimerStatus.Config): actuator_id: uuid.UUID = GenFRBCTimerStatus.__fields__["actuator_id"].field_info # type: ignore[assignment] message_id: uuid.UUID = GenFRBCTimerStatus.__fields__["message_id"].field_info # type: ignore[assignment] timer_id: uuid.UUID = GenFRBCTimerStatus.__fields__["timer_id"].field_info # type: ignore[assignment] + message_type: Literal["FRBCTimerStatus"] = Field(default="FRBCTimerStatus") diff --git a/src/s2python/frbc/frbc_usage_forecast.py b/src/s2python/frbc/frbc_usage_forecast.py index 618ac53..6fa5327 100644 --- a/src/s2python/frbc/frbc_usage_forecast.py +++ b/src/s2python/frbc/frbc_usage_forecast.py @@ -1,4 +1,5 @@ -from typing import List +from pydantic import Field +from typing import List, Literal import uuid from s2python.generated.gen_s2 import FRBCUsageForecast as GenFRBCUsageForecast @@ -18,3 +19,4 @@ class Config(GenFRBCUsageForecast.Config): "elements" ].field_info # type: ignore[assignment] message_id: uuid.UUID = GenFRBCUsageForecast.__fields__["message_id"].field_info # type: ignore[assignment] + message_type: Literal["FRBCUsageForecast"] = Field(default="FRBCUsageForecast") diff --git a/src/s2python/frbc/frbc_usage_forecast_element.py b/src/s2python/frbc/frbc_usage_forecast_element.py index c4337eb..d661a06 100644 --- a/src/s2python/frbc/frbc_usage_forecast_element.py +++ b/src/s2python/frbc/frbc_usage_forecast_element.py @@ -1,3 +1,6 @@ +from pydantic import Field +from typing import Literal + from s2python.common import Duration from s2python.generated.gen_s2 import ( @@ -17,3 +20,4 @@ class Config(GenFRBCUsageForecastElement.Config): validate_assignment = True duration: Duration = GenFRBCUsageForecastElement.__fields__["duration"].field_info # type: ignore[assignment] + message_type: Literal["FRBCUsageForecastElement"] = Field(default="FRBCUsageForecastElement") From 2d13d5af48db65d37d21cd649d348eee474ac546 Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Mon, 2 Dec 2024 16:31:13 +0100 Subject: [PATCH 03/16] chore: run `datamodel-codegen --input specification/openapi.yml --input-file-type openapi --output src/s2python/generated/gen_s2.py` Signed-off-by: F.N. Claessen --- src/s2python/generated/gen_s2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/s2python/generated/gen_s2.py b/src/s2python/generated/gen_s2.py index 55da95f..6438f43 100644 --- a/src/s2python/generated/gen_s2.py +++ b/src/s2python/generated/gen_s2.py @@ -1,6 +1,6 @@ # generated by datamodel-codegen: # filename: openapi.yml -# timestamp: 2024-07-29T08:53:39+00:00 +# timestamp: 2024-12-02T15:28:08+00:00 from __future__ import annotations From 02966c21e4d70364af3be60ade5e39479c62c25e Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Wed, 15 Jan 2025 21:35:24 +0100 Subject: [PATCH 04/16] refactor: rename old S2Message to S2MessageComponent Signed-off-by: F.N. Claessen --- src/s2python/common/duration.py | 4 +-- src/s2python/common/handshake.py | 4 +-- src/s2python/common/handshake_response.py | 4 +-- .../common/instruction_status_update.py | 4 +-- src/s2python/common/number_range.py | 4 +-- src/s2python/common/power_forecast.py | 4 +-- src/s2python/common/power_forecast_element.py | 4 +-- src/s2python/common/power_forecast_value.py | 4 +-- src/s2python/common/power_measurement.py | 4 +-- src/s2python/common/power_range.py | 4 +-- src/s2python/common/power_value.py | 4 +-- src/s2python/common/reception_status.py | 4 +-- .../common/resource_manager_details.py | 4 +-- src/s2python/common/revoke_object.py | 4 +-- src/s2python/common/role.py | 4 +-- src/s2python/common/select_control_type.py | 4 +-- src/s2python/common/session_request.py | 4 +-- src/s2python/common/timer.py | 4 +-- src/s2python/common/transition.py | 4 +-- .../frbc/frbc_actuator_description.py | 4 +-- src/s2python/frbc/frbc_actuator_status.py | 4 +-- .../frbc/frbc_fill_level_target_profile.py | 4 +-- .../frbc_fill_level_target_profile_element.py | 4 +-- src/s2python/frbc/frbc_instruction.py | 4 +-- src/s2python/frbc/frbc_leakage_behaviour.py | 4 +-- .../frbc/frbc_leakage_behaviour_element.py | 4 +-- src/s2python/frbc/frbc_operation_mode.py | 4 +-- .../frbc/frbc_operation_mode_element.py | 4 +-- src/s2python/frbc/frbc_storage_description.py | 4 +-- src/s2python/frbc/frbc_storage_status.py | 4 +-- src/s2python/frbc/frbc_system_description.py | 4 +-- src/s2python/frbc/frbc_timer_status.py | 4 +-- src/s2python/frbc/frbc_usage_forecast.py | 4 +-- .../frbc/frbc_usage_forecast_element.py | 4 +-- .../ppbc/ppbc_end_interruption_instruction.py | 4 +-- .../ppbc/ppbc_power_profile_definition.py | 4 +-- .../ppbc/ppbc_power_profile_status.py | 4 +-- src/s2python/ppbc/ppbc_power_sequence.py | 4 +-- .../ppbc/ppbc_power_sequence_container.py | 4 +-- .../ppbc_power_sequence_container_status.py | 4 +-- .../ppbc/ppbc_power_sequence_element.py | 4 +-- .../ppbc/ppbc_schedule_instruction.py | 4 +-- .../ppbc_start_interruption_instruction.py | 4 +-- src/s2python/s2_connection.py | 30 +++++++++---------- src/s2python/s2_control_type.py | 6 ++-- src/s2python/s2_parser.py | 8 ++--- src/s2python/validate_values_mixin.py | 4 +-- 47 files changed, 110 insertions(+), 110 deletions(-) diff --git a/src/s2python/common/duration.py b/src/s2python/common/duration.py index 65663c0..a8f6708 100644 --- a/src/s2python/common/duration.py +++ b/src/s2python/common/duration.py @@ -4,12 +4,12 @@ from s2python.generated.gen_s2 import Duration as GenDuration from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class Duration(GenDuration, S2Message["Duration"]): +class Duration(GenDuration, S2MessageComponent["Duration"]): def to_timedelta(self) -> timedelta: return timedelta(milliseconds=self.root) diff --git a/src/s2python/common/handshake.py b/src/s2python/common/handshake.py index c068150..9598c95 100644 --- a/src/s2python/common/handshake.py +++ b/src/s2python/common/handshake.py @@ -3,12 +3,12 @@ from s2python.generated.gen_s2 import Handshake as GenHandshake from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class Handshake(GenHandshake, S2Message["Handshake"]): +class Handshake(GenHandshake, S2MessageComponent["Handshake"]): model_config = GenHandshake.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/common/handshake_response.py b/src/s2python/common/handshake_response.py index fcc2eb5..e6a9d95 100644 --- a/src/s2python/common/handshake_response.py +++ b/src/s2python/common/handshake_response.py @@ -3,12 +3,12 @@ from s2python.generated.gen_s2 import HandshakeResponse as GenHandshakeResponse from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class HandshakeResponse(GenHandshakeResponse, S2Message["HandshakeResponse"]): +class HandshakeResponse(GenHandshakeResponse, S2MessageComponent["HandshakeResponse"]): model_config = GenHandshakeResponse.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/common/instruction_status_update.py b/src/s2python/common/instruction_status_update.py index 5a8c45f..6420058 100644 --- a/src/s2python/common/instruction_status_update.py +++ b/src/s2python/common/instruction_status_update.py @@ -5,12 +5,12 @@ ) from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class InstructionStatusUpdate(GenInstructionStatusUpdate, S2Message["InstructionStatusUpdate"]): +class InstructionStatusUpdate(GenInstructionStatusUpdate, S2MessageComponent["InstructionStatusUpdate"]): model_config = GenInstructionStatusUpdate.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/common/number_range.py b/src/s2python/common/number_range.py index 070b74a..40525a2 100644 --- a/src/s2python/common/number_range.py +++ b/src/s2python/common/number_range.py @@ -1,11 +1,11 @@ from typing import Any -from s2python.validate_values_mixin import S2Message, catch_and_convert_exceptions +from s2python.validate_values_mixin import S2MessageComponent, catch_and_convert_exceptions from s2python.generated.gen_s2 import NumberRange as GenNumberRange @catch_and_convert_exceptions -class NumberRange(GenNumberRange, S2Message["NumberRange"]): +class NumberRange(GenNumberRange, S2MessageComponent["NumberRange"]): model_config = GenNumberRange.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/common/power_forecast.py b/src/s2python/common/power_forecast.py index 31c595d..dff4fe2 100644 --- a/src/s2python/common/power_forecast.py +++ b/src/s2python/common/power_forecast.py @@ -5,12 +5,12 @@ from s2python.generated.gen_s2 import PowerForecast as GenPowerForecast from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class PowerForecast(GenPowerForecast, S2Message["PowerForecast"]): +class PowerForecast(GenPowerForecast, S2MessageComponent["PowerForecast"]): model_config = GenPowerForecast.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/common/power_forecast_element.py b/src/s2python/common/power_forecast_element.py index 10460f7..5f1626d 100644 --- a/src/s2python/common/power_forecast_element.py +++ b/src/s2python/common/power_forecast_element.py @@ -3,14 +3,14 @@ from s2python.generated.gen_s2 import PowerForecastElement as GenPowerForecastElement from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) from s2python.common.duration import Duration from s2python.common.power_forecast_value import PowerForecastValue @catch_and_convert_exceptions -class PowerForecastElement(GenPowerForecastElement, S2Message["PowerForecastElement"]): +class PowerForecastElement(GenPowerForecastElement, S2MessageComponent["PowerForecastElement"]): model_config = GenPowerForecastElement.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/common/power_forecast_value.py b/src/s2python/common/power_forecast_value.py index 3ee2cc3..296b35e 100644 --- a/src/s2python/common/power_forecast_value.py +++ b/src/s2python/common/power_forecast_value.py @@ -1,11 +1,11 @@ from s2python.generated.gen_s2 import PowerForecastValue as GenPowerForecastValue from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class PowerForecastValue(GenPowerForecastValue, S2Message["PowerForecastValue"]): +class PowerForecastValue(GenPowerForecastValue, S2MessageComponent["PowerForecastValue"]): model_config = GenPowerForecastValue.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/common/power_measurement.py b/src/s2python/common/power_measurement.py index 27896c9..b4c1749 100644 --- a/src/s2python/common/power_measurement.py +++ b/src/s2python/common/power_measurement.py @@ -5,12 +5,12 @@ from s2python.generated.gen_s2 import PowerMeasurement as GenPowerMeasurement from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class PowerMeasurement(GenPowerMeasurement, S2Message["PowerMeasurement"]): +class PowerMeasurement(GenPowerMeasurement, S2MessageComponent["PowerMeasurement"]): model_config = GenPowerMeasurement.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/common/power_range.py b/src/s2python/common/power_range.py index 4ca1ec8..dc0e0bf 100644 --- a/src/s2python/common/power_range.py +++ b/src/s2python/common/power_range.py @@ -4,13 +4,13 @@ from s2python.generated.gen_s2 import PowerRange as GenPowerRange from s2python.validate_values_mixin import ( - S2Message, + S2MessageComponent, catch_and_convert_exceptions, ) @catch_and_convert_exceptions -class PowerRange(GenPowerRange, S2Message["PowerRange"]): +class PowerRange(GenPowerRange, S2MessageComponent["PowerRange"]): model_config = GenPowerRange.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/common/power_value.py b/src/s2python/common/power_value.py index c623627..a210bf2 100644 --- a/src/s2python/common/power_value.py +++ b/src/s2python/common/power_value.py @@ -1,11 +1,11 @@ from s2python.generated.gen_s2 import PowerValue as GenPowerValue from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class PowerValue(GenPowerValue, S2Message["PowerValue"]): +class PowerValue(GenPowerValue, S2MessageComponent["PowerValue"]): model_config = GenPowerValue.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/common/reception_status.py b/src/s2python/common/reception_status.py index a759897..edae59c 100644 --- a/src/s2python/common/reception_status.py +++ b/src/s2python/common/reception_status.py @@ -3,12 +3,12 @@ from s2python.generated.gen_s2 import ReceptionStatus as GenReceptionStatus from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class ReceptionStatus(GenReceptionStatus, S2Message["ReceptionStatus"]): +class ReceptionStatus(GenReceptionStatus, S2MessageComponent["ReceptionStatus"]): model_config = GenReceptionStatus.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/common/resource_manager_details.py b/src/s2python/common/resource_manager_details.py index 82ce844..35b00b6 100644 --- a/src/s2python/common/resource_manager_details.py +++ b/src/s2python/common/resource_manager_details.py @@ -8,12 +8,12 @@ ) from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class ResourceManagerDetails(GenResourceManagerDetails, S2Message["ResourceManagerDetails"]): +class ResourceManagerDetails(GenResourceManagerDetails, S2MessageComponent["ResourceManagerDetails"]): model_config = GenResourceManagerDetails.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/common/revoke_object.py b/src/s2python/common/revoke_object.py index d133c79..250628b 100644 --- a/src/s2python/common/revoke_object.py +++ b/src/s2python/common/revoke_object.py @@ -3,12 +3,12 @@ from s2python.generated.gen_s2 import RevokeObject as GenRevokeObject from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class RevokeObject(GenRevokeObject, S2Message["RevokeObject"]): +class RevokeObject(GenRevokeObject, S2MessageComponent["RevokeObject"]): model_config = GenRevokeObject.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/common/role.py b/src/s2python/common/role.py index 4a3d3ef..293983c 100644 --- a/src/s2python/common/role.py +++ b/src/s2python/common/role.py @@ -1,11 +1,11 @@ from s2python.generated.gen_s2 import Role as GenRole from s2python.validate_values_mixin import ( - S2Message, + S2MessageComponent, catch_and_convert_exceptions, ) @catch_and_convert_exceptions -class Role(GenRole, S2Message["Role"]): +class Role(GenRole, S2MessageComponent["Role"]): model_config = GenRole.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/common/select_control_type.py b/src/s2python/common/select_control_type.py index 5f02954..675fcc8 100644 --- a/src/s2python/common/select_control_type.py +++ b/src/s2python/common/select_control_type.py @@ -3,12 +3,12 @@ from s2python.generated.gen_s2 import SelectControlType as GenSelectControlType from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class SelectControlType(GenSelectControlType, S2Message["SelectControlType"]): +class SelectControlType(GenSelectControlType, S2MessageComponent["SelectControlType"]): model_config = GenSelectControlType.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/common/session_request.py b/src/s2python/common/session_request.py index f962427..907eb67 100644 --- a/src/s2python/common/session_request.py +++ b/src/s2python/common/session_request.py @@ -3,12 +3,12 @@ from s2python.generated.gen_s2 import SessionRequest as GenSessionRequest from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class SessionRequest(GenSessionRequest, S2Message["SessionRequest"]): +class SessionRequest(GenSessionRequest, S2MessageComponent["SessionRequest"]): model_config = GenSessionRequest.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/common/timer.py b/src/s2python/common/timer.py index 3811082..e4f313e 100644 --- a/src/s2python/common/timer.py +++ b/src/s2python/common/timer.py @@ -3,13 +3,13 @@ from s2python.common.duration import Duration from s2python.generated.gen_s2 import Timer as GenTimer from s2python.validate_values_mixin import ( - S2Message, + S2MessageComponent, catch_and_convert_exceptions, ) @catch_and_convert_exceptions -class Timer(GenTimer, S2Message["Timer"]): +class Timer(GenTimer, S2MessageComponent["Timer"]): model_config = GenTimer.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/common/transition.py b/src/s2python/common/transition.py index e1e1a25..2c10a06 100644 --- a/src/s2python/common/transition.py +++ b/src/s2python/common/transition.py @@ -4,13 +4,13 @@ from s2python.common.duration import Duration from s2python.generated.gen_s2 import Transition as GenTransition from s2python.validate_values_mixin import ( - S2Message, + S2MessageComponent, catch_and_convert_exceptions, ) @catch_and_convert_exceptions -class Transition(GenTransition, S2Message["Transition"]): +class Transition(GenTransition, S2MessageComponent["Transition"]): model_config = GenTransition.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/frbc/frbc_actuator_description.py b/src/s2python/frbc/frbc_actuator_description.py index 08afce6..eee1132 100644 --- a/src/s2python/frbc/frbc_actuator_description.py +++ b/src/s2python/frbc/frbc_actuator_description.py @@ -12,13 +12,13 @@ FRBCActuatorDescription as GenFRBCActuatorDescription, ) from s2python.validate_values_mixin import ( - S2Message, + S2MessageComponent, catch_and_convert_exceptions, ) @catch_and_convert_exceptions -class FRBCActuatorDescription(GenFRBCActuatorDescription, S2Message["FRBCActuatorDescription"]): +class FRBCActuatorDescription(GenFRBCActuatorDescription, S2MessageComponent["FRBCActuatorDescription"]): model_config = GenFRBCActuatorDescription.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/frbc/frbc_actuator_status.py b/src/s2python/frbc/frbc_actuator_status.py index 585a23d..a9d6072 100644 --- a/src/s2python/frbc/frbc_actuator_status.py +++ b/src/s2python/frbc/frbc_actuator_status.py @@ -4,12 +4,12 @@ from s2python.generated.gen_s2 import FRBCActuatorStatus as GenFRBCActuatorStatus from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class FRBCActuatorStatus(GenFRBCActuatorStatus, S2Message["FRBCActuatorStatus"]): +class FRBCActuatorStatus(GenFRBCActuatorStatus, S2MessageComponent["FRBCActuatorStatus"]): model_config = GenFRBCActuatorStatus.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/frbc/frbc_fill_level_target_profile.py b/src/s2python/frbc/frbc_fill_level_target_profile.py index 38ef83b..5232172 100644 --- a/src/s2python/frbc/frbc_fill_level_target_profile.py +++ b/src/s2python/frbc/frbc_fill_level_target_profile.py @@ -9,12 +9,12 @@ ) from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class FRBCFillLevelTargetProfile(GenFRBCFillLevelTargetProfile, S2Message["FRBCFillLevelTargetProfile"]): +class FRBCFillLevelTargetProfile(GenFRBCFillLevelTargetProfile, S2MessageComponent["FRBCFillLevelTargetProfile"]): model_config = GenFRBCFillLevelTargetProfile.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/frbc/frbc_fill_level_target_profile_element.py b/src/s2python/frbc/frbc_fill_level_target_profile_element.py index cdb7d84..ab32ef5 100644 --- a/src/s2python/frbc/frbc_fill_level_target_profile_element.py +++ b/src/s2python/frbc/frbc_fill_level_target_profile_element.py @@ -8,12 +8,12 @@ from s2python.generated.gen_s2 import ( FRBCFillLevelTargetProfileElement as GenFRBCFillLevelTargetProfileElement, ) -from s2python.validate_values_mixin import catch_and_convert_exceptions, S2Message +from s2python.validate_values_mixin import catch_and_convert_exceptions, S2MessageComponent @catch_and_convert_exceptions class FRBCFillLevelTargetProfileElement( - GenFRBCFillLevelTargetProfileElement, S2Message["FRBCFillLevelTargetProfileElement"] + GenFRBCFillLevelTargetProfileElement, S2MessageComponent["FRBCFillLevelTargetProfileElement"] ): model_config = GenFRBCFillLevelTargetProfileElement.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/frbc/frbc_instruction.py b/src/s2python/frbc/frbc_instruction.py index 584cfba..ca465f6 100644 --- a/src/s2python/frbc/frbc_instruction.py +++ b/src/s2python/frbc/frbc_instruction.py @@ -3,12 +3,12 @@ from s2python.generated.gen_s2 import FRBCInstruction as GenFRBCInstruction from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class FRBCInstruction(GenFRBCInstruction, S2Message["FRBCInstruction"]): +class FRBCInstruction(GenFRBCInstruction, S2MessageComponent["FRBCInstruction"]): model_config = GenFRBCInstruction.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/frbc/frbc_leakage_behaviour.py b/src/s2python/frbc/frbc_leakage_behaviour.py index fda7d3b..29ca901 100644 --- a/src/s2python/frbc/frbc_leakage_behaviour.py +++ b/src/s2python/frbc/frbc_leakage_behaviour.py @@ -5,12 +5,12 @@ from s2python.generated.gen_s2 import FRBCLeakageBehaviour as GenFRBCLeakageBehaviour from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class FRBCLeakageBehaviour(GenFRBCLeakageBehaviour, S2Message["FRBCLeakageBehaviour"]): +class FRBCLeakageBehaviour(GenFRBCLeakageBehaviour, S2MessageComponent["FRBCLeakageBehaviour"]): model_config = GenFRBCLeakageBehaviour.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/frbc/frbc_leakage_behaviour_element.py b/src/s2python/frbc/frbc_leakage_behaviour_element.py index b9ca2eb..103abe9 100644 --- a/src/s2python/frbc/frbc_leakage_behaviour_element.py +++ b/src/s2python/frbc/frbc_leakage_behaviour_element.py @@ -5,12 +5,12 @@ from s2python.common import NumberRange from s2python.generated.gen_s2 import FRBCLeakageBehaviourElement as GenFRBCLeakageBehaviourElement -from s2python.validate_values_mixin import catch_and_convert_exceptions, S2Message +from s2python.validate_values_mixin import catch_and_convert_exceptions, S2MessageComponent @catch_and_convert_exceptions class FRBCLeakageBehaviourElement( - GenFRBCLeakageBehaviourElement, S2Message["FRBCLeakageBehaviourElement"] + GenFRBCLeakageBehaviourElement, S2MessageComponent["FRBCLeakageBehaviourElement"] ): model_config = GenFRBCLeakageBehaviourElement.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/frbc/frbc_operation_mode.py b/src/s2python/frbc/frbc_operation_mode.py index c6758ad..a37d0d9 100644 --- a/src/s2python/frbc/frbc_operation_mode.py +++ b/src/s2python/frbc/frbc_operation_mode.py @@ -9,14 +9,14 @@ from s2python.frbc.frbc_operation_mode_element import FRBCOperationModeElement from s2python.generated.gen_s2 import FRBCOperationMode as GenFRBCOperationMode from s2python.validate_values_mixin import ( - S2Message, + S2MessageComponent, catch_and_convert_exceptions, ) from s2python.utils import pairwise @catch_and_convert_exceptions -class FRBCOperationMode(GenFRBCOperationMode, S2Message["FRBCOperationMode"]): +class FRBCOperationMode(GenFRBCOperationMode, S2MessageComponent["FRBCOperationMode"]): model_config = GenFRBCOperationMode.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/frbc/frbc_operation_mode_element.py b/src/s2python/frbc/frbc_operation_mode_element.py index d154d11..55f18b3 100644 --- a/src/s2python/frbc/frbc_operation_mode_element.py +++ b/src/s2python/frbc/frbc_operation_mode_element.py @@ -5,13 +5,13 @@ FRBCOperationModeElement as GenFRBCOperationModeElement, ) from s2python.validate_values_mixin import ( - S2Message, + S2MessageComponent, catch_and_convert_exceptions, ) @catch_and_convert_exceptions -class FRBCOperationModeElement(GenFRBCOperationModeElement, S2Message["FRBCOperationModeElement"]): +class FRBCOperationModeElement(GenFRBCOperationModeElement, S2MessageComponent["FRBCOperationModeElement"]): model_config = GenFRBCOperationModeElement.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/frbc/frbc_storage_description.py b/src/s2python/frbc/frbc_storage_description.py index eb141b8..3b2c985 100644 --- a/src/s2python/frbc/frbc_storage_description.py +++ b/src/s2python/frbc/frbc_storage_description.py @@ -4,12 +4,12 @@ ) from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class FRBCStorageDescription(GenFRBCStorageDescription, S2Message["FRBCStorageDescription"]): +class FRBCStorageDescription(GenFRBCStorageDescription, S2MessageComponent["FRBCStorageDescription"]): model_config = GenFRBCStorageDescription.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/frbc/frbc_storage_status.py b/src/s2python/frbc/frbc_storage_status.py index 7940b79..d0ce3e1 100644 --- a/src/s2python/frbc/frbc_storage_status.py +++ b/src/s2python/frbc/frbc_storage_status.py @@ -3,12 +3,12 @@ from s2python.generated.gen_s2 import FRBCStorageStatus as GenFRBCStorageStatus from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class FRBCStorageStatus(GenFRBCStorageStatus, S2Message["FRBCStorageStatus"]): +class FRBCStorageStatus(GenFRBCStorageStatus, S2MessageComponent["FRBCStorageStatus"]): model_config = GenFRBCStorageStatus.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/frbc/frbc_system_description.py b/src/s2python/frbc/frbc_system_description.py index 2eb5899..4497d44 100644 --- a/src/s2python/frbc/frbc_system_description.py +++ b/src/s2python/frbc/frbc_system_description.py @@ -4,14 +4,14 @@ from s2python.generated.gen_s2 import FRBCSystemDescription as GenFRBCSystemDescription from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) from s2python.frbc.frbc_actuator_description import FRBCActuatorDescription from s2python.frbc.frbc_storage_description import FRBCStorageDescription @catch_and_convert_exceptions -class FRBCSystemDescription(GenFRBCSystemDescription, S2Message["FRBCSystemDescription"]): +class FRBCSystemDescription(GenFRBCSystemDescription, S2MessageComponent["FRBCSystemDescription"]): model_config = GenFRBCSystemDescription.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/frbc/frbc_timer_status.py b/src/s2python/frbc/frbc_timer_status.py index 80c86d6..02a6d22 100644 --- a/src/s2python/frbc/frbc_timer_status.py +++ b/src/s2python/frbc/frbc_timer_status.py @@ -3,12 +3,12 @@ from s2python.generated.gen_s2 import FRBCTimerStatus as GenFRBCTimerStatus from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class FRBCTimerStatus(GenFRBCTimerStatus, S2Message["FRBCTimerStatus"]): +class FRBCTimerStatus(GenFRBCTimerStatus, S2MessageComponent["FRBCTimerStatus"]): model_config = GenFRBCTimerStatus.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/frbc/frbc_usage_forecast.py b/src/s2python/frbc/frbc_usage_forecast.py index f71fda4..bab3297 100644 --- a/src/s2python/frbc/frbc_usage_forecast.py +++ b/src/s2python/frbc/frbc_usage_forecast.py @@ -4,13 +4,13 @@ from s2python.generated.gen_s2 import FRBCUsageForecast as GenFRBCUsageForecast from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) from s2python.frbc.frbc_usage_forecast_element import FRBCUsageForecastElement @catch_and_convert_exceptions -class FRBCUsageForecast(GenFRBCUsageForecast, S2Message["FRBCUsageForecast"]): +class FRBCUsageForecast(GenFRBCUsageForecast, S2MessageComponent["FRBCUsageForecast"]): model_config = GenFRBCUsageForecast.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/frbc/frbc_usage_forecast_element.py b/src/s2python/frbc/frbc_usage_forecast_element.py index 370c04e..97e9524 100644 --- a/src/s2python/frbc/frbc_usage_forecast_element.py +++ b/src/s2python/frbc/frbc_usage_forecast_element.py @@ -5,12 +5,12 @@ ) from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions -class FRBCUsageForecastElement(GenFRBCUsageForecastElement, S2Message["FRBCUsageForecastElement"]): +class FRBCUsageForecastElement(GenFRBCUsageForecastElement, S2MessageComponent["FRBCUsageForecastElement"]): model_config = GenFRBCUsageForecastElement.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/ppbc/ppbc_end_interruption_instruction.py b/src/s2python/ppbc/ppbc_end_interruption_instruction.py index d53c527..2b098f1 100644 --- a/src/s2python/ppbc/ppbc_end_interruption_instruction.py +++ b/src/s2python/ppbc/ppbc_end_interruption_instruction.py @@ -5,14 +5,14 @@ ) from s2python.validate_values_mixin import ( - S2Message, + S2MessageComponent, catch_and_convert_exceptions, ) @catch_and_convert_exceptions class PPBCEndInterruptionInstruction( - GenPPBCEndInterruptionInstruction, S2Message["PPBCEndInterruptionInstruction"] + GenPPBCEndInterruptionInstruction, S2MessageComponent["PPBCEndInterruptionInstruction"] ): model_config = GenPPBCEndInterruptionInstruction.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/ppbc/ppbc_power_profile_definition.py b/src/s2python/ppbc/ppbc_power_profile_definition.py index cc4ba6a..d3926c7 100644 --- a/src/s2python/ppbc/ppbc_power_profile_definition.py +++ b/src/s2python/ppbc/ppbc_power_profile_definition.py @@ -6,7 +6,7 @@ ) from s2python.validate_values_mixin import ( - S2Message, + S2MessageComponent, catch_and_convert_exceptions, ) @@ -15,7 +15,7 @@ @catch_and_convert_exceptions class PPBCPowerProfileDefinition( - GenPPBCPowerProfileDefinition, S2Message["PPBCPowerProfileDefinition"] + GenPPBCPowerProfileDefinition, S2MessageComponent["PPBCPowerProfileDefinition"] ): model_config = GenPPBCPowerProfileDefinition.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/ppbc/ppbc_power_profile_status.py b/src/s2python/ppbc/ppbc_power_profile_status.py index d44f7e2..bec09cd 100644 --- a/src/s2python/ppbc/ppbc_power_profile_status.py +++ b/src/s2python/ppbc/ppbc_power_profile_status.py @@ -5,7 +5,7 @@ ) from s2python.validate_values_mixin import ( - S2Message, + S2MessageComponent, catch_and_convert_exceptions, ) @@ -16,7 +16,7 @@ @catch_and_convert_exceptions class PPBCPowerProfileStatus( - GenPPBCPowerProfileStatus, S2Message["PPBCPowerProfileStatus"] + GenPPBCPowerProfileStatus, S2MessageComponent["PPBCPowerProfileStatus"] ): model_config = GenPPBCPowerProfileStatus.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/ppbc/ppbc_power_sequence.py b/src/s2python/ppbc/ppbc_power_sequence.py index 95e2758..6f7af3d 100644 --- a/src/s2python/ppbc/ppbc_power_sequence.py +++ b/src/s2python/ppbc/ppbc_power_sequence.py @@ -6,7 +6,7 @@ ) from s2python.validate_values_mixin import ( - S2Message, + S2MessageComponent, catch_and_convert_exceptions, ) @@ -15,7 +15,7 @@ @catch_and_convert_exceptions -class PPBCPowerSequence(GenPPBCPowerSequence, S2Message["PPBCPowerSequence"]): +class PPBCPowerSequence(GenPPBCPowerSequence, S2MessageComponent["PPBCPowerSequence"]): model_config = GenPPBCPowerSequence.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/ppbc/ppbc_power_sequence_container.py b/src/s2python/ppbc/ppbc_power_sequence_container.py index 3a11163..08f30ff 100644 --- a/src/s2python/ppbc/ppbc_power_sequence_container.py +++ b/src/s2python/ppbc/ppbc_power_sequence_container.py @@ -7,7 +7,7 @@ ) from s2python.validate_values_mixin import ( - S2Message, + S2MessageComponent, catch_and_convert_exceptions, ) @@ -16,7 +16,7 @@ @catch_and_convert_exceptions class PPBCPowerSequenceContainer( - GenPPBCPowerSequenceContainer, S2Message["PPBCPowerSequenceContainer"] + GenPPBCPowerSequenceContainer, S2MessageComponent["PPBCPowerSequenceContainer"] ): model_config = GenPPBCPowerSequenceContainer.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/ppbc/ppbc_power_sequence_container_status.py b/src/s2python/ppbc/ppbc_power_sequence_container_status.py index 624e4d6..19e897d 100644 --- a/src/s2python/ppbc/ppbc_power_sequence_container_status.py +++ b/src/s2python/ppbc/ppbc_power_sequence_container_status.py @@ -6,14 +6,14 @@ ) from s2python.validate_values_mixin import ( - S2Message, + S2MessageComponent, catch_and_convert_exceptions, ) @catch_and_convert_exceptions class PPBCPowerSequenceContainerStatus( - GenPPBCPowerSequenceContainerStatus, S2Message["PPBCPowerSequenceContainerStatus"] + GenPPBCPowerSequenceContainerStatus, S2MessageComponent["PPBCPowerSequenceContainerStatus"] ): model_config = GenPPBCPowerSequenceContainerStatus.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/ppbc/ppbc_power_sequence_element.py b/src/s2python/ppbc/ppbc_power_sequence_element.py index 1372063..206f5ec 100644 --- a/src/s2python/ppbc/ppbc_power_sequence_element.py +++ b/src/s2python/ppbc/ppbc_power_sequence_element.py @@ -5,7 +5,7 @@ ) from s2python.validate_values_mixin import ( - S2Message, + S2MessageComponent, catch_and_convert_exceptions, ) @@ -14,7 +14,7 @@ @catch_and_convert_exceptions class PPBCPowerSequenceElement( - GenPPBCPowerSequenceElement, S2Message["PPBCPowerSequenceElement"] + GenPPBCPowerSequenceElement, S2MessageComponent["PPBCPowerSequenceElement"] ): model_config = GenPPBCPowerSequenceElement.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/ppbc/ppbc_schedule_instruction.py b/src/s2python/ppbc/ppbc_schedule_instruction.py index c794b78..2e7802d 100644 --- a/src/s2python/ppbc/ppbc_schedule_instruction.py +++ b/src/s2python/ppbc/ppbc_schedule_instruction.py @@ -5,13 +5,13 @@ ) from s2python.validate_values_mixin import ( catch_and_convert_exceptions, - S2Message, + S2MessageComponent, ) @catch_and_convert_exceptions class PPBCScheduleInstruction( - GenPPBCScheduleInstruction, S2Message["PPBCScheduleInstruction"] + GenPPBCScheduleInstruction, S2MessageComponent["PPBCScheduleInstruction"] ): model_config = GenPPBCScheduleInstruction.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/ppbc/ppbc_start_interruption_instruction.py b/src/s2python/ppbc/ppbc_start_interruption_instruction.py index f6d25ff..0924021 100644 --- a/src/s2python/ppbc/ppbc_start_interruption_instruction.py +++ b/src/s2python/ppbc/ppbc_start_interruption_instruction.py @@ -5,14 +5,14 @@ ) from s2python.validate_values_mixin import ( - S2Message, + S2MessageComponent, catch_and_convert_exceptions, ) @catch_and_convert_exceptions class PPBCStartInterruptionInstruction( - GenPPBCStartInterruptionInstruction, S2Message["PPBCStartInterruptionInstruction"] + GenPPBCStartInterruptionInstruction, S2MessageComponent["PPBCStartInterruptionInstruction"] ): model_config = GenPPBCStartInterruptionInstruction.model_config model_config["validate_assignment"] = True diff --git a/src/s2python/s2_connection.py b/src/s2python/s2_connection.py index 188ecc7..eeb96bc 100644 --- a/src/s2python/s2_connection.py +++ b/src/s2python/s2_connection.py @@ -27,7 +27,7 @@ from s2python.s2_control_type import S2ControlType from s2python.s2_parser import S2Parser from s2python.s2_validation_error import S2ValidationError -from s2python.validate_values_mixin import S2Message +from s2python.validate_values_mixin import S2MessageComponent from s2python.version import S2_VERSION logger = logging.getLogger("s2python") @@ -73,8 +73,8 @@ def to_resource_manager_details( S2MessageHandler = Union[ - Callable[["S2Connection", S2Message, Callable[[], None]], None], - Callable[["S2Connection", S2Message, Awaitable[None]], Awaitable[None]], + Callable[["S2Connection", S2MessageComponent, Callable[[], None]], None], + Callable[["S2Connection", S2MessageComponent, Awaitable[None]], Awaitable[None]], ] @@ -106,7 +106,7 @@ def run_sync(self) -> None: diagnostic_label="Processed okay.", ) - async def ensure_send_async(self, type_msg: Type[S2Message]) -> None: + async def ensure_send_async(self, type_msg: Type[S2MessageComponent]) -> None: if not self.status_is_send.is_set(): logger.warning( "Handler for message %s %s did not call send_okay / function to send the ReceptionStatus. " @@ -116,7 +116,7 @@ async def ensure_send_async(self, type_msg: Type[S2Message]) -> None: ) await self.run_async() - def ensure_send_sync(self, type_msg: Type[S2Message]) -> None: + def ensure_send_sync(self, type_msg: Type[S2MessageComponent]) -> None: if not self.status_is_send.is_set(): logger.warning( "Handler for message %s %s did not call send_okay / function to send the ReceptionStatus. " @@ -128,12 +128,12 @@ def ensure_send_sync(self, type_msg: Type[S2Message]) -> None: class MessageHandlers: - handlers: Dict[Type[S2Message], S2MessageHandler] + handlers: Dict[Type[S2MessageComponent], S2MessageHandler] def __init__(self) -> None: self.handlers = {} - async def handle_message(self, connection: "S2Connection", msg: S2Message) -> None: + async def handle_message(self, connection: "S2Connection", msg: S2MessageComponent) -> None: """Handle the S2 message using the registered handler. :param connection: The S2 conncetion the `msg` is received from. @@ -170,7 +170,7 @@ def do_message() -> None: type(msg), ) - def register_handler(self, msg_type: Type[S2Message], handler: S2MessageHandler) -> None: + def register_handler(self, msg_type: Type[S2MessageComponent], handler: S2MessageHandler) -> None: """Register a coroutine function or a normal function as the handler for a specific S2 message type. :param msg_type: The S2 message type to attach the handler to. @@ -334,7 +334,7 @@ async def _connect_as_rm(self) -> None: await self._handle_received_messages() async def handle_handshake( - self, _: "S2Connection", message: S2Message, send_okay: Awaitable[None] + self, _: "S2Connection", message: S2MessageComponent, send_okay: Awaitable[None] ) -> None: if not isinstance(message, Handshake): logger.error( @@ -350,7 +350,7 @@ async def handle_handshake( await send_okay async def handle_handshake_response_as_rm( - self, _: "S2Connection", message: S2Message, send_okay: Awaitable[None] + self, _: "S2Connection", message: S2MessageComponent, send_okay: Awaitable[None] ) -> None: if not isinstance(message, HandshakeResponse): logger.error( @@ -370,7 +370,7 @@ async def handle_handshake_response_as_rm( ) async def handle_select_control_type_as_rm( - self, _: "S2Connection", message: S2Message, send_okay: Awaitable[None] + self, _: "S2Connection", message: S2MessageComponent, send_okay: Awaitable[None] ) -> None: if not isinstance(message, SelectControlType): logger.error( @@ -414,7 +414,7 @@ async def _receive_messages(self) -> None: async for message in self.ws: try: - s2_msg: S2Message = self.s2_parser.parse_as_any_message(message) + s2_msg: S2MessageComponent = self.s2_parser.parse_as_any_message(message) except json.JSONDecodeError: await self._send_and_forget( ReceptionStatus( @@ -450,7 +450,7 @@ async def _receive_messages(self) -> None: else: await self._received_messages.put(s2_msg) - async def _send_and_forget(self, s2_msg: S2Message) -> None: + async def _send_and_forget(self, s2_msg: S2MessageComponent) -> None: if self.ws is None: raise RuntimeError( "Cannot send messages if websocket connection is not yet established." @@ -485,7 +485,7 @@ def respond_with_reception_status_sync( ).result() async def send_msg_and_await_reception_status_async( - self, s2_msg: S2Message, timeout_reception_status: float = 5.0, raise_on_error: bool = True + self, s2_msg: S2MessageComponent, timeout_reception_status: float = 5.0, raise_on_error: bool = True ) -> ReceptionStatus: await self._send_and_forget(s2_msg) logger.debug( @@ -511,7 +511,7 @@ async def send_msg_and_await_reception_status_async( return reception_status def send_msg_and_await_reception_status_sync( - self, s2_msg: S2Message, timeout_reception_status: float = 5.0, raise_on_error: bool = True + self, s2_msg: S2MessageComponent, timeout_reception_status: float = 5.0, raise_on_error: bool = True ) -> ReceptionStatus: return asyncio.run_coroutine_threadsafe( self.send_msg_and_await_reception_status_async( diff --git a/src/s2python/s2_control_type.py b/src/s2python/s2_control_type.py index 43f3b8e..39d30c5 100644 --- a/src/s2python/s2_control_type.py +++ b/src/s2python/s2_control_type.py @@ -4,7 +4,7 @@ from s2python.common import ControlType as ProtocolControlType from s2python.frbc import FRBCInstruction from s2python.ppbc import PPBCScheduleInstruction -from s2python.validate_values_mixin import S2Message +from s2python.validate_values_mixin import S2MessageComponent if typing.TYPE_CHECKING: from s2python.s2_connection import S2Connection, MessageHandlers @@ -33,7 +33,7 @@ def register_handlers(self, handlers: "MessageHandlers") -> None: @abc.abstractmethod def handle_instruction( - self, conn: "S2Connection", msg: S2Message, send_okay: typing.Callable[[], None] + self, conn: "S2Connection", msg: S2MessageComponent, send_okay: typing.Callable[[], None] ) -> None: ... @abc.abstractmethod @@ -54,7 +54,7 @@ def register_handlers(self, handlers: "MessageHandlers") -> None: @abc.abstractmethod def handle_instruction( - self, conn: "S2Connection", msg: S2Message, send_okay: typing.Callable[[], None] + self, conn: "S2Connection", msg: S2MessageComponent, send_okay: typing.Callable[[], None] ) -> None: ... @abc.abstractmethod diff --git a/src/s2python/s2_parser.py b/src/s2python/s2_parser.py index e1a5c43..84d720f 100644 --- a/src/s2python/s2_parser.py +++ b/src/s2python/s2_parser.py @@ -26,18 +26,18 @@ ) from s2python.ppbc import PPBCScheduleInstruction -from s2python.validate_values_mixin import S2Message +from s2python.validate_values_mixin import S2MessageComponent from s2python.s2_validation_error import S2ValidationError LOGGER = logging.getLogger(__name__) S2MessageType = str -M = TypeVar("M", bound=S2Message) +M = TypeVar("M", bound=S2MessageComponent) # May be generated with development_utilities/generate_s2_message_type_to_class.py -TYPE_TO_MESSAGE_CLASS: Dict[str, Type[S2Message]] = { +TYPE_TO_MESSAGE_CLASS: Dict[str, Type[S2MessageComponent]] = { "FRBC.ActuatorStatus": FRBCActuatorStatus, "FRBC.FillLevelTargetProfile": FRBCFillLevelTargetProfile, "FRBC.Instruction": FRBCInstruction, @@ -68,7 +68,7 @@ def _parse_json_if_required(unparsed_message: Union[dict, str, bytes]) -> dict: return unparsed_message @staticmethod - def parse_as_any_message(unparsed_message: Union[dict, str, bytes]) -> S2Message: + def parse_as_any_message(unparsed_message: Union[dict, str, bytes]) -> S2MessageComponent: """Parse the message as any S2 python message regardless of message type. :param unparsed_message: The message as a JSON-formatted string or as a json-parsed dictionary. diff --git a/src/s2python/validate_values_mixin.py b/src/s2python/validate_values_mixin.py index 7d0d9d6..cc9c6fd 100644 --- a/src/s2python/validate_values_mixin.py +++ b/src/s2python/validate_values_mixin.py @@ -15,7 +15,7 @@ C = TypeVar("C", bound="BaseModel") -class S2Message(BaseModel, Generic[C]): +class S2MessageComponent(BaseModel, Generic[C]): def to_json(self: C) -> str: try: return self.model_dump_json(by_alias=True, exclude_none=True) @@ -59,7 +59,7 @@ def inner(*args: List[Any], **kwargs: Dict[str, Any]) -> Any: return inner -def catch_and_convert_exceptions(input_class: Type[S2Message[B_co]]) -> Type[S2Message[B_co]]: +def catch_and_convert_exceptions(input_class: Type[S2MessageComponent[B_co]]) -> Type[S2MessageComponent[B_co]]: input_class.__init__ = convert_to_s2exception(input_class.__init__) # type: ignore[method-assign] input_class.__setattr__ = convert_to_s2exception(input_class.__setattr__) # type: ignore[method-assign] input_class.model_validate_json = convert_to_s2exception( # type: ignore[method-assign] From 78ff1d363c18ece1e44bf8d0130fe70347cc9c80 Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Wed, 15 Jan 2025 22:55:52 +0100 Subject: [PATCH 05/16] style: pylint Signed-off-by: F.N. Claessen --- src/s2python/message.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/s2python/message.py b/src/s2python/message.py index cf73bbd..071d16f 100644 --- a/src/s2python/message.py +++ b/src/s2python/message.py @@ -1,5 +1,4 @@ from typing import Union -from pydantic import BaseModel from s2python.frbc import ( FRBCActuatorStatus, @@ -44,4 +43,4 @@ RevokeObject, SelectControlType, SessionRequest, -] \ No newline at end of file +] From fd59de63d5634dfaba55b558ad1a713baa1f39df Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Wed, 15 Jan 2025 23:30:03 +0100 Subject: [PATCH 06/16] refactor: prefer S2Message over S2MessageComponent Signed-off-by: F.N. Claessen --- src/s2python/s2_connection.py | 30 +++++++++++++++--------------- src/s2python/s2_control_type.py | 6 +++--- src/s2python/s2_parser.py | 8 ++++---- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/s2python/s2_connection.py b/src/s2python/s2_connection.py index eeb96bc..1dab4cb 100644 --- a/src/s2python/s2_connection.py +++ b/src/s2python/s2_connection.py @@ -27,7 +27,7 @@ from s2python.s2_control_type import S2ControlType from s2python.s2_parser import S2Parser from s2python.s2_validation_error import S2ValidationError -from s2python.validate_values_mixin import S2MessageComponent +from s2python.message import S2Message from s2python.version import S2_VERSION logger = logging.getLogger("s2python") @@ -73,8 +73,8 @@ def to_resource_manager_details( S2MessageHandler = Union[ - Callable[["S2Connection", S2MessageComponent, Callable[[], None]], None], - Callable[["S2Connection", S2MessageComponent, Awaitable[None]], Awaitable[None]], + Callable[["S2Connection", S2Message, Callable[[], None]], None], + Callable[["S2Connection", S2Message, Awaitable[None]], Awaitable[None]], ] @@ -106,7 +106,7 @@ def run_sync(self) -> None: diagnostic_label="Processed okay.", ) - async def ensure_send_async(self, type_msg: Type[S2MessageComponent]) -> None: + async def ensure_send_async(self, type_msg: Type[S2Message]) -> None: if not self.status_is_send.is_set(): logger.warning( "Handler for message %s %s did not call send_okay / function to send the ReceptionStatus. " @@ -116,7 +116,7 @@ async def ensure_send_async(self, type_msg: Type[S2MessageComponent]) -> None: ) await self.run_async() - def ensure_send_sync(self, type_msg: Type[S2MessageComponent]) -> None: + def ensure_send_sync(self, type_msg: Type[S2Message]) -> None: if not self.status_is_send.is_set(): logger.warning( "Handler for message %s %s did not call send_okay / function to send the ReceptionStatus. " @@ -128,12 +128,12 @@ def ensure_send_sync(self, type_msg: Type[S2MessageComponent]) -> None: class MessageHandlers: - handlers: Dict[Type[S2MessageComponent], S2MessageHandler] + handlers: Dict[Type[S2Message], S2MessageHandler] def __init__(self) -> None: self.handlers = {} - async def handle_message(self, connection: "S2Connection", msg: S2MessageComponent) -> None: + async def handle_message(self, connection: "S2Connection", msg: S2Message) -> None: """Handle the S2 message using the registered handler. :param connection: The S2 conncetion the `msg` is received from. @@ -170,7 +170,7 @@ def do_message() -> None: type(msg), ) - def register_handler(self, msg_type: Type[S2MessageComponent], handler: S2MessageHandler) -> None: + def register_handler(self, msg_type: Type[S2Message], handler: S2MessageHandler) -> None: """Register a coroutine function or a normal function as the handler for a specific S2 message type. :param msg_type: The S2 message type to attach the handler to. @@ -334,7 +334,7 @@ async def _connect_as_rm(self) -> None: await self._handle_received_messages() async def handle_handshake( - self, _: "S2Connection", message: S2MessageComponent, send_okay: Awaitable[None] + self, _: "S2Connection", message: S2Message, send_okay: Awaitable[None] ) -> None: if not isinstance(message, Handshake): logger.error( @@ -350,7 +350,7 @@ async def handle_handshake( await send_okay async def handle_handshake_response_as_rm( - self, _: "S2Connection", message: S2MessageComponent, send_okay: Awaitable[None] + self, _: "S2Connection", message: S2Message, send_okay: Awaitable[None] ) -> None: if not isinstance(message, HandshakeResponse): logger.error( @@ -370,7 +370,7 @@ async def handle_handshake_response_as_rm( ) async def handle_select_control_type_as_rm( - self, _: "S2Connection", message: S2MessageComponent, send_okay: Awaitable[None] + self, _: "S2Connection", message: S2Message, send_okay: Awaitable[None] ) -> None: if not isinstance(message, SelectControlType): logger.error( @@ -414,7 +414,7 @@ async def _receive_messages(self) -> None: async for message in self.ws: try: - s2_msg: S2MessageComponent = self.s2_parser.parse_as_any_message(message) + s2_msg: S2Message = self.s2_parser.parse_as_any_message(message) except json.JSONDecodeError: await self._send_and_forget( ReceptionStatus( @@ -450,7 +450,7 @@ async def _receive_messages(self) -> None: else: await self._received_messages.put(s2_msg) - async def _send_and_forget(self, s2_msg: S2MessageComponent) -> None: + async def _send_and_forget(self, s2_msg: S2Message) -> None: if self.ws is None: raise RuntimeError( "Cannot send messages if websocket connection is not yet established." @@ -485,7 +485,7 @@ def respond_with_reception_status_sync( ).result() async def send_msg_and_await_reception_status_async( - self, s2_msg: S2MessageComponent, timeout_reception_status: float = 5.0, raise_on_error: bool = True + self, s2_msg: S2Message, timeout_reception_status: float = 5.0, raise_on_error: bool = True ) -> ReceptionStatus: await self._send_and_forget(s2_msg) logger.debug( @@ -511,7 +511,7 @@ async def send_msg_and_await_reception_status_async( return reception_status def send_msg_and_await_reception_status_sync( - self, s2_msg: S2MessageComponent, timeout_reception_status: float = 5.0, raise_on_error: bool = True + self, s2_msg: S2Message, timeout_reception_status: float = 5.0, raise_on_error: bool = True ) -> ReceptionStatus: return asyncio.run_coroutine_threadsafe( self.send_msg_and_await_reception_status_async( diff --git a/src/s2python/s2_control_type.py b/src/s2python/s2_control_type.py index 39d30c5..982c9be 100644 --- a/src/s2python/s2_control_type.py +++ b/src/s2python/s2_control_type.py @@ -4,7 +4,7 @@ from s2python.common import ControlType as ProtocolControlType from s2python.frbc import FRBCInstruction from s2python.ppbc import PPBCScheduleInstruction -from s2python.validate_values_mixin import S2MessageComponent +from s2python.message import S2Message if typing.TYPE_CHECKING: from s2python.s2_connection import S2Connection, MessageHandlers @@ -33,7 +33,7 @@ def register_handlers(self, handlers: "MessageHandlers") -> None: @abc.abstractmethod def handle_instruction( - self, conn: "S2Connection", msg: S2MessageComponent, send_okay: typing.Callable[[], None] + self, conn: "S2Connection", msg: S2Message, send_okay: typing.Callable[[], None] ) -> None: ... @abc.abstractmethod @@ -54,7 +54,7 @@ def register_handlers(self, handlers: "MessageHandlers") -> None: @abc.abstractmethod def handle_instruction( - self, conn: "S2Connection", msg: S2MessageComponent, send_okay: typing.Callable[[], None] + self, conn: "S2Connection", msg: S2Message, send_okay: typing.Callable[[], None] ) -> None: ... @abc.abstractmethod diff --git a/src/s2python/s2_parser.py b/src/s2python/s2_parser.py index 84d720f..642843f 100644 --- a/src/s2python/s2_parser.py +++ b/src/s2python/s2_parser.py @@ -26,18 +26,18 @@ ) from s2python.ppbc import PPBCScheduleInstruction -from s2python.validate_values_mixin import S2MessageComponent +from s2python.message import S2Message from s2python.s2_validation_error import S2ValidationError LOGGER = logging.getLogger(__name__) S2MessageType = str -M = TypeVar("M", bound=S2MessageComponent) +M = TypeVar("M", bound=S2Message) # May be generated with development_utilities/generate_s2_message_type_to_class.py -TYPE_TO_MESSAGE_CLASS: Dict[str, Type[S2MessageComponent]] = { +TYPE_TO_MESSAGE_CLASS: Dict[str, Type[S2Message]] = { "FRBC.ActuatorStatus": FRBCActuatorStatus, "FRBC.FillLevelTargetProfile": FRBCFillLevelTargetProfile, "FRBC.Instruction": FRBCInstruction, @@ -68,7 +68,7 @@ def _parse_json_if_required(unparsed_message: Union[dict, str, bytes]) -> dict: return unparsed_message @staticmethod - def parse_as_any_message(unparsed_message: Union[dict, str, bytes]) -> S2MessageComponent: + def parse_as_any_message(unparsed_message: Union[dict, str, bytes]) -> S2Message: """Parse the message as any S2 python message regardless of message type. :param unparsed_message: The message as a JSON-formatted string or as a json-parsed dictionary. From 0171f5a7a3456386d9277677199bc9559b2ca35e Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Wed, 15 Jan 2025 23:35:55 +0100 Subject: [PATCH 07/16] Revert "refactor: prefer S2Message over S2MessageComponent" This reverts commit fd59de63d5634dfaba55b558ad1a713baa1f39df. --- src/s2python/s2_connection.py | 30 +++++++++++++++--------------- src/s2python/s2_control_type.py | 6 +++--- src/s2python/s2_parser.py | 8 ++++---- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/s2python/s2_connection.py b/src/s2python/s2_connection.py index 1dab4cb..eeb96bc 100644 --- a/src/s2python/s2_connection.py +++ b/src/s2python/s2_connection.py @@ -27,7 +27,7 @@ from s2python.s2_control_type import S2ControlType from s2python.s2_parser import S2Parser from s2python.s2_validation_error import S2ValidationError -from s2python.message import S2Message +from s2python.validate_values_mixin import S2MessageComponent from s2python.version import S2_VERSION logger = logging.getLogger("s2python") @@ -73,8 +73,8 @@ def to_resource_manager_details( S2MessageHandler = Union[ - Callable[["S2Connection", S2Message, Callable[[], None]], None], - Callable[["S2Connection", S2Message, Awaitable[None]], Awaitable[None]], + Callable[["S2Connection", S2MessageComponent, Callable[[], None]], None], + Callable[["S2Connection", S2MessageComponent, Awaitable[None]], Awaitable[None]], ] @@ -106,7 +106,7 @@ def run_sync(self) -> None: diagnostic_label="Processed okay.", ) - async def ensure_send_async(self, type_msg: Type[S2Message]) -> None: + async def ensure_send_async(self, type_msg: Type[S2MessageComponent]) -> None: if not self.status_is_send.is_set(): logger.warning( "Handler for message %s %s did not call send_okay / function to send the ReceptionStatus. " @@ -116,7 +116,7 @@ async def ensure_send_async(self, type_msg: Type[S2Message]) -> None: ) await self.run_async() - def ensure_send_sync(self, type_msg: Type[S2Message]) -> None: + def ensure_send_sync(self, type_msg: Type[S2MessageComponent]) -> None: if not self.status_is_send.is_set(): logger.warning( "Handler for message %s %s did not call send_okay / function to send the ReceptionStatus. " @@ -128,12 +128,12 @@ def ensure_send_sync(self, type_msg: Type[S2Message]) -> None: class MessageHandlers: - handlers: Dict[Type[S2Message], S2MessageHandler] + handlers: Dict[Type[S2MessageComponent], S2MessageHandler] def __init__(self) -> None: self.handlers = {} - async def handle_message(self, connection: "S2Connection", msg: S2Message) -> None: + async def handle_message(self, connection: "S2Connection", msg: S2MessageComponent) -> None: """Handle the S2 message using the registered handler. :param connection: The S2 conncetion the `msg` is received from. @@ -170,7 +170,7 @@ def do_message() -> None: type(msg), ) - def register_handler(self, msg_type: Type[S2Message], handler: S2MessageHandler) -> None: + def register_handler(self, msg_type: Type[S2MessageComponent], handler: S2MessageHandler) -> None: """Register a coroutine function or a normal function as the handler for a specific S2 message type. :param msg_type: The S2 message type to attach the handler to. @@ -334,7 +334,7 @@ async def _connect_as_rm(self) -> None: await self._handle_received_messages() async def handle_handshake( - self, _: "S2Connection", message: S2Message, send_okay: Awaitable[None] + self, _: "S2Connection", message: S2MessageComponent, send_okay: Awaitable[None] ) -> None: if not isinstance(message, Handshake): logger.error( @@ -350,7 +350,7 @@ async def handle_handshake( await send_okay async def handle_handshake_response_as_rm( - self, _: "S2Connection", message: S2Message, send_okay: Awaitable[None] + self, _: "S2Connection", message: S2MessageComponent, send_okay: Awaitable[None] ) -> None: if not isinstance(message, HandshakeResponse): logger.error( @@ -370,7 +370,7 @@ async def handle_handshake_response_as_rm( ) async def handle_select_control_type_as_rm( - self, _: "S2Connection", message: S2Message, send_okay: Awaitable[None] + self, _: "S2Connection", message: S2MessageComponent, send_okay: Awaitable[None] ) -> None: if not isinstance(message, SelectControlType): logger.error( @@ -414,7 +414,7 @@ async def _receive_messages(self) -> None: async for message in self.ws: try: - s2_msg: S2Message = self.s2_parser.parse_as_any_message(message) + s2_msg: S2MessageComponent = self.s2_parser.parse_as_any_message(message) except json.JSONDecodeError: await self._send_and_forget( ReceptionStatus( @@ -450,7 +450,7 @@ async def _receive_messages(self) -> None: else: await self._received_messages.put(s2_msg) - async def _send_and_forget(self, s2_msg: S2Message) -> None: + async def _send_and_forget(self, s2_msg: S2MessageComponent) -> None: if self.ws is None: raise RuntimeError( "Cannot send messages if websocket connection is not yet established." @@ -485,7 +485,7 @@ def respond_with_reception_status_sync( ).result() async def send_msg_and_await_reception_status_async( - self, s2_msg: S2Message, timeout_reception_status: float = 5.0, raise_on_error: bool = True + self, s2_msg: S2MessageComponent, timeout_reception_status: float = 5.0, raise_on_error: bool = True ) -> ReceptionStatus: await self._send_and_forget(s2_msg) logger.debug( @@ -511,7 +511,7 @@ async def send_msg_and_await_reception_status_async( return reception_status def send_msg_and_await_reception_status_sync( - self, s2_msg: S2Message, timeout_reception_status: float = 5.0, raise_on_error: bool = True + self, s2_msg: S2MessageComponent, timeout_reception_status: float = 5.0, raise_on_error: bool = True ) -> ReceptionStatus: return asyncio.run_coroutine_threadsafe( self.send_msg_and_await_reception_status_async( diff --git a/src/s2python/s2_control_type.py b/src/s2python/s2_control_type.py index 982c9be..39d30c5 100644 --- a/src/s2python/s2_control_type.py +++ b/src/s2python/s2_control_type.py @@ -4,7 +4,7 @@ from s2python.common import ControlType as ProtocolControlType from s2python.frbc import FRBCInstruction from s2python.ppbc import PPBCScheduleInstruction -from s2python.message import S2Message +from s2python.validate_values_mixin import S2MessageComponent if typing.TYPE_CHECKING: from s2python.s2_connection import S2Connection, MessageHandlers @@ -33,7 +33,7 @@ def register_handlers(self, handlers: "MessageHandlers") -> None: @abc.abstractmethod def handle_instruction( - self, conn: "S2Connection", msg: S2Message, send_okay: typing.Callable[[], None] + self, conn: "S2Connection", msg: S2MessageComponent, send_okay: typing.Callable[[], None] ) -> None: ... @abc.abstractmethod @@ -54,7 +54,7 @@ def register_handlers(self, handlers: "MessageHandlers") -> None: @abc.abstractmethod def handle_instruction( - self, conn: "S2Connection", msg: S2Message, send_okay: typing.Callable[[], None] + self, conn: "S2Connection", msg: S2MessageComponent, send_okay: typing.Callable[[], None] ) -> None: ... @abc.abstractmethod diff --git a/src/s2python/s2_parser.py b/src/s2python/s2_parser.py index 642843f..84d720f 100644 --- a/src/s2python/s2_parser.py +++ b/src/s2python/s2_parser.py @@ -26,18 +26,18 @@ ) from s2python.ppbc import PPBCScheduleInstruction -from s2python.message import S2Message +from s2python.validate_values_mixin import S2MessageComponent from s2python.s2_validation_error import S2ValidationError LOGGER = logging.getLogger(__name__) S2MessageType = str -M = TypeVar("M", bound=S2Message) +M = TypeVar("M", bound=S2MessageComponent) # May be generated with development_utilities/generate_s2_message_type_to_class.py -TYPE_TO_MESSAGE_CLASS: Dict[str, Type[S2Message]] = { +TYPE_TO_MESSAGE_CLASS: Dict[str, Type[S2MessageComponent]] = { "FRBC.ActuatorStatus": FRBCActuatorStatus, "FRBC.FillLevelTargetProfile": FRBCFillLevelTargetProfile, "FRBC.Instruction": FRBCInstruction, @@ -68,7 +68,7 @@ def _parse_json_if_required(unparsed_message: Union[dict, str, bytes]) -> dict: return unparsed_message @staticmethod - def parse_as_any_message(unparsed_message: Union[dict, str, bytes]) -> S2Message: + def parse_as_any_message(unparsed_message: Union[dict, str, bytes]) -> S2MessageComponent: """Parse the message as any S2 python message regardless of message type. :param unparsed_message: The message as a JSON-formatted string or as a json-parsed dictionary. From 87a4ca63a22f760a97e13e13852878d3fecef2c5 Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Thu, 16 Jan 2025 10:49:53 +0100 Subject: [PATCH 08/16] refactor: prefer S2Message over S2MessageComponent in s2_parser.py Signed-off-by: F.N. Claessen --- src/s2python/s2_parser.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/s2python/s2_parser.py b/src/s2python/s2_parser.py index 84d720f..642843f 100644 --- a/src/s2python/s2_parser.py +++ b/src/s2python/s2_parser.py @@ -26,18 +26,18 @@ ) from s2python.ppbc import PPBCScheduleInstruction -from s2python.validate_values_mixin import S2MessageComponent +from s2python.message import S2Message from s2python.s2_validation_error import S2ValidationError LOGGER = logging.getLogger(__name__) S2MessageType = str -M = TypeVar("M", bound=S2MessageComponent) +M = TypeVar("M", bound=S2Message) # May be generated with development_utilities/generate_s2_message_type_to_class.py -TYPE_TO_MESSAGE_CLASS: Dict[str, Type[S2MessageComponent]] = { +TYPE_TO_MESSAGE_CLASS: Dict[str, Type[S2Message]] = { "FRBC.ActuatorStatus": FRBCActuatorStatus, "FRBC.FillLevelTargetProfile": FRBCFillLevelTargetProfile, "FRBC.Instruction": FRBCInstruction, @@ -68,7 +68,7 @@ def _parse_json_if_required(unparsed_message: Union[dict, str, bytes]) -> dict: return unparsed_message @staticmethod - def parse_as_any_message(unparsed_message: Union[dict, str, bytes]) -> S2MessageComponent: + def parse_as_any_message(unparsed_message: Union[dict, str, bytes]) -> S2Message: """Parse the message as any S2 python message regardless of message type. :param unparsed_message: The message as a JSON-formatted string or as a json-parsed dictionary. From 112e78fc7d1bbd0748e9f1765326a73dfe61cdc1 Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Thu, 16 Jan 2025 10:50:33 +0100 Subject: [PATCH 09/16] fix: `src/s2python/s2_parser.py:49: error: Dict entry 8 has incompatible type "str": "type[PPBCScheduleInstruction]"; expected "str": "Union[type[FRBCActuatorStatus], type[FRBCFillLevelTargetProfile], type[FRBCInstruction], type[FRBCLeakageBehaviour], type[FRBCStorageStatus], <13 more items>]" [dict-item]` Signed-off-by: F.N. Claessen --- src/s2python/message.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/s2python/message.py b/src/s2python/message.py index 071d16f..aafc009 100644 --- a/src/s2python/message.py +++ b/src/s2python/message.py @@ -10,6 +10,9 @@ FRBCTimerStatus, FRBCUsageForecast ) +from s2python.ppbc import ( + PPBCScheduleInstruction, +) from s2python.common import ( Handshake, @@ -33,6 +36,7 @@ FRBCSystemDescription, FRBCTimerStatus, FRBCUsageForecast, + PPBCScheduleInstruction, Handshake, HandshakeResponse, InstructionStatusUpdate, From 828309f22647cb564d26cdc86057e13371dbc954 Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Thu, 16 Jan 2025 10:52:29 +0100 Subject: [PATCH 10/16] refactor: prefer S2Message over S2MessageComponent in s2_control_type.py Signed-off-by: F.N. Claessen --- src/s2python/s2_control_type.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/s2python/s2_control_type.py b/src/s2python/s2_control_type.py index 39d30c5..982c9be 100644 --- a/src/s2python/s2_control_type.py +++ b/src/s2python/s2_control_type.py @@ -4,7 +4,7 @@ from s2python.common import ControlType as ProtocolControlType from s2python.frbc import FRBCInstruction from s2python.ppbc import PPBCScheduleInstruction -from s2python.validate_values_mixin import S2MessageComponent +from s2python.message import S2Message if typing.TYPE_CHECKING: from s2python.s2_connection import S2Connection, MessageHandlers @@ -33,7 +33,7 @@ def register_handlers(self, handlers: "MessageHandlers") -> None: @abc.abstractmethod def handle_instruction( - self, conn: "S2Connection", msg: S2MessageComponent, send_okay: typing.Callable[[], None] + self, conn: "S2Connection", msg: S2Message, send_okay: typing.Callable[[], None] ) -> None: ... @abc.abstractmethod @@ -54,7 +54,7 @@ def register_handlers(self, handlers: "MessageHandlers") -> None: @abc.abstractmethod def handle_instruction( - self, conn: "S2Connection", msg: S2MessageComponent, send_okay: typing.Callable[[], None] + self, conn: "S2Connection", msg: S2Message, send_okay: typing.Callable[[], None] ) -> None: ... @abc.abstractmethod From 82dab119edd6badbc8b5730bd60af114f98dda69 Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Thu, 23 Jan 2025 11:47:39 +0100 Subject: [PATCH 11/16] refactor: prefer S2Message over S2MessageComponent in s2_connection.py Signed-off-by: F.N. Claessen --- src/s2python/s2_connection.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/s2python/s2_connection.py b/src/s2python/s2_connection.py index eeb96bc..1dab4cb 100644 --- a/src/s2python/s2_connection.py +++ b/src/s2python/s2_connection.py @@ -27,7 +27,7 @@ from s2python.s2_control_type import S2ControlType from s2python.s2_parser import S2Parser from s2python.s2_validation_error import S2ValidationError -from s2python.validate_values_mixin import S2MessageComponent +from s2python.message import S2Message from s2python.version import S2_VERSION logger = logging.getLogger("s2python") @@ -73,8 +73,8 @@ def to_resource_manager_details( S2MessageHandler = Union[ - Callable[["S2Connection", S2MessageComponent, Callable[[], None]], None], - Callable[["S2Connection", S2MessageComponent, Awaitable[None]], Awaitable[None]], + Callable[["S2Connection", S2Message, Callable[[], None]], None], + Callable[["S2Connection", S2Message, Awaitable[None]], Awaitable[None]], ] @@ -106,7 +106,7 @@ def run_sync(self) -> None: diagnostic_label="Processed okay.", ) - async def ensure_send_async(self, type_msg: Type[S2MessageComponent]) -> None: + async def ensure_send_async(self, type_msg: Type[S2Message]) -> None: if not self.status_is_send.is_set(): logger.warning( "Handler for message %s %s did not call send_okay / function to send the ReceptionStatus. " @@ -116,7 +116,7 @@ async def ensure_send_async(self, type_msg: Type[S2MessageComponent]) -> None: ) await self.run_async() - def ensure_send_sync(self, type_msg: Type[S2MessageComponent]) -> None: + def ensure_send_sync(self, type_msg: Type[S2Message]) -> None: if not self.status_is_send.is_set(): logger.warning( "Handler for message %s %s did not call send_okay / function to send the ReceptionStatus. " @@ -128,12 +128,12 @@ def ensure_send_sync(self, type_msg: Type[S2MessageComponent]) -> None: class MessageHandlers: - handlers: Dict[Type[S2MessageComponent], S2MessageHandler] + handlers: Dict[Type[S2Message], S2MessageHandler] def __init__(self) -> None: self.handlers = {} - async def handle_message(self, connection: "S2Connection", msg: S2MessageComponent) -> None: + async def handle_message(self, connection: "S2Connection", msg: S2Message) -> None: """Handle the S2 message using the registered handler. :param connection: The S2 conncetion the `msg` is received from. @@ -170,7 +170,7 @@ def do_message() -> None: type(msg), ) - def register_handler(self, msg_type: Type[S2MessageComponent], handler: S2MessageHandler) -> None: + def register_handler(self, msg_type: Type[S2Message], handler: S2MessageHandler) -> None: """Register a coroutine function or a normal function as the handler for a specific S2 message type. :param msg_type: The S2 message type to attach the handler to. @@ -334,7 +334,7 @@ async def _connect_as_rm(self) -> None: await self._handle_received_messages() async def handle_handshake( - self, _: "S2Connection", message: S2MessageComponent, send_okay: Awaitable[None] + self, _: "S2Connection", message: S2Message, send_okay: Awaitable[None] ) -> None: if not isinstance(message, Handshake): logger.error( @@ -350,7 +350,7 @@ async def handle_handshake( await send_okay async def handle_handshake_response_as_rm( - self, _: "S2Connection", message: S2MessageComponent, send_okay: Awaitable[None] + self, _: "S2Connection", message: S2Message, send_okay: Awaitable[None] ) -> None: if not isinstance(message, HandshakeResponse): logger.error( @@ -370,7 +370,7 @@ async def handle_handshake_response_as_rm( ) async def handle_select_control_type_as_rm( - self, _: "S2Connection", message: S2MessageComponent, send_okay: Awaitable[None] + self, _: "S2Connection", message: S2Message, send_okay: Awaitable[None] ) -> None: if not isinstance(message, SelectControlType): logger.error( @@ -414,7 +414,7 @@ async def _receive_messages(self) -> None: async for message in self.ws: try: - s2_msg: S2MessageComponent = self.s2_parser.parse_as_any_message(message) + s2_msg: S2Message = self.s2_parser.parse_as_any_message(message) except json.JSONDecodeError: await self._send_and_forget( ReceptionStatus( @@ -450,7 +450,7 @@ async def _receive_messages(self) -> None: else: await self._received_messages.put(s2_msg) - async def _send_and_forget(self, s2_msg: S2MessageComponent) -> None: + async def _send_and_forget(self, s2_msg: S2Message) -> None: if self.ws is None: raise RuntimeError( "Cannot send messages if websocket connection is not yet established." @@ -485,7 +485,7 @@ def respond_with_reception_status_sync( ).result() async def send_msg_and_await_reception_status_async( - self, s2_msg: S2MessageComponent, timeout_reception_status: float = 5.0, raise_on_error: bool = True + self, s2_msg: S2Message, timeout_reception_status: float = 5.0, raise_on_error: bool = True ) -> ReceptionStatus: await self._send_and_forget(s2_msg) logger.debug( @@ -511,7 +511,7 @@ async def send_msg_and_await_reception_status_async( return reception_status def send_msg_and_await_reception_status_sync( - self, s2_msg: S2MessageComponent, timeout_reception_status: float = 5.0, raise_on_error: bool = True + self, s2_msg: S2Message, timeout_reception_status: float = 5.0, raise_on_error: bool = True ) -> ReceptionStatus: return asyncio.run_coroutine_threadsafe( self.send_msg_and_await_reception_status_async( From 76a76ac3702a953a088d0c5411a3275fe0198dad Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Thu, 23 Jan 2025 11:48:02 +0100 Subject: [PATCH 12/16] fix: s2_parser.py has 1 place that still requires the S2MessageComponent Signed-off-by: F.N. Claessen --- src/s2python/s2_parser.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/s2python/s2_parser.py b/src/s2python/s2_parser.py index 642843f..403503f 100644 --- a/src/s2python/s2_parser.py +++ b/src/s2python/s2_parser.py @@ -27,13 +27,14 @@ from s2python.ppbc import PPBCScheduleInstruction from s2python.message import S2Message +from s2python.validate_values_mixin import S2MessageComponent from s2python.s2_validation_error import S2ValidationError LOGGER = logging.getLogger(__name__) S2MessageType = str -M = TypeVar("M", bound=S2Message) +M = TypeVar("M", bound=S2MessageComponent) # May be generated with development_utilities/generate_s2_message_type_to_class.py From dc3d7064d8d9b35f48a503f5b3b903b57bdf0b40 Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Thu, 23 Jan 2025 11:48:45 +0100 Subject: [PATCH 13/16] dev: change subject_message_id to message_id (did mypy find a bug? Related to https://github.com/flexiblepower/s2-ws-json/issues/21) Signed-off-by: F.N. Claessen --- specification/openapi.yml | 4 ++-- src/s2python/common/reception_status.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/specification/openapi.yml b/specification/openapi.yml index 64c932e..3203a9b 100644 --- a/specification/openapi.yml +++ b/specification/openapi.yml @@ -1002,13 +1002,13 @@ components: type: object required: - message_type - - subject_message_id + - message_id - status properties: message_type: const: ReceptionStatus type: string - subject_message_id: + message_id: $ref: '#/components/schemas/ID' description: "The message this ReceptionStatus refers to" status: diff --git a/src/s2python/common/reception_status.py b/src/s2python/common/reception_status.py index edae59c..dd7c3a1 100644 --- a/src/s2python/common/reception_status.py +++ b/src/s2python/common/reception_status.py @@ -12,4 +12,4 @@ class ReceptionStatus(GenReceptionStatus, S2MessageComponent["ReceptionStatus"]) model_config = GenReceptionStatus.model_config model_config["validate_assignment"] = True - subject_message_id: uuid.UUID = GenReceptionStatus.model_fields["subject_message_id"] # type: ignore[assignment] + message_id: uuid.UUID = GenReceptionStatus.model_fields["message_id"] # type: ignore[assignment] From f10e708fddd2ea9c096009defe801b64e736119d Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Thu, 23 Jan 2025 11:49:03 +0100 Subject: [PATCH 14/16] Revert "dev: change subject_message_id to message_id (did mypy find a bug? Related to https://github.com/flexiblepower/s2-ws-json/issues/21)" This reverts commit dc3d7064d8d9b35f48a503f5b3b903b57bdf0b40. --- specification/openapi.yml | 4 ++-- src/s2python/common/reception_status.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/specification/openapi.yml b/specification/openapi.yml index 3203a9b..64c932e 100644 --- a/specification/openapi.yml +++ b/specification/openapi.yml @@ -1002,13 +1002,13 @@ components: type: object required: - message_type - - message_id + - subject_message_id - status properties: message_type: const: ReceptionStatus type: string - message_id: + subject_message_id: $ref: '#/components/schemas/ID' description: "The message this ReceptionStatus refers to" status: diff --git a/src/s2python/common/reception_status.py b/src/s2python/common/reception_status.py index dd7c3a1..edae59c 100644 --- a/src/s2python/common/reception_status.py +++ b/src/s2python/common/reception_status.py @@ -12,4 +12,4 @@ class ReceptionStatus(GenReceptionStatus, S2MessageComponent["ReceptionStatus"]) model_config = GenReceptionStatus.model_config model_config["validate_assignment"] = True - message_id: uuid.UUID = GenReceptionStatus.model_fields["message_id"] # type: ignore[assignment] + subject_message_id: uuid.UUID = GenReceptionStatus.model_fields["subject_message_id"] # type: ignore[assignment] From ad87e8bc33ed29bca6800f32bbec35ad0d6d6e9f Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Thu, 23 Jan 2025 11:53:47 +0100 Subject: [PATCH 15/16] fix: type ignore union-attr instead; underlying issue should be fixed under https://github.com/flexiblepower/s2-ws-json/issues/21 instead Signed-off-by: F.N. Claessen --- src/s2python/s2_connection.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/s2python/s2_connection.py b/src/s2python/s2_connection.py index 1dab4cb..a3f5c2d 100644 --- a/src/s2python/s2_connection.py +++ b/src/s2python/s2_connection.py @@ -141,7 +141,7 @@ async def handle_message(self, connection: "S2Connection", msg: S2Message) -> No """ handler = self.handlers.get(type(msg)) if handler is not None: - send_okay = SendOkay(connection, msg.message_id) # type: ignore[attr-defined] + send_okay = SendOkay(connection, msg.message_id) # type: ignore[attr-defined, union-attr] try: if asyncio.iscoroutinefunction(handler): @@ -158,9 +158,9 @@ def do_message() -> None: except Exception: if not send_okay.status_is_send.is_set(): await connection.respond_with_reception_status( - subject_message_id=str(msg.message_id), # type: ignore[attr-defined] + subject_message_id=str(msg.message_id), # type: ignore[attr-defined, union-attr] status=ReceptionStatusValues.PERMANENT_ERROR, - diagnostic_label=f"While processing message {msg.message_id} " # type: ignore[attr-defined] + diagnostic_label=f"While processing message {msg.message_id} " # type: ignore[attr-defined, union-attr] f"an unrecoverable error occurred.", ) raise @@ -490,17 +490,17 @@ async def send_msg_and_await_reception_status_async( await self._send_and_forget(s2_msg) logger.debug( "Waiting for ReceptionStatus for %s %s seconds", - s2_msg.message_id, # type: ignore[attr-defined] + s2_msg.message_id, # type: ignore[attr-defined, union-attr] timeout_reception_status, ) try: reception_status = await self.reception_status_awaiter.wait_for_reception_status( - s2_msg.message_id, timeout_reception_status # type: ignore[attr-defined] + s2_msg.message_id, timeout_reception_status # type: ignore[attr-defined, union-attr] ) except TimeoutError: logger.error( "Did not receive a reception status on time for %s", - s2_msg.message_id, # type: ignore[attr-defined] + s2_msg.message_id, # type: ignore[attr-defined, union-attr] ) self._stop_event.set() raise From 3f31f1692c7e3cdb4c622836e38e284f6aaae1d5 Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Thu, 23 Jan 2025 11:58:43 +0100 Subject: [PATCH 16/16] fix: linting Signed-off-by: F.N. Claessen --- src/s2python/s2_connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/s2python/s2_connection.py b/src/s2python/s2_connection.py index a3f5c2d..5864203 100644 --- a/src/s2python/s2_connection.py +++ b/src/s2python/s2_connection.py @@ -160,7 +160,7 @@ def do_message() -> None: await connection.respond_with_reception_status( subject_message_id=str(msg.message_id), # type: ignore[attr-defined, union-attr] status=ReceptionStatusValues.PERMANENT_ERROR, - diagnostic_label=f"While processing message {msg.message_id} " # type: ignore[attr-defined, union-attr] + diagnostic_label=f"While processing message {msg.message_id} " # type: ignore[attr-defined, union-attr] # pylint: disable=line-too-long f"an unrecoverable error occurred.", ) raise