From 514504d227a06e78953a70532770c2ac3e698f68 Mon Sep 17 00:00:00 2001 From: Dr Maurice Hendrix Date: Mon, 3 Mar 2025 09:15:54 +0100 Subject: [PATCH 1/4] Update ci.yml (#82) updated artifacts to v4 due to github giving depracation errors en not running pipeline --- .github/workflows/ci.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf4e441..7ca3906 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,7 @@ jobs: outputs: wheel-distribution: ${{ steps.wheel-distribution.outputs.path }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: {fetch-depth: 0} # deep clone for setuptools-scm - uses: actions/setup-python@v4 id: setup-python @@ -46,7 +46,7 @@ jobs: - name: Store the distribution files for use in other stages # `tests` and `publish` will use the same pre-built distributions, # so we make sure to release the exact same package that was tested - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: python-distribution-files path: dist/ @@ -68,13 +68,13 @@ jobs: # - windows-latest runs-on: ${{ matrix.platform }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v4 id: setup-python with: python-version: ${{ matrix.python }} - name: Retrieve pre-built distribution files - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: {name: python-distribution-files, path: dist/} - name: Run tests run: >- @@ -107,13 +107,13 @@ jobs: # - windows-latest runs-on: ${{ matrix.platform }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v4 id: setup-python with: python-version: ${{ matrix.python }} - name: Retrieve pre-built distribution files - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: {name: python-distribution-files, path: dist/} - name: Run tests run: >- @@ -136,13 +136,13 @@ jobs: # - windows-latest runs-on: ${{ matrix.platform }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v4 id: setup-python with: python-version: ${{ matrix.python }} - name: Retrieve pre-built distribution files - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: {name: python-distribution-files, path: dist/} - name: Run tests run: >- @@ -165,11 +165,11 @@ jobs: permissions: id-token: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v4 with: {python-version: "3.11"} - name: Retrieve pre-built distribution files - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: {name: python-distribution-files, path: dist/} - name: Publish Package uses: pypa/gh-action-pypi-publish@release/v1 @@ -185,11 +185,11 @@ jobs: permissions: id-token: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v4 with: {python-version: "3.11"} - name: Retrieve pre-built distribution files - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: {name: python-distribution-files, path: dist/} - name: Publish Package uses: pypa/gh-action-pypi-publish@release/v1 From 793086251db2f711e5beeed8796f66d04d022b72 Mon Sep 17 00:00:00 2001 From: Dr Maurice Hendrix Date: Mon, 3 Mar 2025 09:17:29 +0100 Subject: [PATCH 2/4] fix moved message import in frbc example (#81) * fix moved message import in frbc example * Update ci.yml updated artifacts to v4 due to github giving depracation errors en not running pipeline --- examples/example_frbc_rm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/example_frbc_rm.py b/examples/example_frbc_rm.py index 53b80df..774d936 100644 --- a/examples/example_frbc_rm.py +++ b/examples/example_frbc_rm.py @@ -30,7 +30,7 @@ ) from s2python.s2_connection import S2Connection, AssetDetails from s2python.s2_control_type import FRBCControlType, NoControlControlType -from s2python.validate_values_mixin import S2Message +from s2python.message import S2Message logger = logging.getLogger("s2python") logger.addHandler(logging.StreamHandler(sys.stdout)) From 4adc556deeabee232177e480b1bb3460a5dd32dd Mon Sep 17 00:00:00 2001 From: VladIftime <49650168+VladIftime@users.noreply.github.com> Date: Mon, 3 Mar 2025 10:22:03 +0100 Subject: [PATCH 3/4] DDBC skeleton class implementation (#69) * Add DDBC actuator and operation mode classes * Add DDBC operation mode and actuator status classes * Add additional DDBC classes to the initialization module * Refactor DDBC classes for improved readability and consistency * Refactor gen_s2.py and fix cyclic import * Added the controll type to s2_control_type wrapper * Fixed the new type of S2Message as union Signed-off-by: Vlad Iftime * Fixed lines too long Signed-off-by: Vlad Iftime --------- Signed-off-by: Vlad Iftime --- src/s2python/ddbc/__init__.py | 12 ++++++++ .../ddbc/ddbc_actuator_description.py | 30 +++++++++++++++++++ src/s2python/ddbc/ddbc_actuator_status.py | 22 ++++++++++++++ .../ddbc/ddbc_average_demand_rate_forecast.py | 30 +++++++++++++++++++ ...bc_average_demand_rate_forecast_element.py | 21 +++++++++++++ src/s2python/ddbc/ddbc_instruction.py | 19 ++++++++++++ src/s2python/ddbc/ddbc_operation_mode.py | 26 ++++++++++++++++ src/s2python/ddbc/ddbc_system_description.py | 29 ++++++++++++++++++ src/s2python/ddbc/ddbc_timer_status.py | 18 +++++++++++ src/s2python/s2_control_type.py | 14 +++++++++ 10 files changed, 221 insertions(+) create mode 100644 src/s2python/ddbc/__init__.py create mode 100644 src/s2python/ddbc/ddbc_actuator_description.py create mode 100644 src/s2python/ddbc/ddbc_actuator_status.py create mode 100644 src/s2python/ddbc/ddbc_average_demand_rate_forecast.py create mode 100644 src/s2python/ddbc/ddbc_average_demand_rate_forecast_element.py create mode 100644 src/s2python/ddbc/ddbc_instruction.py create mode 100644 src/s2python/ddbc/ddbc_operation_mode.py create mode 100644 src/s2python/ddbc/ddbc_system_description.py create mode 100644 src/s2python/ddbc/ddbc_timer_status.py diff --git a/src/s2python/ddbc/__init__.py b/src/s2python/ddbc/__init__.py new file mode 100644 index 0000000..efc12b8 --- /dev/null +++ b/src/s2python/ddbc/__init__.py @@ -0,0 +1,12 @@ +from s2python.ddbc.ddbc_actuator_description import DDBCActuatorDescription +from s2python.ddbc.ddbc_operation_mode import DDBCOperationMode +from s2python.ddbc.ddbc_instruction import DDBCInstruction +from s2python.ddbc.ddbc_actuator_status import DDBCActuatorStatus +from s2python.ddbc.ddbc_average_demand_rate_forecast_element import ( + DDBCAverageDemandRateForecastElement, +) +from s2python.ddbc.ddbc_average_demand_rate_forecast import ( + DDBCAverageDemandRateForecast, +) +from s2python.ddbc.ddbc_system_description import DDBCSystemDescription +from s2python.ddbc.ddbc_timer_status import DDBCTimerStatus diff --git a/src/s2python/ddbc/ddbc_actuator_description.py b/src/s2python/ddbc/ddbc_actuator_description.py new file mode 100644 index 0000000..4bd4b8b --- /dev/null +++ b/src/s2python/ddbc/ddbc_actuator_description.py @@ -0,0 +1,30 @@ +from typing import List +import uuid + +from s2python.generated.gen_s2 import ( + DDBCActuatorDescription as GenDDBCActuatorDescription, +) +from s2python.generated.gen_s2 import Commodity +from s2python.ddbc.ddbc_operation_mode import DDBCOperationMode + +from s2python.common.timer import Timer + +from s2python.validate_values_mixin import ( + catch_and_convert_exceptions, + S2MessageComponent, +) + + +@catch_and_convert_exceptions +class DDBCActuatorDescription(GenDDBCActuatorDescription, S2MessageComponent["DDBCActuatorDescription"]): + model_config = GenDDBCActuatorDescription.model_config + model_config["validate_assignment"] = True + + id: uuid.UUID = GenDDBCActuatorDescription.model_fields["id"] # type: ignore[assignment] + supported_commodites: List[Commodity] = GenDDBCActuatorDescription.model_fields[ + "supported_commodites" + ] # type: ignore[assignment] + timers: List[Timer] = GenDDBCActuatorDescription.model_fields["timers"] # type: ignore[assignment] + operation_modes: List[DDBCOperationMode] = GenDDBCActuatorDescription.model_fields[ + "operation_modes" + ] # type: ignore[assignment] diff --git a/src/s2python/ddbc/ddbc_actuator_status.py b/src/s2python/ddbc/ddbc_actuator_status.py new file mode 100644 index 0000000..19b457b --- /dev/null +++ b/src/s2python/ddbc/ddbc_actuator_status.py @@ -0,0 +1,22 @@ +import uuid + +from s2python.generated.gen_s2 import DDBCActuatorStatus as GenDDBCActuatorStatus +from s2python.validate_values_mixin import ( + catch_and_convert_exceptions, + S2MessageComponent, +) + + +@catch_and_convert_exceptions +class DDBCActuatorStatus(GenDDBCActuatorStatus, S2MessageComponent["DDBCActuatorStatus"]): + model_config = GenDDBCActuatorStatus.model_config + model_config["validate_assignment"] = True + + message_id: uuid.UUID = GenDDBCActuatorStatus.model_fields["message_id"] # type: ignore[assignment] + actuator_id: uuid.UUID = GenDDBCActuatorStatus.model_fields["actuator_id"] # type: ignore[assignment] + active_operation_mode_id: uuid.UUID = GenDDBCActuatorStatus.model_fields[ + "active_operation_mode_id" + ] # type: ignore[assignment] + operation_mode_factor: float = GenDDBCActuatorStatus.model_fields[ + "operation_mode_factor" + ] # type: ignore[assignment] diff --git a/src/s2python/ddbc/ddbc_average_demand_rate_forecast.py b/src/s2python/ddbc/ddbc_average_demand_rate_forecast.py new file mode 100644 index 0000000..c265b72 --- /dev/null +++ b/src/s2python/ddbc/ddbc_average_demand_rate_forecast.py @@ -0,0 +1,30 @@ +from typing import List +import uuid + +from s2python.generated.gen_s2 import ( + DDBCAverageDemandRateForecast as GenDDBCAverageDemandRateForecast, +) +from s2python.ddbc.ddbc_average_demand_rate_forecast_element import ( + DDBCAverageDemandRateForecastElement, +) + +from s2python.validate_values_mixin import ( + catch_and_convert_exceptions, + S2MessageComponent, +) + + +@catch_and_convert_exceptions +class DDBCAverageDemandRateForecast( + GenDDBCAverageDemandRateForecast, + S2MessageComponent["DDBCAverageDemandRateForecast"], +): + model_config = GenDDBCAverageDemandRateForecast.model_config + model_config["validate_assignment"] = True + + message_id: uuid.UUID = GenDDBCAverageDemandRateForecast.model_fields["message_id"] # type: ignore[assignment] + elements: List[ + DDBCAverageDemandRateForecastElement + ] = GenDDBCAverageDemandRateForecast.model_fields[ + "elements" + ] # type: ignore[assignment] diff --git a/src/s2python/ddbc/ddbc_average_demand_rate_forecast_element.py b/src/s2python/ddbc/ddbc_average_demand_rate_forecast_element.py new file mode 100644 index 0000000..4768e1a --- /dev/null +++ b/src/s2python/ddbc/ddbc_average_demand_rate_forecast_element.py @@ -0,0 +1,21 @@ +from s2python.generated.gen_s2 import Duration + +from s2python.generated.gen_s2 import ( + DDBCAverageDemandRateForecastElement as GenDDBCAverageDemandRateForecastElement, +) + +from s2python.validate_values_mixin import catch_and_convert_exceptions, S2MessageComponent + + +@catch_and_convert_exceptions +class DDBCAverageDemandRateForecastElement( + GenDDBCAverageDemandRateForecastElement, + S2MessageComponent["DDBCAverageDemandRateForecastElement"], +): + model_config = GenDDBCAverageDemandRateForecastElement.model_config + model_config["validate_assignment"] = True + + duration: Duration = GenDDBCAverageDemandRateForecastElement.model_fields["duration"] # type: ignore[assignment] + demand_rate_expected: float = GenDDBCAverageDemandRateForecastElement.model_fields[ + "demand_rate_expected" + ] # type: ignore[assignment] diff --git a/src/s2python/ddbc/ddbc_instruction.py b/src/s2python/ddbc/ddbc_instruction.py new file mode 100644 index 0000000..0bfb867 --- /dev/null +++ b/src/s2python/ddbc/ddbc_instruction.py @@ -0,0 +1,19 @@ +import uuid + +from s2python.generated.gen_s2 import DDBCInstruction as GenDDBCInstruction +from s2python.validate_values_mixin import ( + catch_and_convert_exceptions, + S2MessageComponent, +) + + +@catch_and_convert_exceptions +class DDBCInstruction(GenDDBCInstruction, S2MessageComponent["DDBCInstruction"]): + model_config = GenDDBCInstruction.model_config + model_config["validate_assignment"] = True + + message_id: uuid.UUID = GenDDBCInstruction.model_fields["message_id"] # type: ignore[assignment] + actuator_id: uuid.UUID = GenDDBCInstruction.model_fields["actuator_id"] # type: ignore[assignment] + operation_mode_id: uuid.UUID = GenDDBCInstruction.model_fields["operation_mode_id"] # type: ignore[assignment] + operation_mode_factor: float = GenDDBCInstruction.model_fields["operation_mode_factor"] # type: ignore[assignment] + abnormal_condition: bool = GenDDBCInstruction.model_fields["abnormal_condition"] # type: ignore[assignment] diff --git a/src/s2python/ddbc/ddbc_operation_mode.py b/src/s2python/ddbc/ddbc_operation_mode.py new file mode 100644 index 0000000..7a2ebe2 --- /dev/null +++ b/src/s2python/ddbc/ddbc_operation_mode.py @@ -0,0 +1,26 @@ +from typing import List +import uuid + +from s2python.generated.gen_s2 import DDBCOperationMode as GenDDBCOperationMode + +from s2python.common.power_range import PowerRange +from s2python.common.number_range import NumberRange + +from s2python.validate_values_mixin import ( + catch_and_convert_exceptions, + S2MessageComponent, +) + + +@catch_and_convert_exceptions +class DDBCOperationMode(GenDDBCOperationMode, S2MessageComponent["DDBCOperationMode"]): + model_config = GenDDBCOperationMode.model_config + model_config["validate_assignment"] = True + + # ? Id vs id + id: uuid.UUID = GenDDBCOperationMode.model_fields["Id"] # type: ignore[assignment] + power_ranges: List[PowerRange] = GenDDBCOperationMode.model_fields["power_ranges"] # type: ignore[assignment] + supply_ranges: List[NumberRange] = GenDDBCOperationMode.model_fields["supply_ranges"] # type: ignore[assignment] + abnormal_condition_only: bool = GenDDBCOperationMode.model_fields[ + "abnormal_condition_only" + ] # type: ignore[assignment] diff --git a/src/s2python/ddbc/ddbc_system_description.py b/src/s2python/ddbc/ddbc_system_description.py new file mode 100644 index 0000000..93724c8 --- /dev/null +++ b/src/s2python/ddbc/ddbc_system_description.py @@ -0,0 +1,29 @@ +from typing import List +import uuid + +from s2python.generated.gen_s2 import ( + DDBCSystemDescription as GenDDBCSystemDescription, +) +from s2python.common.number_range import NumberRange +from s2python.ddbc.ddbc_actuator_description import DDBCActuatorDescription +from s2python.validate_values_mixin import ( + catch_and_convert_exceptions, + S2MessageComponent, +) + + +@catch_and_convert_exceptions +class DDBCSystemDescription(GenDDBCSystemDescription, S2MessageComponent["DDBCSystemDescription"]): + model_config = GenDDBCSystemDescription.model_config + model_config["validate_assignment"] = True + + message_id: uuid.UUID = GenDDBCSystemDescription.model_fields["message_id"] # type: ignore[assignment] + actuators: List[DDBCActuatorDescription] = GenDDBCSystemDescription.model_fields[ + "actuators" + ] # type: ignore[assignment] + present_demand_rate: NumberRange = GenDDBCSystemDescription.model_fields[ + "present_demand_rate" + ] # type: ignore[assignment] + provides_average_demand_rate_forecast: bool = GenDDBCSystemDescription.model_fields[ + "provides_average_demand_rate_forecast" + ] # type: ignore[assignment] diff --git a/src/s2python/ddbc/ddbc_timer_status.py b/src/s2python/ddbc/ddbc_timer_status.py new file mode 100644 index 0000000..954a883 --- /dev/null +++ b/src/s2python/ddbc/ddbc_timer_status.py @@ -0,0 +1,18 @@ +import uuid + +from s2python.generated.gen_s2 import DDBCTimerStatus as GenDDBCTimerStatus + +from s2python.validate_values_mixin import ( + catch_and_convert_exceptions, + S2MessageComponent, +) + + +@catch_and_convert_exceptions +class DDBCTimerStatus(GenDDBCTimerStatus, S2MessageComponent["DDBCTimerStatus"]): + model_config = GenDDBCTimerStatus.model_config + model_config["validate_assignment"] = True + + message_id: uuid.UUID = GenDDBCTimerStatus.model_fields["message_id"] # type: ignore[assignment] + timer_id: uuid.UUID = GenDDBCTimerStatus.model_fields["timer_id"] # type: ignore[assignment] + actuator_id: uuid.UUID = GenDDBCTimerStatus.model_fields["actuator_id"] # type: ignore[assignment] diff --git a/src/s2python/s2_control_type.py b/src/s2python/s2_control_type.py index 982c9be..02b9967 100644 --- a/src/s2python/s2_control_type.py +++ b/src/s2python/s2_control_type.py @@ -66,6 +66,20 @@ def deactivate(self, conn: "S2Connection") -> None: """Overwrite with the actual deactivation logic of your Resource Manager for this particular control type.""" +class DDBControlType(S2ControlType): + def get_protocol_control_type(self) -> ProtocolControlType: + return ProtocolControlType.DEMAND_DRIVEN_BASED_CONTROL + + def register_handlers(self, handlers: "MessageHandlers") -> None: + pass + + @abc.abstractmethod + def activate(self, conn: "S2Connection") -> None: ... + + @abc.abstractmethod + def deactivate(self, conn: "S2Connection") -> None: ... + + class NoControlControlType(S2ControlType): def get_protocol_control_type(self) -> ProtocolControlType: return ProtocolControlType.NOT_CONTROLABLE From d4b6d74bf90aea75e66ce7972cf40bf36272d18e Mon Sep 17 00:00:00 2001 From: VladIftime <49650168+VladIftime@users.noreply.github.com> Date: Mon, 3 Mar 2025 10:24:50 +0100 Subject: [PATCH 4/4] PEBC skeleton class implementation (#60) * Publish branch. * PEBC power envelope limit type * Implement PEBCAllowedLimitRange, PEBCPowerEnvelopeElement and PEBCPowerEnvelope classes; remove obsolete PEBCPowerEnvelopeLimitType * Implement PEBCEnergyConstraint and PEBCPowerConstraints classes; add __init__.py file * Add PEBCInstruction class and __init__.py file; refactor imports in energy constraint module * Add PEBCInstruction class and __init__.py file; refactor imports in energy constraint module * null * OpenAI API Response: { "error": { "message": "We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)", "type": "invalid_request_error", "param": null, "code": null } } null * Payload: { "model": "gpt-4", "messages": [ { "role": "system", "content": "You are a helpful assistant that creates concise, meaningful git commit messages based on code changes." }, { "role": "user", "content": "Generate a commit message for the following changes:\n src/s2python/pebc/pebc_instruction.py | 1 + src/s2python/pebc/pebc_power_constraints.py | 1 + 2 files changed, 2 insertions(+)\nFiles changed:\nsrc/s2python/pebc/pebc_instruction.py,src/s2python/pebc/pebc_power_constraints.py," } ] } OpenAI API Response: { "error": { "message": "We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)", "type": "invalid_request_error", "param": null, "code": null } } null * Payload: { "model": "gpt-4", "messages": [ { "role": "system", "content": "You are a helpful assistant that creates concise, meaningful git commit messages based on code changes." }, { "role": "user", "content": "Generate a commit message for the following changes:\n src/s2python/pebc/pebc_instruction.py | 1 - src/s2python/pebc/pebc_power_constraints.py | 1 - 2 files changed, 2 deletions(-)\nFiles changed:\nsrc/s2python/pebc/pebc_instruction.py,src/s2python/pebc/pebc_power_constraints.py" } ] } OpenAI API Response: { "error": { "message": "We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)", "type": "invalid_request_error", "param": null, "code": null } } null * Payload: { "model": "gpt-4", "messages": [ { "role": "system", "content": "You are a helpful assistant that creates concise, meaningful git commit messages based on code changes." }, { "role": "user", "content": "Generate a commit message for the following changes:\n src/s2python/pebc/pebc_instruction.py | 1 + src/s2python/pebc/pebc_power_constraints.py | 1 + 2 files changed, 2 insertions(+) \nFiles changed:\nsrc/s2python/pebc/pebc_instruction.py,src/s2python/pebc/pebc_power_constraints.py," } ] } OpenAI API Response: { "id": "chatcmpl-Al2WJ2cNcBy1e7SuAXcIMjLbcFdBs", "object": "chat.completion", "created": 1735774467, "model": "gpt-4-0613", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Added new code lines in pebc_instruction.py and pebc_power_constraints.py", "refusal": null }, "logprobs": null, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 116, "completion_tokens": 16, "total_tokens": 132, "prompt_tokens_details": { "cached_tokens": 0, "audio_tokens": 0 }, "completion_tokens_details": { "reasoning_tokens": 0, "audio_tokens": 0, "accepted_prediction_tokens": 0, "rejected_prediction_tokens": 0 } }, "system_fingerprint": null } Added new code lines in pebc_instruction.py and pebc_power_constraints.py * Payload: { "model": "gpt-4", "messages": [ { "role": "system", "content": "You are a helpful assistant that creates concise, meaningful git commit messages based on code changes." }, { "role": "user", "content": "Generate a commit message for the following changes:\n src/s2python/pebc/pebc_instruction.py | 1 - src/s2python/pebc/pebc_power_constraints.py | 1 - 2 files changed, 2 deletions(-) \nFiles changed:\nsrc/s2python/pebc/pebc_instruction.py,src/s2python/pebc/pebc_power_constraints.py," } ] } Removed unnecessary lines from pebc_instruction.py and pebc_power_constraints.py * Payload: { "model": "gpt-4", "messages": [ { "role": "system", "content": "You are a helpful assistant that creates concise, meaningful git commit messages based on code changes." }, { "role": "user", "content": "Generate a commit message for the following changes:\n src/s2python/pebc/pebc_instruction.py | 1 + src/s2python/pebc/pebc_power_constraints.py | 1 + 2 files changed, 2 insertions(+) \nFiles changed:\nsrc/s2python/pebc/pebc_instruction.py,src/s2python/pebc/pebc_power_constraints.py," } ] } OpenAI API Response: { "id": "chatcmpl-AlAbv6QhnCJYGj5n7bQAdF7PiD0iT", "object": "chat.completion", "created": 1735805567, "model": "gpt-4-0613", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Added new functionalities to pebc_instruction and pebc_power_constraints files", "refusal": null }, "logprobs": null, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 116, "completion_tokens": 14, "total_tokens": 130, "prompt_tokens_details": { "cached_tokens": 0, "audio_tokens": 0 }, "completion_tokens_details": { "reasoning_tokens": 0, "audio_tokens": 0, "accepted_prediction_tokens": 0, "rejected_prediction_tokens": 0 } }, "system_fingerprint": null } Added new functionalities to pebc_instruction and pebc_power_constraints files * "Updated pebc_instruction.py and removed a line from pebc_power_constraints.py" * "Updated pebc_instruction.py and added new feature to pebc_power_constraints.py" * Removed unnecessary code from pebc_instruction.py and pebc_power_constraints.py * "Added new lines in pebc_instruction and pebc_power_constraints modules" * Removed unnecessary lines in pebc_instruction.py and pebc_power_constraints.py files * Added new relevant instructions and power constraints in the PEBC modules. * Added missing elements in pebc_instruction and pebc_power_constraints modules in s2python. * Added new methods to pebc_instruction.py and pebc_power_constraints.py files in s2python module * Refactored class definitions in PEBC modules for improved readability * Refactored class definitions in PEBC modules for improved readability * Added the controll type to s2_control_type wrapper * Added the controll type to s2_control_type wrapper * Added missing classes to init Signed-off-by: Vlad Iftime * Removed build files and added the PEBC_instruction in the submodule init Signed-off-by: Vlad Iftime * Removed build files and added the PEBC_instruction in the submodule init Signed-off-by: Vlad Iftime * Fixed the new type of S2Message as union Signed-off-by: Vlad Iftime --------- Signed-off-by: Vlad Iftime --- src/s2python/pebc/__init__.py | 10 +++++++ src/s2python/pebc/pebc_allowed_limit_range.py | 26 ++++++++++++++++++ src/s2python/pebc/pebc_energy_constraint.py | 25 +++++++++++++++++ src/s2python/pebc/pebc_instruction.py | 27 +++++++++++++++++++ src/s2python/pebc/pebc_power_constraints.py | 27 +++++++++++++++++++ src/s2python/pebc/pebc_power_envelope.py | 23 ++++++++++++++++ .../pebc/pebc_power_envelope_element.py | 16 +++++++++++ src/s2python/s2_control_type.py | 5 ++-- 8 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 src/s2python/pebc/__init__.py create mode 100644 src/s2python/pebc/pebc_allowed_limit_range.py create mode 100644 src/s2python/pebc/pebc_energy_constraint.py create mode 100644 src/s2python/pebc/pebc_instruction.py create mode 100644 src/s2python/pebc/pebc_power_constraints.py create mode 100644 src/s2python/pebc/pebc_power_envelope.py create mode 100644 src/s2python/pebc/pebc_power_envelope_element.py diff --git a/src/s2python/pebc/__init__.py b/src/s2python/pebc/__init__.py new file mode 100644 index 0000000..489c85c --- /dev/null +++ b/src/s2python/pebc/__init__.py @@ -0,0 +1,10 @@ +from s2python.pebc.pebc_allowed_limit_range import PEBCAllowedLimitRange +from s2python.pebc.pebc_power_constraints import PEBCPowerConstraints +from s2python.pebc.pebc_power_envelope import PEBCPowerEnvelope +from s2python.pebc.pebc_power_envelope_element import PEBCPowerEnvelopeElement +from s2python.pebc.pebc_energy_constraint import PEBCEnergyConstraint +from s2python.generated.gen_s2 import ( + PEBCPowerEnvelopeConsequenceType, + PEBCPowerEnvelopeLimitType, +) +from s2python.pebc.pebc_instruction import PEBCInstruction diff --git a/src/s2python/pebc/pebc_allowed_limit_range.py b/src/s2python/pebc/pebc_allowed_limit_range.py new file mode 100644 index 0000000..244cbec --- /dev/null +++ b/src/s2python/pebc/pebc_allowed_limit_range.py @@ -0,0 +1,26 @@ +from s2python.generated.gen_s2 import ( + PEBCAllowedLimitRange as GenPEBCAllowedLimitRange, + PEBCPowerEnvelopeLimitType as GenPEBCPowerEnvelopeLimitType, +) +from s2python.common import CommodityQuantity, NumberRange +from s2python.validate_values_mixin import ( + catch_and_convert_exceptions, + S2MessageComponent, +) + + +@catch_and_convert_exceptions +class PEBCAllowedLimitRange(GenPEBCAllowedLimitRange, S2MessageComponent["PEBCAllowedLimitRange"]): + model_config = GenPEBCAllowedLimitRange.model_config + model_config["validate_assignment"] = True + + commodity_quantity: CommodityQuantity = GenPEBCAllowedLimitRange.model_fields[ + "commodity_quantity" + ] # type: ignore[assignment] + limit_type: GenPEBCPowerEnvelopeLimitType = GenPEBCAllowedLimitRange.model_fields[ + "limit_type" + ] # type: ignore[assignment] + range_boundary: NumberRange = GenPEBCAllowedLimitRange.model_fields["range_boundary"] # type: ignore[assignment] + abnormal_condition_only: bool = [ + GenPEBCAllowedLimitRange.model_fields["abnormal_condition_only"] # type: ignore[assignment] + ] diff --git a/src/s2python/pebc/pebc_energy_constraint.py b/src/s2python/pebc/pebc_energy_constraint.py new file mode 100644 index 0000000..db09213 --- /dev/null +++ b/src/s2python/pebc/pebc_energy_constraint.py @@ -0,0 +1,25 @@ +import uuid + +from s2python.generated.gen_s2 import ( + PEBCEnergyConstraint as GenPEBCEnergyConstraint, +) +from s2python.common import CommodityQuantity +from s2python.validate_values_mixin import ( + catch_and_convert_exceptions, + S2MessageComponent, +) + + +@catch_and_convert_exceptions +class PEBCEnergyConstraint(GenPEBCEnergyConstraint, S2MessageComponent["PEBCEnergyConstraint"]): + model_config = GenPEBCEnergyConstraint.model_config + model_config["validate_assignment"] = True + + message_id: uuid.UUID = GenPEBCEnergyConstraint.model_fields["message_id"] # type: ignore[assignment] + id: uuid.UUID = GenPEBCEnergyConstraint.model_fields["id"] # type: ignore[assignment] + + upper_average_power: float = GenPEBCEnergyConstraint.model_fields["upper_average_power"] # type: ignore[assignment] + lower_average_power: float = GenPEBCEnergyConstraint.model_fields["lower_average_power"] # type: ignore[assignment] + commodity_quantity: CommodityQuantity = [ + GenPEBCEnergyConstraint.model_fields["commodity_quantity"] # type: ignore[assignment] + ] diff --git a/src/s2python/pebc/pebc_instruction.py b/src/s2python/pebc/pebc_instruction.py new file mode 100644 index 0000000..6f8192b --- /dev/null +++ b/src/s2python/pebc/pebc_instruction.py @@ -0,0 +1,27 @@ +import uuid +from typing import List + +from s2python.generated.gen_s2 import ( + PEBCInstruction as GenPEBCInstruction, +) +from s2python.pebc.pebc_power_envelope import PEBCPowerEnvelope +from s2python.validate_values_mixin import ( + catch_and_convert_exceptions, + S2MessageComponent, +) + + +@catch_and_convert_exceptions +class PEBCInstruction(GenPEBCInstruction, S2MessageComponent["PEBCInstruction"]): + model_config = GenPEBCInstruction.model_config + model_config["validate_assignment"] = True + + message_id: uuid.UUID = GenPEBCInstruction.model_fields["message_id"] # type: ignore[assignment] + id: uuid.UUID = GenPEBCInstruction.model_fields["id"] # type: ignore[assignment] + power_constraints_id: uuid.UUID = [ + GenPEBCInstruction.model_fields["power_constraints_id"] # type: ignore[assignment] + ] + power_envelopes: List[PEBCPowerEnvelope] = [ + GenPEBCInstruction.model_fields["power_envelopes"] # type: ignore[assignment] + ] + abnormal_conditions: bool = GenPEBCInstruction.model_fields["abnormal_conditions"] # type: ignore[assignment] diff --git a/src/s2python/pebc/pebc_power_constraints.py b/src/s2python/pebc/pebc_power_constraints.py new file mode 100644 index 0000000..16264ff --- /dev/null +++ b/src/s2python/pebc/pebc_power_constraints.py @@ -0,0 +1,27 @@ +import uuid +from typing import List + +from s2python.generated.gen_s2 import ( + PEBCPowerConstraints as GenPEBCPowerConstraints, + PEBCPowerEnvelopeConsequenceType as GenPEBCPowerEnvelopeConsequenceType, +) +from s2python.pebc.pebc_allowed_limit_range import PEBCAllowedLimitRange +from s2python.validate_values_mixin import ( + catch_and_convert_exceptions, + S2MessageComponent, +) + + +@catch_and_convert_exceptions +class PEBCPowerConstraints(GenPEBCPowerConstraints, S2MessageComponent["PEBCPowerConstraints"]): + model_config = GenPEBCPowerConstraints.model_config + model_config["validate_assignment"] = True + + message_id: uuid.UUID = GenPEBCPowerConstraints.model_fields["message_id"] # type: ignore[assignment] + id: uuid.UUID = GenPEBCPowerConstraints.model_fields["id"] # type: ignore[assignment] + consequence_type: GenPEBCPowerEnvelopeConsequenceType = GenPEBCPowerConstraints.model_fields[ + "consequence_type" + ] # type: ignore[assignment] + allowed_limit_ranges: List[PEBCAllowedLimitRange] = GenPEBCPowerConstraints.model_fields[ + "allowed_limit_ranges" + ] # type: ignore[assignment] diff --git a/src/s2python/pebc/pebc_power_envelope.py b/src/s2python/pebc/pebc_power_envelope.py new file mode 100644 index 0000000..4033e8b --- /dev/null +++ b/src/s2python/pebc/pebc_power_envelope.py @@ -0,0 +1,23 @@ +from typing import List +from s2python.generated.gen_s2 import ( + PEBCPowerEnvelope as GenPEBCPowerEnvelope, +) +from s2python.pebc.pebc_power_envelope_element import PEBCPowerEnvelopeElement +from s2python.common import CommodityQuantity +from s2python.validate_values_mixin import ( + catch_and_convert_exceptions, + S2MessageComponent, +) + + +@catch_and_convert_exceptions +class PEBCPowerEnvelope(GenPEBCPowerEnvelope, S2MessageComponent["PEBCPowerEnvelope"]): + model_config = GenPEBCPowerEnvelope.model_config + model_config["validate_assignment"] = True + + commodity_quantity: CommodityQuantity = GenPEBCPowerEnvelope.model_fields[ + "commodity_quantity" + ] # type: ignore[assignment] + power_envelope_elements: List[PEBCPowerEnvelopeElement] = GenPEBCPowerEnvelope.model_fields[ + "power_envelope_elements" + ] # type: ignore[assignment] diff --git a/src/s2python/pebc/pebc_power_envelope_element.py b/src/s2python/pebc/pebc_power_envelope_element.py new file mode 100644 index 0000000..8e75440 --- /dev/null +++ b/src/s2python/pebc/pebc_power_envelope_element.py @@ -0,0 +1,16 @@ +from s2python.generated.gen_s2 import ( + PEBCPowerEnvelopeElement as GenPEBCPowerEnvelopeElement, +) +from s2python.validate_values_mixin import ( + catch_and_convert_exceptions, + S2MessageComponent, +) + + +@catch_and_convert_exceptions +class PEBCPowerEnvelopeElement(GenPEBCPowerEnvelopeElement, S2MessageComponent["PEBCPowerEnvelopeElement"]): + model_config = GenPEBCPowerEnvelopeElement.model_config + model_config["validate_assignment"] = True + + lower_limit: float = GenPEBCPowerEnvelopeElement.model_fields["lower_limit"] # type: ignore[assignment] + upper_limit: float = GenPEBCPowerEnvelopeElement.model_fields["upper_limit"] # type: ignore[assignment] diff --git a/src/s2python/s2_control_type.py b/src/s2python/s2_control_type.py index 02b9967..8463d04 100644 --- a/src/s2python/s2_control_type.py +++ b/src/s2python/s2_control_type.py @@ -66,9 +66,10 @@ def deactivate(self, conn: "S2Connection") -> None: """Overwrite with the actual deactivation logic of your Resource Manager for this particular control type.""" -class DDBControlType(S2ControlType): + +class PEBCControlType(S2ControlType): def get_protocol_control_type(self) -> ProtocolControlType: - return ProtocolControlType.DEMAND_DRIVEN_BASED_CONTROL + return ProtocolControlType.POWER_ENVELOPE_BASED_CONTROL def register_handlers(self, handlers: "MessageHandlers") -> None: pass