2016-01-24 20:28:09 +00:00
|
|
|
""" Event Decorators for custom components """
|
|
|
|
|
|
|
|
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):
|
|
|
|
""" Decorator factory to track state changes for entity id """
|
|
|
|
|
|
|
|
def track_state_change_decorator(action):
|
|
|
|
""" Decorator to track state changes """
|
2016-01-24 22:46:05 +00:00
|
|
|
event.track_state_change(HASS, entity_ids, action,
|
|
|
|
from_state, to_state)
|
|
|
|
return action
|
2016-01-24 20:28:09 +00:00
|
|
|
|
|
|
|
return track_state_change_decorator
|
|
|
|
|
|
|
|
|
|
|
|
def track_sunrise(offset=None):
|
|
|
|
""" Decorator factory to track sunrise events """
|
|
|
|
|
|
|
|
def track_sunrise_decorator(action):
|
|
|
|
""" Decorator to track sunrise events """
|
2016-01-24 22:46:05 +00:00
|
|
|
event.track_sunrise(HASS, action, offset)
|
|
|
|
return action
|
2016-01-24 20:28:09 +00:00
|
|
|
|
|
|
|
return track_sunrise_decorator
|
|
|
|
|
|
|
|
|
|
|
|
def track_sunset(offset=None):
|
|
|
|
""" Decorator factory to track sunset events """
|
|
|
|
|
|
|
|
def track_sunset_decorator(action):
|
|
|
|
""" Decorator to track sunset events """
|
2016-01-24 22:46:05 +00:00
|
|
|
event.track_sunset(HASS, action, offset)
|
|
|
|
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):
|
|
|
|
""" Decorator factory to track time changes """
|
|
|
|
|
|
|
|
def track_time_change_decorator(action):
|
|
|
|
""" Decorator to track time changes """
|
2016-01-24 22:46:05 +00:00
|
|
|
event.track_time_change(HASS, action, year, month, day, hour,
|
|
|
|
minute, second)
|
|
|
|
return action
|
2016-01-24 20:28:09 +00:00
|
|
|
|
|
|
|
return track_time_change_decorator
|