Skip to content

Commit

Permalink
feat: Added duration in minutes to saving sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
BottlecapDave committed Apr 13, 2024
1 parent 756535e commit 35d17dc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions _docs/entities/octoplus.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) |

Expand Down
5 changes: 4 additions & 1 deletion _docs/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand All @@ -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
})
Expand All @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion tests/unit/coordinators/test_async_refresh_saving_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 35d17dc

Please sign in to comment.