Add ecobee indefinite away preset, remove unusable/broken presets (#108636)
* Add ecobee indefinite away preset, remove unusable/broken presets * Revert cleanup of presets which no longer work
This commit is contained in:
parent
d3c68303b0
commit
9e86f82a1b
6 changed files with 88 additions and 17 deletions
|
@ -1,6 +1,6 @@
|
|||
"""Validation utility functions for ecobee services."""
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import date, datetime, timedelta
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -23,3 +23,13 @@ def ecobee_time(time_string):
|
|||
"Time does not match ecobee 24-hour time format HH:MM:SS"
|
||||
) from err
|
||||
return time_string
|
||||
|
||||
|
||||
def is_indefinite_hold(start_date_string: str, end_date_string: str) -> bool:
|
||||
"""Determine if the given start and end dates from the ecobee API represent an indefinite hold.
|
||||
|
||||
This is not documented in the API, so a rough heuristic is used where a hold over 1 year is considered indefinite.
|
||||
"""
|
||||
return date.fromisoformat(end_date_string) - date.fromisoformat(
|
||||
start_date_string
|
||||
) > timedelta(days=365)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue