Exemplo n.º 1
0
<?php

include_once "../modules/SymconSonos/Sonos/sonosAccess.php";
include_once "../modules/SymconSonos/Sonos/radio_stations.php";
$ip = IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "IPAddress");
$timeout = IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "TimeOut");
if (!$timeout || Sys_Ping($ip, $timeout) == true) {
    $sonos = new SonosAccess($ip);
    $status = $sonos->GetTransportInfo();
    SetValueInteger(IPS_GetObjectIDByName("Volume", IPS_GetParent($_IPS["SELF"])), $sonos->GetVolume());
    if (IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "MuteControl")) {
        SetValueInteger(IPS_GetObjectIDByName("Mute", IPS_GetParent($_IPS["SELF"])), $sonos->GetMute());
    }
    if (IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "LoudnessControl")) {
        SetValueInteger(IPS_GetObjectIDByName("Loudness", IPS_GetParent($_IPS["SELF"])), $sonos->GetLoudness());
    }
    if (IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "BassControl")) {
        SetValueInteger(IPS_GetObjectIDByName("Bass", IPS_GetParent($_IPS["SELF"])), $sonos->GetBass());
    }
    if (IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "TrebleControl")) {
        SetValueInteger(IPS_GetObjectIDByName("Treble", IPS_GetParent($_IPS["SELF"])), $sonos->GetTreble());
    }
    if (IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "BalanceControl")) {
        $leftVolume = $sonos->GetVolume("LF");
        $rightVolume = $sonos->GetVolume("RF");
        if ($leftVolume == $rightVolume) {
            SetValueInteger(IPS_GetObjectIDByName("Balance", IPS_GetParent($_IPS["SELF"])), 0);
        } elseif ($leftVolume > $rightVolume) {
            SetValueInteger(IPS_GetObjectIDByName("Balance", IPS_GetParent($_IPS["SELF"])), $rightVolume - 100);
        } else {
            SetValueInteger(IPS_GetObjectIDByName("Balance", IPS_GetParent($_IPS["SELF"])), 100 - $leftVolume);
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
            }
            $xmlr = new SimpleXMLElement($result);
            $rincon = str_replace("uuid:", "", $xmlr->device->UDN);
            IPS_SetProperty($SonosID, "RINCON", $rincon);
            IPS_ApplyChanges($SonosID);
        }
    }
    $rinconMapping[] = array("ID" => $SonosID, "RINCON" => $rincon);
    if ($SonosID === IPS_GetParent($_IPS["SELF"])) {
        $ownRincon = $rincon;
    }
}
$ipAddress = IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "IPAddress");
$timeout = IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "TimeOut");
if (!$timeout || Sys_Ping($ipAddress, $timeout) == true) {
    $sonos = new SonosAccess($ipAddress);
    $sonosGroupCoordinator = explode(":", $sonos->GetZoneGroupAttributes()["CurrentZoneGroupID"])[0];
    foreach ($rinconMapping as $key => $value) {
        if ($value["RINCON"] === $sonosGroupCoordinator) {
            $sonosGroupCoordinatorID = $value["ID"];
            break;
        }
    }
    // If groupCoordinator in Sonos = this instance --> set ID to 0 (does not belong to group)
    if ($sonosGroupCoordinatorID === IPS_GetParent($_IPS["SELF"])) {
        $sonosGroupCoordinatorID = 0;
    }
    if ($sonosGroupCoordinatorID !== $MemberOfGroup) {
        if ($groupForcing) {
            SNS_SetGroup(IPS_GetParent($_IPS["SELF"]), $MemberOfGroup);
        } else {