/**
  * deletes the variable in ip-symcon
  *
  * @access public
  */
 public function delete()
 {
     IPS_DeleteVariable($this->id);
 }
Exemple #2
0
 protected function UnregisterVariable($Name)
 {
     $id = @IPS_GetObjectIDByIdent($Name, $this->InstanceID);
     if ($id > 0) {
         if (!IPS_VariableExists($id)) {
             throw new Exception('Variable not present', E_USER_NOTICE);
         }
         IPS_DeleteVariable($id);
     }
 }
Exemple #3
0
 protected function GetVariable($Ident, $VarType, $VarName, $Profile, $EnableAction)
 {
     $VarID = @$this->GetIDForIdent($Ident);
     if ($VarID > 0) {
         if (IPS_GetVariable($VarID)['VariableType'] != $VarType) {
             IPS_DeleteVariable($VarID);
             $VarID = false;
         }
     }
     if ($VarID === false) {
         $this->MaintainVariable($Ident, $VarName, $VarType, $Profile, 0, true);
         if ($EnableAction) {
             $this->MaintainAction($Ident, true);
         }
         $VarID = $this->GetIDForIdent($Ident);
     }
     return $VarID;
 }
Exemple #4
0
 /**
  * RegisterVariableByParent
  * @param integer $ParentID
  * @param string $Ident
  * @param string $Name
  * @param integer $Type
  * @param string $Profile
  * @param integer $Position
  * @return integer
  */
 private function RegisterVariableByParent($ParentID, $Ident, $Name, $Type, $Profile = "", $Position = 0)
 {
     if ($Profile !== "") {
         //prefer system profiles
         if (IPS_VariableProfileExists("~" . $Profile)) {
             $Profile = "~" . $Profile;
         }
         if (!IPS_VariableProfileExists($Profile)) {
             throw new Exception("Profile with name " . $Profile . " does not exist");
         }
     }
     //search for already available variables with proper ident
     $vid = @IPS_GetObjectIDByIdent($Ident, $ParentID);
     //properly update variableID
     if ($vid === false) {
         $vid = 0;
     }
     //we have a variable with the proper ident. check if it fits
     if ($vid > 0) {
         //check if we really have a variable
         if (!IPS_VariableExists($vid)) {
             throw new Exception("Ident with name " . $Ident . " is used for wrong object type");
         }
         //bail out
         //check for type mismatch
         if (IPS_GetVariable($vid)["VariableType"] != $Type) {
             //mismatch detected. delete this one. we will create a new below
             IPS_DeleteVariable($vid);
             //this will ensure, that a new one is created
             $vid = 0;
         }
     }
     //we need to create one
     if ($vid === 0) {
         $vid = IPS_CreateVariable($Type);
         //configure it
         IPS_SetParent($vid, $ParentID);
         IPS_SetIdent($vid, $Ident);
         IPS_SetName($vid, $Name);
         IPS_SetPosition($vid, $Position);
         //IPS_SetReadOnly($vid, true);
     }
     //update variable profile. profiles may be changed in module development.
     //this update does not affect any custom profile choices
     IPS_SetVariableCustomProfile($vid, $Profile);
     return $vid;
 }
