mirror of
https://github.com/esphome/esphome.git
synced 2025-09-06 05:12:21 +01:00
Add 'at' time trigger (#493)
## Description: **Related issue (if applicable):** fixes <link to issue> **Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs#<esphome-docs PR number goes here> **Pull request in [esphome-core](https://github.com/esphome/esphome-core) with C++ framework changes (if applicable):** esphome/esphome-core#<esphome-core PR number goes here> ## Checklist: - [ ] The code change is tested and works locally. - [ ] Tests have been added to verify that the new code works (under `tests/` folder). If user exposed functionality or configuration variables are added/changed: - [ ] Documentation added/updated in [esphomedocs](https://github.com/OttoWinter/esphomedocs).
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
"""Helpers for config validation using voluptuous."""
|
||||
from __future__ import print_function
|
||||
|
||||
from datetime import datetime
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
@@ -13,7 +14,7 @@ from esphome import core
|
||||
from esphome.const import CONF_AVAILABILITY, CONF_COMMAND_TOPIC, CONF_DISCOVERY, CONF_ID, \
|
||||
CONF_INTERNAL, CONF_NAME, CONF_PAYLOAD_AVAILABLE, CONF_PAYLOAD_NOT_AVAILABLE, CONF_PLATFORM, \
|
||||
CONF_RETAIN, CONF_SETUP_PRIORITY, CONF_STATE_TOPIC, CONF_TOPIC, ESP_PLATFORM_ESP32, \
|
||||
ESP_PLATFORM_ESP8266
|
||||
ESP_PLATFORM_ESP8266, CONF_HOUR, CONF_MINUTE, CONF_SECOND
|
||||
from esphome.core import CORE, HexInt, IPAddress, Lambda, TimePeriod, TimePeriodMicroseconds, \
|
||||
TimePeriodMilliseconds, TimePeriodSeconds, TimePeriodMinutes
|
||||
from esphome.py_compat import integer_types, string_types, text_type, IS_PY2
|
||||
@@ -391,6 +392,23 @@ positive_not_null_time_period = vol.All(time_period,
|
||||
vol.Range(min=TimePeriod(), min_included=False))
|
||||
|
||||
|
||||
def time_of_day(value):
|
||||
value = string(value)
|
||||
try:
|
||||
date = datetime.strptime(value, '%H:%M:%S')
|
||||
except ValueError as err:
|
||||
try:
|
||||
date = datetime.strptime(value, '%H:%M:%S %p')
|
||||
except ValueError:
|
||||
raise vol.Invalid("Invalid time of day: {}".format(err))
|
||||
|
||||
return {
|
||||
CONF_HOUR: date.hour,
|
||||
CONF_MINUTE: date.minute,
|
||||
CONF_SECOND: date.second,
|
||||
}
|
||||
|
||||
|
||||
def mac_address(value):
|
||||
value = string_strict(value)
|
||||
parts = value.split(':')
|
||||
|
Reference in New Issue
Block a user