diff --git a/homeassistant/components/script.py b/homeassistant/components/script.py index c4f70b6d6d3..c5b1d4872de 100644 --- a/homeassistant/components/script.py +++ b/homeassistant/components/script.py @@ -8,154 +8,198 @@ by the user or automatically based upon automation events, etc. import logging from datetime import timedelta import homeassistant.util.dt as date_util +from itertools import islice import threading -from homeassistant.helpers.event import track_point_in_time +from homeassistant.helpers.entity_component import EntityComponent +from homeassistant.helpers.entity import ToggleEntity +from homeassistant.helpers.event import track_point_in_utc_time from homeassistant.util import split_entity_id from homeassistant.const import ( - STATE_ON, STATE_OFF, SERVICE_TURN_ON, SERVICE_TURN_OFF, EVENT_TIME_CHANGED) + ATTR_ENTITY_ID, EVENT_TIME_CHANGED, STATE_ON, SERVICE_TURN_ON, + SERVICE_TURN_OFF) DOMAIN = "script" +ENTITY_ID_FORMAT = DOMAIN + '.{}' DEPENDENCIES = ["group"] +STATE_NOT_RUNNING = 'Not Running' + CONF_ALIAS = "alias" -CONF_SERVICE = "execute_service" +CONF_SERVICE = "service" +CONF_SERVICE_OLD = "execute_service" CONF_SERVICE_DATA = "service_data" CONF_SEQUENCE = "sequence" CONF_EVENT = "event" CONF_EVENT_DATA = "event_data" CONF_DELAY = "delay" -ATTR_ENTITY_ID = "entity_id" + +ATTR_LAST_ACTION = 'last_action' _LOGGER = logging.getLogger(__name__) +def is_on(hass, entity_id): + """ Returns if the switch is on based on the statemachine. """ + return hass.states.is_state(entity_id, STATE_ON) + + +def turn_on(hass, entity_id): + """ Turn script on. """ + _, object_id = split_entity_id(entity_id) + + hass.services.call(DOMAIN, object_id) + + +def turn_off(hass, entity_id): + """ Turn script on. """ + hass.services.call(DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: entity_id}) + + def setup(hass, config): """ Load the scripts from the configuration. """ - scripts = [] + component = EntityComponent(_LOGGER, DOMAIN, hass) + + def service_handler(service): + """ Execute a service call to script.