-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sensors): Fixed issue with saving session evaluating incorrectly … (
#317) …when data is unavailable
- Loading branch information
Showing
6 changed files
with
56 additions
and
37 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
34 changes: 19 additions & 15 deletions
34
custom_components/octopus_energy/saving_sessions/__init__.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 |
---|---|---|
@@ -1,24 +1,28 @@ | ||
def current_saving_sessions_event(current_date, events): | ||
current_event = None | ||
for event in events: | ||
if (event["start"] <= current_date and event["end"] >= current_date): | ||
current_event = { | ||
"start": event["start"], | ||
"end": event["end"], | ||
"duration_in_minutes": (event["end"] - event["start"]).total_seconds() / 60 | ||
} | ||
break | ||
|
||
if events is not None: | ||
for event in events: | ||
if (event["start"] <= current_date and event["end"] >= current_date): | ||
current_event = { | ||
"start": event["start"], | ||
"end": event["end"], | ||
"duration_in_minutes": (event["end"] - event["start"]).total_seconds() / 60 | ||
} | ||
break | ||
|
||
return current_event | ||
|
||
def get_next_saving_sessions_event(current_date, events): | ||
next_event = None | ||
for event in events: | ||
if event["start"] > current_date and (next_event == None or event["start"] < next_event["start"]): | ||
next_event = { | ||
"start": event["start"], | ||
"end": event["end"], | ||
"duration_in_minutes": (event["end"] - event["start"]).total_seconds() / 60 | ||
} | ||
|
||
if events is not None: | ||
for event in events: | ||
if event["start"] > current_date and (next_event == None or event["start"] < next_event["start"]): | ||
next_event = { | ||
"start": event["start"], | ||
"end": event["end"], | ||
"duration_in_minutes": (event["end"] - event["start"]).total_seconds() / 60 | ||
} | ||
|
||
return next_event |
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