Ejemplo n.º 1
0
 private function SetCover()
 {
     $CoverID = @IPS_GetObjectIDByIdent('CoverIMG', $this->InstanceID);
     if ($CoverID === false) {
         $CoverID = IPS_CreateMedia(1);
         IPS_SetParent($CoverID, $this->InstanceID);
         IPS_SetIdent($CoverID, 'CoverIMG');
         IPS_SetName($CoverID, 'Cover');
         IPS_SetPosition($CoverID, 27);
         IPS_SetMediaCached($CoverID, true);
         IPS_SetMediaFile($CoverID, "media" . DIRECTORY_SEPARATOR . "Cover_" . $this->InstanceID . ".png", False);
     }
     $ParentID = $this->GetParent();
     if (!($ParentID === false)) {
         $Host = IPS_GetProperty($ParentID, 'Host') . ":" . IPS_GetProperty($ParentID, 'Webport');
         $Size = $this->ReadPropertyString("CoverSize");
         $PlayerID = rawurlencode($this->Address);
         $CoverRAW = @Sys_GetURLContent("http://" . $Host . "/music/current/" . $Size . ".png?player=" . $PlayerID);
         if (!($CoverRAW === false)) {
             IPS_SetMediaContent($CoverID, base64_encode($CoverRAW));
         }
     }
     return;
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
		/**
		* This function will be available automatically after the module is imported with the module control.
		* Using the custom prefix this function will be callable from PHP and JSON-RPC through:
		*
		* LJ_GenerateShutter($id, $Start, $End);
		*
		*/
		public function GenerateShutter($Start, $End)
		{
			
			$qid = @IPS_GetObjectIDByIdent("KNXQuick", 0);
			if($qid === false) {
				$qid = IPS_CreateCategory();
				IPS_SetName($qid, "KNX quick");
				IPS_SetIdent($qid, "KNXQuick");
			}
			
			$sid = @IPS_GetObjectIDByIdent("Shutter", $qid);
			if($sid === false) {
				$sid = IPS_CreateCategory();
				IPS_SetName($sid, "Shutter");
				IPS_SetIdent($sid, "Shutter");
				IPS_SetParent($sid, $qid);
				IPS_SetPosition($sid, 2);
			}
			
			for($i=$Start; $i<=$End; $i++) {
				for($j=0; $j<=9; $j++) {
					$iid = @IPS_GetObjectIDByIdent("Shutter".strtoupper(dechex($i).$j), $sid);
					if($iid === false) {
						$iid = IPS_CreateInstance("{24A9D68D-7B98-4D74-9BAE-3645D435A9EF}");
						IPS_SetName($iid, "Shutter (Group ".strtoupper(dechex($i)).", Channel ".$j.")");
						IPS_SetIdent($iid, "Shutter".strtoupper(dechex($i)).$j);
						IPS_SetParent($iid, $sid);
						IPS_SetProperty($iid, "GroupMoveAddress1", 14);
						IPS_SetProperty($iid, "GroupMoveAddress2", 0);
						IPS_SetProperty($iid, "GroupMoveAddress3", ($i*16)+$j);
						IPS_SetProperty($iid, "GroupStopAddress1", 14);
						IPS_SetProperty($iid, "GroupStopAddress2", 1);
						IPS_SetProperty($iid, "GroupStopAddress3", ($i*16)+$j);
						if($j > 0) {
							$mapping = Array();
							$mapping[] = Array(
								"GroupAddress1" => 14,
								"GroupAddress2" => 0,
								"GroupAddress3" => $i*16
							);
							$mapping[] = Array(
								"GroupAddress1" => 14,
								"GroupAddress2" => 0,
								"GroupAddress3" => 240
							);
							$mapping[] = Array(
								"GroupAddress1" => 14,
								"GroupAddress2" => 0,
								"GroupAddress3" => 240+$j
							);
							IPS_SetProperty($iid, "GroupMoveMapping", json_encode($mapping));
							$mapping = Array();
							$mapping[] = Array(
								"GroupAddress1" => 14,
								"GroupAddress2" => 1,
								"GroupAddress3" => $i*16
							);
							$mapping[] = Array(
								"GroupAddress1" => 14,
								"GroupAddress2" => 1,
								"GroupAddress3" => 240
							);
							$mapping[] = Array(
								"GroupAddress1" => 14,
								"GroupAddress2" => 1,
								"GroupAddress3" => 240+$j
							);
							IPS_SetProperty($iid, "GroupStopMapping", json_encode($mapping));
						}
						IPS_ApplyChanges($iid);
					}
				}
			}
			
			echo "Done.";
			
		}		
Ejemplo n.º 4
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;
    }
  }
Ejemplo n.º 5
0
 protected function RegisterTimer($Name, $Interval, $Script, $Position = 99)
 {
     $id = @IPS_GetObjectIDByIdent($Name, $this->InstanceID);
     if ($id === false) {
         $id = 0;
     }
     if ($id > 0) {
         if (!IPS_EventExists($id)) {
             throw new Exception("Ident with name " . $Name . " is used for wrong object type", E_USER_WARNING);
         }
         if (IPS_GetEvent($id)['EventType'] != 1) {
             IPS_DeleteEvent($id);
             $id = 0;
         }
     }
     if ($id == 0) {
         $id = IPS_CreateEvent(1);
         IPS_SetParent($id, $this->InstanceID);
         IPS_SetIdent($id, $Name);
     }
     IPS_SetName($id, $Name);
     IPS_SetHidden($id, true);
     IPS_SetEventScript($id, $Script);
     IPS_SetPosition($id, $Position);
     if ($Interval > 0) {
         IPS_SetEventCyclic($id, 0, 0, 0, 0, 1, $Interval);
         IPS_SetEventActive($id, true);
     } else {
         IPS_SetEventCyclic($id, 0, 0, 0, 0, 1, 1);
         IPS_SetEventActive($id, false);
     }
 }