<?php

class HomeAutomationService {

	private static function DoRequest($endpoint, $args=array()) {
		$argsString=count($args)>0 ? implode('/'.$args) : "";
		$result=file_get_contents("http://has.robware.uk/$endpoint/$argsString");
		return json_decode($result);
	}

	public static function GetTemperature() {
		return self::DoRequest("gettemperature");
	}

	public static function GetOutsideTemperature() {
		return self::DoRequest("getoutsidetemperature");
	}

	public static function GetTargetTemperature() {
		return self::DoRequest("gettargettemperature");
	}

	public static function GetBothTemperatures() {
		return self::DoRequest("GetbothTemperatures");
	}

	public static function GetCurrentMode() {
		return self::DoRequest("getcurrentmode");
	}

	public static function SetTargetTemperature($temperature) {
		return self::DoRequest("settargettemperature", array($temperature));
	}

	public static function TakeReading() {
		$result=self::GetBothTemperatures();
		var_dump($result);
		$reading=new TemperatureReading();
		$reading->Inside=self::GetTemperature();
		$reading->Outside=self::GetOutsideTemperature();
		$reading->Save();

		return $reading;
	}
}
