var RunLoop = require('./RunLoop').RunLoop,
    CurrentTemperatureProvider = require('./CurrentTemperatureProvider').CurrentTemperatureProvider,
    TargetTemperatureProvider = require('./TargetTemperatureProvider').TargetTemperatureProvider,
    HeatingControl = require('./HeatingControl').HeatingControl
    CallForHeatCommandFactory = require('./CallForHeatCommandFactory')
;

var DEFAULTS = {
    INTERVAL_SECONDS : 30,
    SENSOR_DATA_PATH : "/var/lib/homecontrol/sensordata/temperatureSensors/TA"
};

function usage() {
    console.log("Usage: node index.js [-i <INTERVAL_IN_SECONDS>] [-sensorpath <SENSOR_DATA_PATH>]");
    console.log("         -i    the interval between comparing temperatures and calling for heat");
    console.log("-sensorpath    path at which temperature sensor readings can be read");
    process.exit();
}

function parseArgs() {
    var args = {
        updateIntervalSeconds : DEFAULTS.INTERVAL_SECONDS,
        sensorDataPath : DEFAULTS.SENSOR_DATA_PATH
    };

    for(var argi = 2; argi < process.argv.length; argi++) {
        if(process.argv[argi] === '-i') {
            args.updateIntervalSeconds = parseInt(process.argv[++argi]) || usage();
        }
        else if(process.argv[argi] === '-sensorpath') {
            args.sensorDataPath = process.argv[++argi] || usage();
        }
        else {
            usage();
        }
    }

    return args;
}

function start(args) {
    console.log("Starting heatingd...");

    console.log("Monitoring temperature every " + args.updateIntervalSeconds + " seconds.");
    console.log("Monitoring temperatures from sensor path: " + args.sensorDataPath);

    var heatingControl = new HeatingControl(
        new TargetTemperatureProvider(),
        new CurrentTemperatureProvider(args.sensorDataPath),
        new CallForHeatCommandFactory.CallForHeatOnCommand(),
        new CallForHeatCommandFactory.CallForHeatOffCommand()
    );

    heatingControl.onInterval();
    var runloop = new RunLoop(args.updateIntervalSeconds * 1000, function() {
        heatingControl.onInterval();
    });
    runloop.start();
}

parseArgs();
start(parseArgs());

@@ -412,16 +412,19 @@
 SECONDS 
+   
 : 30,%0A  
@@ -442,16 +442,19 @@
 TA_PATH 
+   
 : %22/var/
@@ -502,16 +502,79 @@
 sors/TA%22
+,%0A    PROGRAMME_DATA_PATH : %22/var/lib/homecontrol/programdata/%22
 %0A%7D;%0A%0Afun
@@ -612,16 +612,39 @@
 (%22Usage:
+ %22);%0A    console.log(%22 
  node in
@@ -709,24 +709,107 @@
 A_PATH%3E%5D%22);%0A
+    console.log(%22       %5B-programme %3CPROGRAMME_DATA_PATH%3E%5D%22);%0A    console.log(%22%22);%0A
     console.
@@ -981,24 +981,110 @@
  be read%22);%0A
+    console.log(%22 -programme    path at which programme/schedule data can be found%22);%0A
     process.
@@ -1247,15 +1247,235 @@
 PATH
+,%0A        programmeDataPath : DEFAULTS.PROGRAMME_DATA_PATH%0A    %7D;%0A%0A    function hasArg(arg) %7B%0A        return process.argv%5Bargi%5D === arg;%0A    %7D%0A%0A    function readArgValue() %7B%0A        return process.argv%5B++argi%5D %7C%7C usage();
 %0A    %7D
-;
 %0A%0A  
@@ -1547,36 +1547,21 @@
  if(
-process.argv%5Bargi%5D === 
+hasArg(
 '-i')
+)
  %7B%0A 
@@ -1609,36 +1609,30 @@
 arseInt(
-process.argv%5B++argi%5D
+readArgValue()
 ) %7C%7C usa
@@ -1663,39 +1663,23 @@
 else if(
-process.argv%5Bargi%5D === 
+hasArg(
 '-sensor
@@ -1684,16 +1684,17 @@
 orpath')
+)
  %7B%0A     
@@ -1726,36 +1726,122 @@
 h = 
-process.argv%5B++argi%5D %7C%7C usag
+readArgValue();%0A        %7D%0A        else if(hasArg('-programme')) %7B%0A            args.programmeDataPath = readArgValu
 e();
@@ -2166,16 +2166,108 @@
 taPath);
+%0A    console.log(%22Monitoring programme/schedule data from path: %22 + args.programmeDataPath);
 %0A%0A    va

read programme data path arg