Improve ecobee service schemas (#26955)
* Validate date and time in create vaction Improve validation with utility functions. * Improve validate ATTR_VACATION_NAME * Add tests for ecobee.util functions * Revise tests as standalone functions
This commit is contained in:
1 parent
1c72a246a0
commit
2dfdc5f6f8
3 files changed
+67
-6
No files matched your search
@@ -0,0 +1,21 @@
|
||||
"""Validation utility functions for ecobee services."""
|
||||
from datetime import datetime
|
||||
import voluptuous as vol
|
||||
|
||||
|
||||
def ecobee_date(date_string):
|
||||
"""Validate a date_string as valid for the ecobee API."""
|
||||
try:
|
||||
datetime.strptime(date_string, "%Y-%m-%d")
|
||||
except ValueError:
|
||||
raise vol.Invalid("Date does not match ecobee date format YYYY-MM-DD")
|
||||
return date_string
|
||||
|
||||
|
||||
def ecobee_time(time_string):
|
||||
"""Validate a time_string as valid for the ecobee API."""
|
||||
try:
|
||||
datetime.strptime(time_string, "%H:%M:%S")
|
||||
except ValueError:
|
||||
raise vol.Invalid("Time does not match ecobee 24-hour time format HH:MM:SS")
|
||||
return time_string
|
||||
Reference in new issue
Block a user