-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added support for national carbon intensity rates
- Loading branch information
1 parent
4f749a3
commit f3877e1
Showing
7 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
tests/integration/api_client/test_get_national_intensity_and_generation_rates.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from datetime import datetime, timedelta | ||
import os | ||
import pytest | ||
|
||
from custom_components.carbon_intensity.api_client import CarbonIntensityApiClient | ||
|
||
@pytest.mark.asyncio | ||
async def test_when_get_national_intensity_and_generation_rate_called_then_calculation_returned(): | ||
# Arrange | ||
client = CarbonIntensityApiClient() | ||
period_from = datetime.strptime("2021-12-01T00:00:00Z", "%Y-%m-%dT%H:%M:%S%z") | ||
|
||
# Act | ||
data = await client.async_get_national_intensity_and_generation_rates(period_from) | ||
|
||
# Assert | ||
assert len(data) == 97 | ||
|
||
# Make sure our data is returned in 30 minute increments | ||
expected_from = period_from - timedelta(minutes=30) | ||
for item in data: | ||
expected_to = expected_from + timedelta(minutes=30) | ||
|
||
assert "from" in item | ||
assert item["from"] == expected_from | ||
assert "to" in item | ||
assert item["to"] == expected_to | ||
assert "intensity_forecast" in item | ||
assert "generation_mix" in item | ||
|
||
for mix in item["generation_mix"]: | ||
assert "fuel" in mix | ||
assert "perc" in mix | ||
|
||
expected_from = expected_to |