Esempio n. 1
0
 public function setRadio()
 {
     // reset values
     SetValue($this->GetIDForIdent("DeviceMode"), "");
     SetValue($this->GetIDForIdent("DeviceState"), "");
     SetValue($this->GetIDForIdent("NowPlaying"), "");
     SetValue($this->GetIDForIdent("Description"), "");
     SetValue($this->GetIDForIdent("Logo"), "");
     // get radio
     $instanceid = IPS_GetInstance($this->InstanceID)['InstanceID'];
     $stationname = GetValueFormatted($this->GetIDForIdent("Radio"));
     $associations = IPS_GetVariableProfile("bose.Device" . $instanceid . "RadioStations")["Associations"];
     foreach ($associations as $key => $value) {
         if ($value["Name"] == $stationname) {
             $index = $value["Value"];
         }
     }
     $associations = IPS_GetVariableProfile("bose.Device" . $instanceid . "RadioLocations")["Associations"];
     foreach ($associations as $key => $value) {
         if ($value["Value"] == $index) {
             $location = $value["Name"];
         }
     }
     // set location
     $timeout = $this->ReadPropertyString("Timeout");
     $deviceip = $this->ReadPropertyString("DeviceIP");
     try {
         if ($timeout && Sys_Ping($deviceip, $timeout) != true) {
             throw new Exception("Device " . $deviceip . " is not available");
         }
         include_once __DIR__ . "/bose_soundtouch_api.php";
         $bosedevice = new BoseSoundTouchAPI($deviceip);
         $result = $bosedevice->setDeviceRadioStationAPI($location);
         // get now playing ???
         SetValue($this->GetIDForIdent("DevicePower"), true);
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
Esempio n. 2
0
		private function AddObjectVariable($link, $id, $name, $position) {
			$value        = GetValue($id);
			$variable     = IPS_GetVariable($id);
			$action       = $variable['VariableCustomAction'] ;
			$type         = $variable['VariableValue']['ValueType'];
			$profile      = $variable['VariableCustomProfile'];
			if ($profile=='') return;
			$profileData  = IPS_GetVariableProfile($profile);
			$associations = $profileData['Associations'];
			$color        = -1;

			$object = array();
			$object['Id']             = $id;
			$object['Link']           = $link;
			$object['Name']           = $name;
			$object['Position']       = $position;
			$object['ValueFormatted'] = GetValueFormatted($id);
			$object['ObjectType']     = 'Variable';
			$object['DisplayType']    = 'Text';
			$object['BlockBegin']     = true;
			$object['BlockEnd']       = true;
			$object['Width']          = 100;
			$object['LineIdx']        = 0;
			$object['Suffix']         = $profileData['Suffix'];
			$object['Prefix']         = $profileData['Prefix'];
			$object['MaxValue']       = $profileData['MaxValue'];
			$object['MinValue']       = $profileData['MinValue'];
			$object['StepSize']       = $profileData['StepSize'];

			switch($type) {
			   case 0: // Boolean
					$object['DisplayType'] = 'Switch';
				   $value = $value ? 1 : 0;
				   $object['Value'] = $value;
					if (array_key_exists($value, $associations)) $color = $associations[$value]['Color'];
			      break;
			   case 1: // Integer
					$object['Value']          = $value;
			      if ($object['Suffix'] == '%') {
						$object['DisplayType']    =  'BarGraph';
				   } else if (count($profileData['Associations']) > 0) {
						$object['DisplayType'] = $this->GetDisplayAttributte($link, 'DisplayType', 'Switch');
						$object['Value']       = ""; // Call Edit Mode
						if ($object['DisplayType']=='Inline' or $object['DisplayType']=='Block') {
						   $this->AddObjectVariableValues($object, $associations, $value, 'Variable');
						   return;
						}
				   } else {
					}
					if (array_key_exists($value, $associations)) $color = $associations[$value]['Color'];
			      break;
			   case 2: // Float
					$object['Value']          = floatval($value);
			      break;
			   case 3: // String
					$object['Value']          = $value;
					if ($profile=='~HTMLBox') return; // Text
			      break;
			   default: // Unsupported Datatype
			}
			
			$object['DisplayType'] = $this->GetDisplayAttributte($link, 'DisplayType', $object['DisplayType']);
			if ($action==0 and $object['DisplayType']<>'Text' and $object['DisplayType']<>'BigText') {
				$object['DisplayType'] = 'Text';
			}

			if ($color==-1) $color = 150*256*256+150*256+150;
			$red    = floor($color/256/256);
			$green  = floor(($color-$red*256*256)/256);
			$blue   = floor(($color-$red*256*256-$green*256));
			$object['Color']  =  $color;
			$object['Red']    =  $red;
			$object['Green']  =  $green;
			$object['Blue']   =  $blue;
			$this->objectList[] = $object;

			if (GetValue($this->objectEditId)==$id) {
				$this->AddObjectVariableValues($object, $associations, $value, 'Edit');
			}
		}