-
-
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.
fix: Updated default naming of entities to be better for areas of HA …
…where space is limited BREAKING CHANGE: If you are relying on the current default names, you will need to adjust accordingly. This will not effect the entity ids, so no automations should be effected.
- Loading branch information
1 parent
eba53bd
commit 4f749a3
Showing
9 changed files
with
111 additions
and
23 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from datetime import datetime, timedelta | ||
|
||
def triangle_number(n): | ||
sum = 0 | ||
for i in range(1, n + 1): | ||
sum += i * (i + 1) / 2 | ||
return sum | ||
|
||
def calculate_next_refresh(current: datetime, request_attempts: int, refresh_rate_in_minutes: int): | ||
next_rate = current + timedelta(minutes=refresh_rate_in_minutes) | ||
if (request_attempts > 1): | ||
i = request_attempts - 1 | ||
target_minutes = i * (i + 1) / 2 | ||
next_rate = next_rate + timedelta(minutes=target_minutes) | ||
return next_rate |
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,26 @@ | ||
from datetime import datetime, timedelta | ||
import pytest | ||
|
||
from custom_components.carbon_intensity.utils.requests import calculate_next_refresh | ||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize("request_attempts,expected_next_refresh",[ | ||
(1, datetime.strptime("2023-07-14T10:35:01+01:00", "%Y-%m-%dT%H:%M:%S%z")), | ||
(2, datetime.strptime("2023-07-14T10:36:01+01:00", "%Y-%m-%dT%H:%M:%S%z")), | ||
(3, datetime.strptime("2023-07-14T10:38:01+01:00", "%Y-%m-%dT%H:%M:%S%z")), | ||
(4, datetime.strptime("2023-07-14T10:41:01+01:00", "%Y-%m-%dT%H:%M:%S%z")), | ||
(5, datetime.strptime("2023-07-14T10:45:01+01:00", "%Y-%m-%dT%H:%M:%S%z")), | ||
(6, datetime.strptime("2023-07-14T10:50:01+01:00", "%Y-%m-%dT%H:%M:%S%z")) | ||
]) | ||
async def test_when_data_provided_then_expected_rate_is_returned(request_attempts, expected_next_refresh): | ||
# Arrange | ||
refresh_rate_in_minutes = 5 | ||
request_datetime = datetime.strptime("2023-07-14T10:30:01+01:00", "%Y-%m-%dT%H:%M:%S%z") | ||
current = request_datetime + timedelta(minutes=refresh_rate_in_minutes) + timedelta(minutes=request_attempts - 1) | ||
|
||
# Act | ||
next_refresh = calculate_next_refresh(request_datetime, request_attempts, refresh_rate_in_minutes) | ||
|
||
# Assert | ||
assert next_refresh == expected_next_refresh | ||
assert current <= next_refresh |