/**
  * checks if the variable logging state fits the settings
  * if not this method will update the variable logging
  *
  * @throws Exception if $archiveId is not set while logging is enabled
  * @access private
  */
 private function verifyVariableLogging()
 {
     if ($this->enableLogging) {
         if ($this->archiveId == NULL) {
             throw new Exception("Parameter \$archiveId is not set but \$enableLogging is true");
         }
         if ($this->checkArchive($this->archiveId)) {
             if (!AC_GetLoggingStatus($this->archiveId, $this->id)) {
                 AC_SetLoggingStatus($this->archiveId, $this->id, true);
                 AC_SetAggregationType($this->archiveId, $this->id, $this->aggregationType);
                 IPS_ApplyChanges($this->archiveId);
             }
         }
     } else {
         //todo: disable logging not implemented
     }
 }
Пример #2
0
 public function ApplyChanges()
 {
     //Never delete this line!
     parent::ApplyChanges();
     $ArchivID = IPS_GetInstanceListByModuleID("{43192F0B-135B-4CE7-A0A7-1475603F3060}");
     $ArchivID = $ArchivID[0];
     $this->RegisterProfile(1, "WITHINGS_M_Groesse", "Gauge", "", " cm");
     $this->RegisterProfile(1, "WITHINGS_M_Puls", "Graph", "", " bpm");
     $this->RegisterProfile(2, "WITHINGS_M_Kilo", "", "", " kg", false, false, false, 1);
     $this->RegisterProfile(2, "WITHINGS_M_Prozent", "", "", " %", false, false, false, 1);
     $this->RegisterProfile(2, "WITHINGS_M_BMI", "", "", " kg/m²", false, false, false, 1);
     $this->RegisterProfile(1, "WITHINGS_M_Blutdruck", "", "", " mmHg");
     $this->RegisterProfileGender("WITHINGS_M_Gender", "", "", "", array(array(0, "maennlich", "", 0xff), array(1, "weiblich", "", 0xff0000)));
     $id = $this->RegisterVariableString("name", "Name", "~String", 0);
     $id = $this->RegisterVariableInteger("gender", "Geschlecht", "WITHINGS_M_Gender", 2);
     $id = $this->RegisterVariableString("birthdate", "Geburtstag", "~String", 1);
     $id = $this->RegisterVariableInteger("height", "Groesse", "WITHINGS_M_Groesse", 3);
     $parent = IPS_GetParent($id);
     $CatID = false;
     if ($this->ReadPropertyBoolean("BloodMeasures") == true) {
         $CatID = $this->CreateKategorie("Blutdruck", $parent);
         if ($CatID === false) {
             throw new Exception("Kategorie Blutdruck nicht definiert");
         }
         $VariablenID = @IPS_GetVariableIDByName("Diastolic", $CatID);
         if ($VariablenID === false) {
             $id = $this->RegisterVariableInteger("diastolicblood", "Diastolic", "WITHINGS_M_Blutdruck", 2);
             IPS_SetParent($id, $CatID);
         }
         $VariablenID = @IPS_GetVariableIDByName("Systolic", $CatID);
         if ($VariablenID === false) {
             $id = $this->RegisterVariableInteger("systolicblood", "Systolic", "WITHINGS_M_Blutdruck", 1);
             IPS_SetParent($id, $CatID);
         }
         $VariablenID = @IPS_GetVariableIDByName("Puls", $CatID);
         if ($VariablenID === false) {
             $id = $this->RegisterVariableInteger("heartpulse", "Puls", "WITHINGS_M_Puls", 3);
             IPS_SetParent($id, $CatID);
         }
         $VariablenID = @IPS_GetVariableIDByName("DatumUhrzeit", $CatID);
         if ($VariablenID === false) {
             $id = $this->RegisterVariableInteger("timestamp", "DatumUhrzeit", "~UnixTimestamp", 0);
             IPS_SetParent($id, $CatID);
         }
     }
     $logging = $this->ReadPropertyBoolean("BloodLogging");
     if ($CatID) {
         if ($logging) {
             $this->Logging("BloodLogging wird eingeschaltet");
         } else {
             $this->Logging("BloodLogging wird ausgeschaltet");
         }
         $id = IPS_GetVariableIDByName("Diastolic", $CatID);
         if (AC_GetLoggingStatus($ArchivID, $id) != $logging) {
             AC_SetLoggingStatus($ArchivID, $id, $logging);
             IPS_ApplyChanges($ArchivID);
         }
         $id = IPS_GetVariableIDByName("Systolic", $CatID);
         if (AC_GetLoggingStatus($ArchivID, $id) != $logging) {
             AC_SetLoggingStatus($ArchivID, $id, $logging);
             IPS_ApplyChanges($ArchivID);
         }
         $id = IPS_GetVariableIDByName("Puls", $CatID);
         if (AC_GetLoggingStatus($ArchivID, $id) != $logging) {
             AC_SetLoggingStatus($ArchivID, $id, $logging);
             IPS_ApplyChanges($ArchivID);
         }
         $status = $this->ReadPropertyBoolean("BloodVisible");
         $this->KategorieEnable($parent, "Blutdruck", $status);
     }
     $CatID = false;
     if ($this->ReadPropertyBoolean("BodyMeasures") == true) {
         $CatID = $this->CreateKategorie("Waage", $parent);
         if ($CatID === false) {
             throw new Exception("Kategorie Waage nicht definiert");
         }
         $VariablenID = @IPS_GetVariableIDByName("DatumUhrzeit", $CatID);
         if ($VariablenID === false) {
             $id = $this->RegisterVariableInteger("timestamp", "DatumUhrzeit", "~UnixTimestamp", 0);
             IPS_SetParent($id, $CatID);
         }
         $VariablenID = @IPS_GetVariableIDByName("Gewicht", $CatID);
         if ($VariablenID === false) {
             $id = $this->RegisterVariableFloat("weight", "Gewicht", "WITHINGS_M_Kilo", 1);
             IPS_SetParent($id, $CatID);
         }
         $VariablenID = @IPS_GetVariableIDByName("Fettfrei Anteil", $CatID);
         if ($VariablenID === false) {
             $id = $this->RegisterVariableFloat("fatfree", "Fettfrei Anteil", "WITHINGS_M_Kilo", 3);
             IPS_SetParent($id, $CatID);
         }
         $VariablenID = @IPS_GetVariableIDByName("Fett Anteil", $CatID);
         if ($VariablenID === false) {
             $id = $this->RegisterVariableFloat("fatmassweight", "Fett Anteil", "WITHINGS_M_Kilo", 2);
             IPS_SetParent($id, $CatID);
         }
         $VariablenID = @IPS_GetVariableIDByName("Fett Prozent", $CatID);
         if ($VariablenID === false) {
             $id = $this->RegisterVariableFloat("fatradio", "Fett Prozent", "WITHINGS_M_Prozent", 4);
             IPS_SetParent($id, $CatID);
         }
         $VariablenID = @IPS_GetVariableIDByName("BMI", $CatID);
         if ($VariablenID === false) {
             $id = $this->RegisterVariableFloat("bmi", "BMI", "WITHINGS_M_BMI", 5);
             IPS_SetParent($id, $CatID);
         } else {
             @IPS_SetVariableCustomProfile($VariablenID, "WITHINGS_M_BMI");
         }
         if ($this->ReadPropertyBoolean("BodyPuls") == true) {
             $VariablenID = @IPS_GetVariableIDByName("Puls", $CatID);
             if ($VariablenID === false) {
                 $id = $this->RegisterVariableInteger("heartpulse", "Puls", "WITHINGS_M_Puls", 3);
                 IPS_SetParent($id, $CatID);
             }
         }
     }
     $logging = $this->ReadPropertyBoolean("BodyLogging");
     if ($CatID) {
         if ($logging) {
             $this->Logging("BodyLogging wird eingeschaltet");
         } else {
             $this->Logging("BodyLogging wird ausgeschaltet");
         }
         $id = IPS_GetVariableIDByName("Gewicht", $CatID);
         if (AC_GetLoggingStatus($ArchivID, $id) != $logging) {
             AC_SetLoggingStatus($ArchivID, $id, $logging);
             IPS_ApplyChanges($ArchivID);
         }
         $id = IPS_GetVariableIDByName("Fettfrei Anteil", $CatID);
         if (AC_GetLoggingStatus($ArchivID, $id) != $logging) {
             AC_SetLoggingStatus($ArchivID, $id, $logging);
             IPS_ApplyChanges($ArchivID);
         }
         $id = IPS_GetVariableIDByName("Fett Anteil", $CatID);
         if (AC_GetLoggingStatus($ArchivID, $id) != $logging) {
             AC_SetLoggingStatus($ArchivID, $id, $logging);
             IPS_ApplyChanges($ArchivID);
         }
         $id = IPS_GetVariableIDByName("Fett Prozent", $CatID);
         if (AC_GetLoggingStatus($ArchivID, $id) != $logging) {
             AC_SetLoggingStatus($ArchivID, $id, $logging);
             IPS_ApplyChanges($ArchivID);
         }
         $id = IPS_GetVariableIDByName("BMI", $CatID);
         if (AC_GetLoggingStatus($ArchivID, $id) != $logging) {
             AC_SetLoggingStatus($ArchivID, $id, $logging);
             IPS_ApplyChanges($ArchivID);
         }
         $id = @IPS_GetVariableIDByName("Puls", $CatID);
         if ($id > 0) {
             if (AC_GetLoggingStatus($ArchivID, $id) != $logging) {
                 AC_SetLoggingStatus($ArchivID, $id, $logging);
                 IPS_ApplyChanges($ArchivID);
             }
         }
     }
     $status = $this->ReadPropertyBoolean("BodyVisible");
     $this->KategorieEnable($parent, "Waage", $status);
     //Timer erstellen
     $this->SetTimerInterval("WIT_UpdateTimer", $this->ReadPropertyInteger("Intervall"));
     //Update
     $this->Update();
 }