2016-03-07 22:39:52 +00:00
|
|
|
"""Event Decorators for custom components."""
|
2016-01-25 00:52:22 +00:00
|
|
|
import functools
|
|
|
|
|
2016-01-24 20:28:09 +00:00
|
|
|
from homeassistant.helpers import event
|
|
|
|
|
2016-01-24 22:46:05 +00:00
|
|
|
HASS = None
|
2016-01-24 20:28:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
def track_state_change(entity_ids, from_state=None, to_state=None):
|
2016-03-07 22:39:52 +00:00
|
|
|
"""Decorator factory to track state changes for entity id."""
|
2016-01-24 20:28:09 +00:00
|
|
|
def track_state_change_decorator(action):
|
2016-03-07 22:39:52 +00:00
|
|
|
"""Decorator to track state changes."""
|
2016-01-25 00:52:22 +00:00
|
|
|
event.track_state_change(HASS, entity_ids,
|
2016-01-25 05:14:16 +00:00
|
|
|
functools.partial(action, HASS),
|
2016-01-24 22:46:05 +00:00
|
|
|
from_state, to_state)
|
|
|
|
return action
|
2016-01-24 20:28:09 +00:00
|
|
|
|
|
|
|
return track_state_change_decorator
|
|
|
|
|
|
|
|
|
|
|
|
def track_sunrise(offset=None):
|
2016-03-07 22:39:52 +00:00
|
|
|
"""Decorator factory to track sunrise events."""
|
2016-01-24 20:28:09 +00:00
|
|
|
def track_sunrise_decorator(action):
|
2016-03-07 22:39:52 +00:00
|
|
|
"""Decorator to track sunrise events."""
|
2016-01-25 00:52:22 +00:00
|
|
|
event.track_sunrise(HASS,
|
2016-01-25 05:14:16 +00:00
|
|
|
functools.partial(action, HASS),
|
2016-01-25 02:06:15 +00:00
|
|
|
offset)
|
2016-01-24 22:46:05 +00:00
|
|
|
return action
|
2016-01-24 20:28:09 +00:00
|
|
|
|
|
|
|
return track_sunrise_decorator
|
|
|
|
|
|
|
|
|
|
|
|
def track_sunset(offset=None):
|
2016-03-07 22:39:52 +00:00
|
|
|
"""Decorator factory to track sunset events."""
|
2016-01-24 20:28:09 +00:00
|
|
|
def track_sunset_decorator(action):
|
2016-03-07 22:39:52 +00:00
|
|
|
"""Decorator to track sunset events."""
|
2016-01-25 00:52:22 +00:00
|
|
|
event.track_sunset(HASS,
|
2016-01-25 05:14:16 +00:00
|
|
|
functools.partial(action, HASS),
|
2016-01-25 00:52:22 +00:00
|
|
|
offset)
|
2016-01-24 22:46:05 +00:00
|
|
|
return action
|
2016-01-24 20:28:09 +00:00
|
|
|
|
|
|
|
return track_sunset_decorator
|
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=too-many-arguments
|
|
|
|
def track_time_change(year=None, month=None, day=None, hour=None, minute=None,
|
|
|
|
second=None):
|
2016-03-07 22:39:52 +00:00
|
|
|
"""Decorator factory to track time changes."""
|
2016-01-24 20:28:09 +00:00
|
|
|
def track_time_change_decorator(action):
|
2016-03-07 22:39:52 +00:00
|
|
|
"""Decorator to track time changes."""
|
2016-01-25 00:52:22 +00:00
|
|
|
event.track_time_change(HASS,
|
2016-01-25 05:14:16 +00:00
|
|
|
functools.partial(action, HASS),
|
2016-01-25 00:52:22 +00:00
|
|
|
year, month, day, hour, minute, second)
|
2016-01-24 22:46:05 +00:00
|
|
|
return action
|
2016-01-24 20:28:09 +00:00
|
|
|
|
|
|
|
return track_time_change_decorator
|
2016-01-25 02:06:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=too-many-arguments
|
|
|
|
def track_utc_time_change(year=None, month=None, day=None, hour=None,
|
|
|
|
minute=None, second=None):
|
2016-03-07 22:39:52 +00:00
|
|
|
"""Decorator factory to track time changes."""
|
2016-01-25 02:06:15 +00:00
|
|
|
def track_utc_time_change_decorator(action):
|
2016-03-07 22:39:52 +00:00
|
|
|
"""Decorator to track time changes."""
|
2016-01-25 02:06:15 +00:00
|
|
|
event.track_utc_time_change(HASS,
|
2016-01-25 05:14:16 +00:00
|
|
|
functools.partial(action, HASS),
|
2016-01-25 02:06:15 +00:00
|
|
|
year, month, day, hour, minute, second)
|
|
|
|
return action
|
|
|
|
|
|
|
|
return track_utc_time_change_decorator
|