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:
alexsydell 2024-03-22 15:45:54 -06:00 committed by GitHub
parent d3c68303b0
commit 9e86f82a1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 88 additions and 17 deletions

View file

@ -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)