Exemple #5
0
  public function ApplyData($data) {
    $data = (array)$data;
    $state = (array)$data['state'];

    /*
     * Properties
     */

    $dirty = false;

    $modelid = utf8_decode((string)$data['modelid']);
    $type = utf8_decode((string)$data['type']);
    $name = utf8_decode((string)$data['name']);
    if (IPS_GetProperty($this->InstanceID, 'ModelId') != $modelid) {
      IPS_SetProperty($this->InstanceID, 'ModelId', $modelid);
      $dirty = true;
    }
    if (IPS_GetProperty($this->InstanceID, 'Type') != $type) {
      IPS_SetProperty($this->InstanceID, 'Type', $type);
      $dirty = true;
    }
    if (IPS_GetName($this->InstanceID) != $name) {
      IPS_SetName($this->InstanceID, $name);
      $dirty = true;
    }

    // Setze den Modus
    if (isset($state['ct']) && isset($state['hue'])) {
      // HUE+CT Lamp
      $lightFeature = 0;
    } elseif(isset($state['hue'])) {
      // HUE Lamp
      $lightFeature = 1;
    } elseif(isset($state['ct'])) {
      // CT Lamp
      $lightFeature = 2;
    } else {
      // Lux Lamp
      $lightFeature = 3;
    }

    if (IPS_GetProperty($this->InstanceID, 'LightFeatures') != $lightFeature) {
      IPS_SetProperty($this->InstanceID, 'LightFeatures', $lightFeature);
      $dirty = true;
    }

    if ($dirty) IPS_ApplyChanges($this->InstanceID);

    /*
     * Variables
     */

    $stateId = $this->RegisterVariableBoolean("STATE", "Zustand", "~Switch");
    $this->EnableAction("STATE");
    IPS_SetPosition($stateId, 1);

    $cmId = $this->RegisterVariableInteger("COLOR_MODE", "Modus", "ColorModeSelect.Hue");
    $this->EnableAction("COLOR_MODE");
    IPS_SetPosition($cmId, 2);
    IPS_SetIcon($cmId, 'ArrowRight');

    $briId = $this->RegisterVariableInteger("BRIGHTNESS", "Helligkeit", "~Intensity.100");
    $this->EnableAction("BRIGHTNESS");
    IPS_SetIcon($briId, 'Sun');
    IPS_SetPosition($briId, 5);

    if ($lightFeature == 0 || $lightFeature == 1) {
      $hueId = $this->RegisterVariableInteger("HUE", "Hue");
      IPS_SetHidden($hueId, true);
    } else {
      $delete = @IPS_GetObjectIDByIdent("HUE", $this->InstanceID);
      if ($delete !== false) IPS_DeleteVariable($delete);
    }

    if ($lightFeature == 0) {
      IPS_SetVariableCustomProfile($cmId, 'ColorModeSelect.Hue');
      IPS_SetHidden($cmId, false);
    } else {
      IPS_SetHidden($cmId, true);
    }

    if ($lightFeature == 0 || $lightFeature == 2) {
      $ctId = $this->RegisterVariableInteger("COLOR_TEMPERATURE", "Farbtemperatur", "~Intensity.100");
      $this->EnableAction("COLOR_TEMPERATURE");
      IPS_SetIcon($ctId, 'Bulb');
      IPS_SetPosition($ctId, 4);
    } else {
      $delete = @IPS_GetObjectIDByIdent("COLOR_TEMPERATURE", $this->InstanceID);
      if ($delete !== false) IPS_DeleteVariable($delete);
    }

    if ($lightFeature == 0 || $lightFeature == 1) {
      $colorId = $this->RegisterVariableInteger("COLOR", "Farbe", "~HexColor");
      $this->EnableAction("COLOR");
      IPS_SetPosition($colorId, 3);
      IPS_SetIcon($colorId, 'Bulb');

      $satId = $this->RegisterVariableInteger("SATURATION", utf8_decode("Sättigung"), "~Intensity.100");
      $this->EnableAction("SATURATION");
      IPS_SetIcon($satId, 'Intensity');
      IPS_SetPosition($satId, 6);

    } else {
      $delete = @IPS_GetObjectIDByIdent("COLOR", $this->InstanceID);
      if ($delete !== false) IPS_DeleteVariable($delete);
      $delete = @IPS_GetObjectIDByIdent("SATURATION", $this->InstanceID);
      if ($delete !== false) IPS_DeleteVariable($delete);
    }

    /*
     * Values
     */

    SetValueBoolean($stateId, $state['on']);
    SetValueInteger($briId, round($state['bri'] * 100 / 254));
    if (@$satId) SetValueInteger($satId, round($state['sat'] * 100 / 254));
    if (@$hueId) SetValueInteger($hueId, $state['hue']);
    if (@$ctId) SetValueInteger($ctId, 100 - round(( $state['ct'] - 153) * 100 / 347));

    switch (@$state['colormode']) {
      case 'xy':
      case 'hs':
        $hex = $this->HSV2HEX($state['hue'], $state['sat'], $state['bri']);
        SetValueInteger($colorId, hexdec($hex));
        IPS_SetHidden($colorId, false);
        IPS_SetHidden($satId, false);
        if (@$ctId) IPS_SetHidden($ctId, true);
        if (@$cmId) SetValueInteger($cmId, 0);
        break;
      case 'ct':
        if(@$colorId) IPS_SetHidden($colorId, true);
        if(@$satId) IPS_SetHidden($satId, true);
        IPS_SetHidden($ctId, false);
        SetValueInteger($cmId, 1);
        break;
    }
  }
 /**
  * Delete a Variable by name if exists and assigned events
  * @param String $ident
  */
 protected function drop_var($ident)
 {
     //use logmessages instead of debug because this isnt available in early stage
     //IPS_LogMessage($this->name, __FUNCTION__ . "(#".$this->InstanceID.") Drop Var $ident");
     $vid = @$this->GetIDForIdent($ident);
     if ($vid > 0 && IPS_VariableExists($vid)) {
         $events = IPS_GetVariableEventList($vid);
         foreach ($events as $ev) {
             @IPS_DeleteEvent($ev);
         }
         @IPS_DeleteVariable($vid);
         return;
     }
     IPS_LogMessage($this->name, __FUNCTION__ . "(#" . $this->InstanceID . ") Error Variable {$ident} not found");
 }