2019-02-13 20:21:14 +00:00
|
|
|
"""Offer time listening automation rules."""
|
2015-09-14 05:25:42 +00:00
|
|
|
import logging
|
|
|
|
|
2016-04-28 10:03:57 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2017-07-17 20:24:05 +00:00
|
|
|
from homeassistant.const import CONF_AT, CONF_PLATFORM
|
2019-12-08 16:29:39 +00:00
|
|
|
from homeassistant.core import callback
|
2016-04-28 10:03:57 +00:00
|
|
|
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
|
|
|
|
2019-08-12 03:38:18 +00:00
|
|
|
# mypy: allow-untyped-defs, no-check-untyped-defs
|
|
|
|
|
2015-09-17 06:24:06 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
TRIGGER_SCHEMA = vol.Schema(
|
|
|
|
{vol.Required(CONF_PLATFORM): "time", vol.Required(CONF_AT): cv.time}
|
|
|
|
)
|
2016-04-28 10:03:57 +00:00
|
|
|
|
2015-01-16 07:32:27 +00:00
|
|
|
|
2019-09-24 21:57:05 +00:00
|
|
|
async def async_attach_trigger(hass, config, action, automation_info):
|
2017-05-02 20:47:20 +00:00
|
|
|
"""Listen for state changes based on configuration."""
|
2019-01-15 17:33:34 +00:00
|
|
|
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
|
|
|
|
2016-10-05 03:44:32 +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."""
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.async_run_job(action, {"trigger": {"platform": "time", "now": now}})
|
|
|
|
|
|
|
|
return async_track_time_change(
|
|
|
|
hass, time_automation_listener, hour=hours, minute=minutes, second=seconds
|
|
|
|
)
|