def run(self, variables=None):
        """Run script."""
        with self._lock:
            if self._cur == -1:
                self._log('Running script')
                self._cur = 0

            # Unregister callback if we were in a delay but turn on is called
            # again. In that case we just continue execution.
            self._remove_listener()

            for cur, action in islice(enumerate(self.sequence), self._cur,
                                      None):

                if CONF_DELAY in action:
                    # Call ourselves in the future to continue work
                    def script_delay(now):
                        """Called after delay is done."""
                        self._delay_listener = None
                        self.run(variables)

                    self._delay_listener = track_point_in_utc_time(
                        self.hass, script_delay,
                        date_util.utcnow() + action[CONF_DELAY])
                    self._cur = cur + 1
                    if self._change_listener:
                        self._change_listener()
                    return

                elif CONF_CONDITION in action:
                    if not self._check_condition(action, variables):
                        break

                elif CONF_EVENT in action:
                    self._fire_event(action)

                else:
                    self._call_service(action, variables)

            self._cur = -1
            self.last_action = None
            if self._change_listener:
                self._change_listener()
dataset/ETHPy150Open home-assistant/home-assistant/homeassistant/helpers/script.py/Script.run/original