""" homeassistant.components.script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ entity_id Scripts are a sequence of actions that can be triggered manually 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.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 ( 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 = "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_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. """ component = EntityComponent(_LOGGER, DOMAIN, hass) def service_handler(service): """ Execute a service call to script.