public function ApplyChanges() { //Never delete this line! parent::ApplyChanges(); $this->RegisterProfileIntegerEx("Status.SONOS", "Information", "", "", array(array(0, "Prev", "", -1), array(1, "Play", "", -1), array(2, "Pause", "", -1), array(3, "Next", "", -1))); $this->RegisterProfileInteger("Volume.SONOS", "Intensity", "", " %", 0, 100, 1); //Build Associations according to user settings include __DIR__ . "/radio_stations.php"; $Associations = array(); $AvailableStations = get_available_stations(); $WebFrontStations = $this->ReadPropertyString("WebFrontStations"); $WebFrontStationsArray = explode(",", $WebFrontStations); $FavoriteStation = $this->ReadPropertyString("FavoriteStation"); $Value = 0; foreach ($AvailableStations as $key => $val) { if (in_array($val['name'], $WebFrontStationsArray) || $WebFrontStations === "<alle>") { if ($val['name'] === $FavoriteStation) { $Color = 0xfcec00; } else { $Color = -1; } $Associations[] = array($Value++, $val['name'], "", $Color); } } if (IPS_VariableProfileExists("Radio.SONOS")) { IPS_DeleteVariableProfile("Radio.SONOS"); } $this->RegisterProfileIntegerEx("Radio.SONOS", "Speaker", "", "", $Associations); $this->RegisterVariableInteger("Status", "Status", "Status.SONOS"); $this->EnableAction("Status"); $this->RegisterVariableInteger("Volume", "Volume", "Volume.SONOS"); $this->EnableAction("Volume"); $this->RegisterVariableInteger("Radio", "Radio", "Radio.SONOS"); $this->EnableAction("Radio"); }
function get_station_url($name, $RadioStations = null) { if ($RadioStations === null) { $RadioStations = get_available_stations(); } foreach ($RadioStations as $key => $val) { if ($val['name'] === $name) { return $RadioStations[$key]['url']; } } }
function get_station_url($name, $RadioStations = null) { if ($RadioStations === null) { $RadioStations = get_available_stations(); } foreach ($RadioStations as $key => $val) { if ($val['name'] === $name) { return $RadioStations[$key]['url']; } } throw new Exception("Radio station " . $name . " is unknown"); }
public function UpdateRadioStations() { include_once __DIR__ . "/radio_stations.php"; $Associations = array(); $AvailableStations = get_available_stations(); $WebFrontStations = $this->ReadPropertyString("WebFrontStations"); $WebFrontStationsArray = array_map("trim", explode(",", $WebFrontStations)); $FavoriteStation = $this->ReadPropertyString("FavoriteStation"); $Value = 1; foreach ($AvailableStations as $key => $val) { if (in_array($val['name'], $WebFrontStationsArray) || $WebFrontStations === "<alle>" || $WebFrontStations === "<all>") { if ($val['name'] === $FavoriteStation) { $Color = 0xfcec00; } else { $Color = -1; } $Associations[] = array($Value++, $val['name'], "", $Color); // associations only support up to 32 variables if ($Value === 33) { break; } } } if ($this->ReadPropertyString("IncludeTunein") && $Value < 33) { $ip = $this->ReadPropertyString("IPAddress"); $timeout = $this->ReadPropertyString("TimeOut"); if ($timeout && Sys_Ping($ip, $timeout) != true) { throw new Exception("Sonos Box " . $ip . " is not available"); } include_once __DIR__ . "/sonosAccess.php"; $sonos = new SonosAccess($ip); foreach ((new SimpleXMLElement($sonos->BrowseContentDirectory('R:0/0')['Result']))->item as $item) { $Associations[] = array($Value++, (string) $item->xpath('dc:title')[0], "", 0x539de1); // associations only support up to 32 variables if ($Value === 33) { break; } } } usort($Associations, function ($a, $b) { return strnatcmp($a[1], $b[1]); }); $Value = 1; foreach ($Associations as $Association) { $Associations[$Value - 1][0] = $Value++; } if (IPS_VariableProfileExists("Radio.SONOS")) { IPS_DeleteVariableProfile("Radio.SONOS"); } $this->RegisterProfileIntegerEx("Radio.SONOS", "Speaker", "", "", $Associations); }
SetValueInteger(IPS_GetObjectIDByName("Status", IPS_GetParent($_IPS["SELF"])), $status); // Titelanzeige $currentStation = 0; if ($status != 1) { // No title if not playing $actuallyPlaying = ""; } else { $positionInfo = $sonos->GetPositionInfo(); $mediaInfo = $sonos->GetMediaInfo(); if (strlen($positionInfo["streamContent"]) != 0) { $actuallyPlaying = $positionInfo["streamContent"]; } else { $actuallyPlaying = utf8_decode($positionInfo["title"] . " | " . $positionInfo["artist"]); } // start find current Radio in VariableProfile $radioStations = get_available_stations(); $playingRadioStation = ''; foreach ($radioStations as $radioStation) { if ($radioStation["url"] == htmlspecialchars_decode($mediaInfo["CurrentURI"])) { $playingRadioStation = $radioStation["name"]; break; } } if ($playingRadioStation == '') { foreach ((new SimpleXMLElement($sonos->BrowseContentDirectory('R:0/0')['Result']))->item as $item) { if ($item->res == htmlspecialchars_decode($mediaInfo["CurrentURI"])) { $playingRadioStation = (string) $item->xpath('dc:title')[0]; break; } } }