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); }
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; } } } $Associations = IPS_GetVariableProfile("Radio.SONOS")["Associations"]; if (isset($playingRadioStation)) { foreach ($Associations as $key => $station) { if ($station["Name"] == $playingRadioStation) { $currentStation = $station["Value"]; break; } } }