diff --git a/_docs/entities/octoplus.md b/_docs/entities/octoplus.md index 66696975..919e6441 100644 --- a/_docs/entities/octoplus.md +++ b/_docs/entities/octoplus.md @@ -49,6 +49,7 @@ Each available event item will include the following attributes | `code` | `string` | The event code of the event. This will be required to join via the [join service](../services.md) | | `start` | `datetime` | The date/time the event starts | | `end` | `datetime` | The date/time the event starts | +| `duration_in_minutes` | `integer` | The duration of the event in minutes | | `octopoints_per_kwh` | `integer` | The number of octopoints that are awarded per kwh saved during the event | Each joined event item will include the following attributes @@ -58,6 +59,7 @@ Each joined event item will include the following attributes | `id` | `integer` | The id of the event | | `start` | `datetime` | The date/time the event starts | | `end` | `datetime` | The date/time the event starts | +| `duration_in_minutes` | `integer` | The duration of the event in minutes | | `rewarded_octopoints` | `integer` | The total number of octopoints that were awarded (if any or known) | | `octopoints_per_kwh` | `integer` | The number of octopoints that are/were awarded per kwh saved during the event (if known) | diff --git a/_docs/events.md b/_docs/events.md index 171f98f2..1ffed8de 100644 --- a/_docs/events.md +++ b/_docs/events.md @@ -319,6 +319,7 @@ This event is raised when a new saving session is discovered. | `event_id` | `string` | The id of the event | | `event_start` | `datetime` | The date/time the event starts | | `event_end` | `datetime` | The date/time the event ends | +| `event_duration_in_minutes` | `integer` | The duration of the event in minutes | | `event_octopoints_per_kwh` | `integer` | The number of octopoints that are awarded per kwh saved during the event | ### Automation Example @@ -333,7 +334,7 @@ This event is raised when a new saving session is discovered. data: title: "New Saving Session" message: > - New Octopus Energy saving session available. It starts at {{ trigger.event.data["event_start"].strftime('%H:%M') }} on {{ trigger.event.data["event_start"].day }}/{{ trigger.event.data["event_start"].month }} + New Octopus Energy saving session available. It starts at {{ trigger.event.data["event_start"].strftime('%H:%M') }} on {{ trigger.event.data["event_start"].day }}/{{ trigger.event.data["event_start"].month }} for {{ trigger.event.data["event_duration_in_minutes"] | int }} minutes. ``` ## All Saving Sessions @@ -356,6 +357,7 @@ Each available event item will include the following attributes | `code` | `string` | The event code of the event. This will be required to join via the [join service](./services.md) | | `start` | `datetime` | The date/time the event starts | | `end` | `datetime` | The date/time the event starts | +| `duration_in_minutes` | `integer` | The duration of the event in minutes | | `octopoints_per_kwh` | `integer` | The number of octopoints that are awarded per kwh saved during the event | Each joined event item will include the following attributes @@ -365,6 +367,7 @@ Each joined event item will include the following attributes | `id` | `integer` | The id of the event | | `start` | `datetime` | The date/time the event starts | | `end` | `datetime` | The date/time the event starts | +| `duration_in_minutes` | `integer` | The duration of the event in minutes | | `octopoints_per_kwh` | `integer` | The number of octopoints that are awarded per kwh saved during the event | | `rewarded_octopoints` | `integer` | The total number of octopoints that were awarded (if any or known) | diff --git a/custom_components/octopus_energy/coordinators/saving_sessions.py b/custom_components/octopus_energy/coordinators/saving_sessions.py index 902b213e..b67cecc6 100644 --- a/custom_components/octopus_energy/coordinators/saving_sessions.py +++ b/custom_components/octopus_energy/coordinators/saving_sessions.py @@ -77,6 +77,7 @@ async def async_refresh_saving_sessions( "event_id": available_event.id, "event_start": available_event.start, "event_end": available_event.end, + "event_duration_in_minutes": available_event.duration_in_minutes, "event_octopoints_per_kwh": available_event.octopoints }) @@ -93,6 +94,7 @@ async def async_refresh_saving_sessions( "id": ev.id, "start": ev.start, "end": ev.end, + "duration_in_minutes": ev.duration_in_minutes, "rewarded_octopoints": ev.octopoints, "octopoints_per_kwh": original_event.octopoints if original_event is not None else None }) @@ -104,6 +106,7 @@ async def async_refresh_saving_sessions( "code": ev.code, "start": ev.start, "end": ev.end, + "duration_in_minutes": ev.duration_in_minutes, "octopoints_per_kwh": ev.octopoints }, available_events)), "joined_events": joined_events, diff --git a/tests/unit/coordinators/test_async_refresh_saving_sessions.py b/tests/unit/coordinators/test_async_refresh_saving_sessions.py index a98e3146..36369efa 100644 --- a/tests/unit/coordinators/test_async_refresh_saving_sessions.py +++ b/tests/unit/coordinators/test_async_refresh_saving_sessions.py @@ -7,7 +7,6 @@ from custom_components.octopus_energy.api_client.saving_sessions import SavingSession, SavingSessionsResponse from custom_components.octopus_energy.const import EVENT_ALL_SAVING_SESSIONS, EVENT_NEW_SAVING_SESSION, REFRESH_RATE_IN_MINUTES_OCTOPLUS_SAVING_SESSIONS - def assert_raised_new_saving_session_event( raised_event: dict, account_id: str, @@ -27,6 +26,9 @@ def assert_raised_new_saving_session_event( assert "event_end" in raised_event assert raised_event["event_end"] == expected_event.end + + assert "event_duration_in_minutes" in raised_event + assert raised_event["event_duration_in_minutes"] == expected_event.duration_in_minutes assert "event_octopoints_per_kwh" in raised_event assert raised_event["event_octopoints_per_kwh"] == expected_event.octopoints @@ -56,6 +58,9 @@ def assert_raised_all_saving_session_event( assert "end" in actual_event assert actual_event["end"] == expected_event.end + + assert "duration_in_minutes" in actual_event + assert actual_event["duration_in_minutes"] == expected_event.duration_in_minutes assert "octopoints_per_kwh" in actual_event assert actual_event["octopoints_per_kwh"] == expected_event.octopoints @@ -71,6 +76,9 @@ def assert_raised_all_saving_session_event( assert "end" in actual_event assert actual_event["end"] == expected_event.end + + assert "duration_in_minutes" in actual_event + assert actual_event["duration_in_minutes"] == expected_event.duration_in_minutes assert "rewarded_octopoints" in actual_event assert actual_event["rewarded_octopoints"] == expected_event.octopoints