HomeAutomationService.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. class HomeAutomationService {
  3. private static function DoRequest($endpoint, $args=array()) {
  4. $argsString=count($args)>0 ? implode('/'.$args) : "";
  5. $result=file_get_contents("http://has.robware.uk/$endpoint/$argsString");
  6. return json_decode($result);
  7. }
  8. public static function GetTemperature() {
  9. return self::DoRequest("gettemperature");
  10. }
  11. public static function GetOutsideTemperature() {
  12. return self::DoRequest("getoutsidetemperature");
  13. }
  14. public static function GetTargetTemperature() {
  15. return self::DoRequest("gettargettemperature");
  16. }
  17. public static function GetBothTemperatures() {
  18. return self::DoRequest("GetbothTemperatures");
  19. }
  20. public static function GetCurrentMode() {
  21. return self::DoRequest("getcurrentmode");
  22. }
  23. public static function SetTargetTemperature($temperature) {
  24. return self::DoRequest("settargettemperature", array($temperature));
  25. }
  26. public static function TakeReading() {
  27. $result=self::GetBothTemperatures();
  28. var_dump($result);
  29. $reading=new TemperatureReading();
  30. $reading->Inside=self::GetTemperature();
  31. $reading->Outside=self::GetOutsideTemperature();
  32. $reading->Save();
  33. return $reading;
  34. }
  35. }