core/homeassistant/components/automation/time.py

36 lines
1.1 KiB
Python
Raw Normal View History

"""Offer time listening automation rules."""
2015-09-14 05:25:42 +00:00
import logging
import voluptuous as vol
from homeassistant.core import callback
from homeassistant.const import CONF_AT, CONF_PLATFORM
from homeassistant.helpers import config_validation as cv
2016-10-01 08:22:13 +00:00
from homeassistant.helpers.event import async_track_time_change
2015-01-16 07:32:27 +00:00
_LOGGER = logging.getLogger(__name__)
TRIGGER_SCHEMA = vol.Schema({
vol.Required(CONF_PLATFORM): 'time',
vol.Required(CONF_AT): cv.time,
})
2015-01-16 07:32:27 +00:00
async def async_trigger(hass, config, action, automation_info):
"""Listen for state changes based on configuration."""
at_time = config.get(CONF_AT)
hours, minutes, seconds = at_time.hour, at_time.minute, at_time.second
2015-09-15 15:56:06 +00:00
@callback
2015-01-16 07:32:27 +00:00
def time_automation_listener(now):
2016-03-07 19:20:07 +00:00
"""Listen for time changes and calls action."""
hass.async_run_job(action, {
'trigger': {
'platform': 'time',
'now': now,
},
})
2015-01-16 07:32:27 +00:00
2016-10-01 08:22:13 +00:00
return async_track_time_change(hass, time_automation_listener,
hour=hours, minute=minutes, second=seconds)