Modul für Lidl/Aldi Internetradio Basis Silvercrest Sird 14A2 "FSAPI"

Begonnen von AK-868, 12 Januar 2015, 17:06:17

Vorheriges Thema - Nächstes Thema

schroediman

Hi Automatisierer,

das ist ja cool wenn das mit 4 Radios klappt. Ich hab nur eins von der Sorte!

Ich hatte gestern tierische Probleme mit der Kommunikation  :( deshalb hab ich nach ein paar Stunden Tüffteln das mit dem Loggen eingebaut.

Wenn das mit dem Notify funzt dann geht der Kommunikationsbedarf auch spürbar runter. Dann kommt mit einer Abfrage fast alles rüber was jetzt einzeln erledigt wird.

@AK-868: wenn Du mir eine PN mit deiner E-Mail schickst bekommst Du die decompiliert Android app.

Für das Abrufen der Senderliste oder steuern  werden wir wahrscheinlich Listen abrufen müssen und über den mitgelieferten Index wird man dem Radio dann seine Auswahl mitteilen können.
Hierfür zur Darstellung dieser Liste suche ich noch eine einfache aber geniale Idee.

Was müssen wir für dieses komische AV-Development Guide dingen noch machen?  8)

- evtl VolumeUp /VolumeDown ?
- Channel ? keine Ahnung so etwas richtiges wie Channels sehe ich da nicht zum Steuern könnte man "next "und "previous" umbenennen

Welche readings sollten noch implementiert werden ???

Was ist mit attributen, sollen die einzelnen Readings über die Attribute aktiviert werden ?

Notify für FHEM  wann soll sowas gesetzt werden?

MfG

Schroediman ::)









schroediman

ZitatMoin,
habs eingebaut. Läuft mal sauber mit allen vier Radios.

Das LogLevel könnte mal geändert werden, bei 'attr Global verbose 3' wird jede empfangene Nachricht vom Radio geloggt. Und da kommt einiges! :o

Gruß
Ingo


EDIT:

lief gut, auch wenn alle vier Radios an waren,einzig der Seitenaufbau im webif wurde merklich langsamer.

Dann ging mein SatReciever an und das ENIGMA2 Modul kam ins spiel... die Meldungen von 'sudo service fhem start' bis zum Absturz von fhem...

Scalar value @auth[0] better written as $auth[0] at ./FHEM/75_MSG.pm line 147, <$fh> line 196.
Scalar value @auth[1] better written as $auth[1] at ./FHEM/75_MSG.pm line 147, <$fh> line 196.
Use of uninitialized value in localtime at (eval 34) line 1, <> line 269.

"my" variable $helper masks earlier declaration in same scope at ./FHEM/17_SIRD.pm line 975, <> line 3.
No value specified for 'KeyAttr' option in call to XMLin() at ./FHEM/70_ENIGMA2.pm line 1041


Gruß
Ingo

Schaue mal in die Funktion
sub SIRD_GetPlayStatus($){
  #  cachable
  #  notifying
  my ($hash) = @_;
  my $helper = "unknown";
  my $response = SIRD_Com ($hash,"netRemote.play.status",1,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if (int($ref->{value}->{u8}) == 0)
{
$helper = "idle";
}
elsif (int($ref->{value}->{u8}) == 1)
{
$helper = "buffering";
}
elsif (int($ref->{value}->{u8}) == 2)
{
$helper = "playing";
}
elsif (int($ref->{value}->{u8}) == 3)
{
$helper = "paused";
}
elsif (int($ref->{value}->{u8}) == 4)
{
$helper = "rebuffering";
}
elsif (int($ref->{value}->{u8}) == 5)
{
$helper = "error";
}
else
{
$helper =  "unknown";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "playStatus", $helper, 1);
readingsEndUpdate($hash, 0);
}
}
return undef;
}



und lösche mal die zweite definiton von $helper.


Allerdings scheinen wir uns mit der Enigma geschichte die Packete zu klauen und entweder der SIRD fängt das noch nicht gut ab oder das Enigma-Modul scheint "XMLin" mit was Leerem zu versorgen.  bNo value specified for 'KeyAttr' option in call to XMLin() at ./FHEM/70_ENIGMA2.pm line 1041'

Sprich hier ist irgendwas mit dem KeyAttr im ENIGMA2.pm falsch gelaufen. Kann ich leider nicht verifidigensda, da ich dieses Modul nicht nutze.

Ich bau erst mal bei uns shuffle und repeat als Befehl ein. Viel neues kann ich wahrscheinlich diese Woche nicht mehr beitragen.




automatisierer

Zitat von: automatisierer am 03 Februar 2015, 09:05:41

"my" variable $helper masks earlier declaration in same scope at ./FHEM/17_SIRD.pm line 975, <> line 3.


Hat geklappt, die Meldung ist mal weg...

schroediman

#33
Hi ,

shuffle und repeat sollte jetzt soweit funktionieren.

Wenn ihr wollt könnt ihr folgendes mal testen.

1. RemoteState auf 'on' stellen  WICHTIG
2. NavListRequest -1 ### Sollte die ersten 20 Listeneinträge abrufen Im Dab Modus Senderspeicher // MediaPlayer

    es werden jetzt die alten readings gelöscht und 20 readings die vom Radio empfangen wurden angezeigt   das dauert:
    nutzt man NavListRequest 20   werden die ab Eintrag nummer 20 nächsten Elemente abgerufen

    sieht dann so aus:

NavList_01_key      29                  2015-02-04 11:52:10
NavList_01_name   1LIVE diGGi   2015-02-04 11:52:11
NavList_01_subtype  1                2015-02-04 11:52:11
NavList_01_type      1                  2015-02-04 11:52:11

Zum auswählen des Senders  1Live diGGi 

3. NavActionSelItem 29 ##### also den Wert aus dem entsprechenden key-reading

Beim MediaPlayer muss man mehr navigieren.
hierfür gibt es den Befehl:
NavActionNav auch hier wieder das key-Reading benutzen. bei -1 scheint es eine Ebene zurück zugehen

bei jedem Ebenenwechsel muss die Liste neu geholt werden

Wichtig  RemoteState auf 'on' stellen  WICHTIG

MfG

Schroediman






package main;

use strict;
use warnings;
use HttpUtils;
use XML::Simple qw(:strict);

use Dumpvalue;
use Time::HiRes qw(gettimeofday sleep);

sub
SIRD_Initialize($)
{
  my ($hash) = @_;
  $hash->{Clients}   = ":EGPM:";
  $hash->{GetFn}     = "SIRD_Get";
  $hash->{SetFn}     = "SIRD_Set";
  $hash->{DefFn}     = "SIRD_Define";
  $hash->{AttrList}  = ""
}

###################################
sub SIRD_Get($@)
{
    my ($hash, @a) = @_;
    my $what;
my $helper= "";

    return "argument is missing" if(int(@a) != 2);
   
    $what = $a[1];
   
    if($what =~ /^(lastcommand|power|presence|volume|volumeStraight|mute|repeat|shuffle|input|currentArtist|currentAlbum|currentTitle|playStatus|state)$/)
    {
if(defined($hash->{READINGS}{$what}))
{
   return $hash->{READINGS}{$what}{VAL};
}
else
{
if ($what eq "state")
{
if ($hash->{READINGS}{"presence"}{VAL} ne "absent")
{
$helper = $hash->{READINGS}{"power"}{VAL};
}
else
{
$helper = $hash->{READINGS}{"presence"}{VAL};
}
return $helper;
}
else
{
return "reading not found: $what";
}

}
}
   
   
return "Unknown argument $what, choose one of lastcommand:noArg power:noArg presence:noArg volume:noArg volumeStraight:noArg mute:noArg repeat:noArg shuffle:noArg "
   ."input:noArg currentArtist:noArg currentAlbum:noArg currentTitle:noArg playStatus:noArg state:noArg ".(exists($hash->{READINGS}{output})?" output:noArg":"");

}

##SET#################################
sub SIRD_Set($@)
{
  my ($hash, @a) = @_;

  return "no set value specified" if(int(@a) < 2);
  return "Unknown argument $a[1], choose one of on:noArg off:noArg play:noArg pause:noArg stop:noArg next:noArg previous:noArg ".
"volume:slider,0,1,100 volumeStraight:slider,0,1,20 mute:on,off,toggle shuffle:on,off repeat:on,off input:InternetRadio,MediaPlayer,DAB-Radio,FM-Radio,AUX ".
"statusRequest:noArg RemoteState:on,off clearreadings:noArg FriendlyNameRequest:noArg VersionRequest:noArg InfoTextRequest:noArg InfoNameRequest:noArg ".
         "FrequencyRequest:noArg SignalStrengthRequest:noArg NavListRequest NavActionSelItem NavActionNavi DABScanRequest:noArg" if($a[1] eq "?");

  my $name = shift @a;
  my $setcommand = shift @a;
  my $params = join(" ", @a);
  my $helper = 0;
  my $logLevel = GetLogLevel($name);
  Log $logLevel, "SIRD set $name (". $hash->{IP}. ") $setcommand $params";

  $helper=SIRD_GetPower($hash);
   
  if (!$helper){
  ### catch block
  SIRD_Login($hash);
  };
 
  if($setcommand eq "on")
  {
eval{
SIRD_Com ($hash,"netRemote.sys.power?pin=",2,1,0);
};
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
  SIRD_GetPower($hash);
  }
 
  elsif($setcommand eq "off")
  {
eval{
SIRD_Com ($hash,"netRemote.sys.power?pin=",2,0,0);
};
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
  SIRD_GetPower($hash);
  } 
 
  elsif($setcommand eq "input")
  {
if ($params eq "InternetRadio")
{
$helper = 0;
}
elsif ($params eq "MediaPlayer")
{
$helper = 1;
}
elsif ($params eq "DAB-Radio")
{
$helper = 2;
}
elsif ($params eq "FM-Radio")
{
$helper = 3;
}
elsif ($params eq "AUX")
{
$helper = 4;
}
else
{
Log 1, "SIRD Command input wrong Parameter: ".$params;
return 0;
}
eval{
SIRD_Com ($hash,"netRemote.sys.mode",2,$helper,0);
  };
 
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };

SIRD_GetInput($hash);
 
  } 
 
  elsif($setcommand eq "volume")
  {
my $helper = int($params/5);
eval{ 
SIRD_Com ($hash,"netRemote.sys.audio.volume",2,$helper,0);
  };
if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
    ## Lautstärke zurücklesen
SIRD_GetVolume($hash);
  }
 
  elsif($setcommand eq "volumeStraight")
  {
my $helper = int($params);
eval{ 
SIRD_Com ($hash,"netRemote.sys.audio.volume",2,$helper,0);
  };
  ## Lautstärke zurücklesen

if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
  SIRD_GetVolume($hash);
  }
  elsif($setcommand eq "mute")
  {
if ($params eq "on")
{
$helper = 1;
}
elsif ($params eq "off")
{
$helper = 0;
}
elsif ($params eq "toggle")
{
if (ReadingsVal($name, "mute", "0") eq "on")
{
$helper = 0;
}
elsif (ReadingsVal($name, "mute", "0") eq "off")
{
$helper = 1;
}
}
else
{
Log 1, "SIRD Command Mute wrong Parameter: ".$params;
return 0;
}
eval{
SIRD_Com ($hash,"netRemote.sys.audio.mute",2,$helper,0);

  };
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
  SIRD_GetMute($hash);
  } 
  elsif($setcommand eq "stop")
  {
eval{
SIRD_Com ($hash,"netRemote.play.control",2,0,0);
};
if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
};
  }
  elsif($setcommand eq "play")
  {
eval{
SIRD_Com ($hash,"netRemote.play.control",2,1,0);
};
if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
};
  }
  elsif($setcommand eq "pause")
  {
eval{
SIRD_Com ($hash,"netRemote.play.control",2,2,0);
};
if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
};
  }
  elsif($setcommand eq "next")
  {
eval{
SIRD_Com ($hash,"netRemote.play.control",2,3,0);
};
if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
};
  }
  elsif($setcommand eq "previous")
  {
eval{
SIRD_Com ($hash,"netRemote.play.control",2,4,0);
};
if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
};
  }
  elsif($setcommand eq "statusRequest" )
  {
   SIRD_GetStatus($hash,1);
  }
  elsif($setcommand eq "shuffle")
  {
if ($params eq "on")
{
$helper = 1;
}
elsif ($params eq "off")
{
$helper = 0;
}
else
{
Log 1, "SIRD Command shuffle wrong Parameter: ".$params;
return 0;
}
eval{
SIRD_Com ($hash,"netRemote.play.shuffle",2,$helper,0);
  };
 
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };

SIRD_GetShuffle($hash);
 
  } 
  elsif($setcommand eq "repeat")
  {
 
if ($params eq "on")
{
$helper = 1;
}
elsif ($params eq "off")
{
$helper = 0;
}
else
{
Log 1, "SIRD Command repeat wrong Parameter: ".$params;
return 0;
}
eval{
SIRD_Com ($hash,"netRemote.play.repeat",2,$helper,0);
  };
 
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };

SIRD_GetRepeat($hash);
 
  } 
  elsif($setcommand eq "NavActionSelItem")
  {
eval{
SIRD_Com ($hash,"netRemote.nav.action.selectItem",2,$params,0);
  };
 
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };  
  } 
  elsif($setcommand eq "NavActionNavi")
  {
eval{
SIRD_Com ($hash,"netRemote.nav.action.navigate",2,$params,0);
  };
 
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };  
  } 
  elsif($setcommand eq "RemoteState")
  {
if ($params eq "on")
{
$helper = 1;
}
elsif ($params eq "off")
{
$helper = 0;
}
else
{
Log 1, "SIRD Command RemoteState wrong Parameter: ".$params;
return 0;
}
eval{ 
SIRD_Com ($hash,"netRemote.nav.state",2,$helper,0);
  };
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
  SIRD_GetRemoteState($hash);
  }
  elsif($setcommand eq "FriendlyNameRequest" )
  {
   SIRD_GetFriendlyName($hash);
  }
  elsif($setcommand eq "VersionRequest")
  {
   SIRD_GetVersion($hash);
  }
  elsif($setcommand eq "InfoTextRequest")
  {
   SIRD_GetInfoText($hash);
  }
  elsif($setcommand eq "InfoNameRequest")
  {
   SIRD_GetInfoName($hash);
  }
  elsif($setcommand eq "FrequencyRequest")
  {
   SIRD_GetFrequency($hash);
  }
  elsif($setcommand eq "SignalStrengthRequest")
  {
   SIRD_GetSignalStrength($hash);
  }
  elsif($setcommand eq "NavListRequest")
  {
SIRD_GetNavList($hash,$params,$params+20);
  }
  elsif($setcommand eq "DABScanRequest")
  {
SIRD_GetDABScan($hash);
  } 
  elsif($setcommand eq "clearreadings")
  {
   delete $hash->{READINGS};
  }
  else
  {
     return "unknown argument $setcommand, choose one of on, off, toggle, statusrequest, clearreadings";
  }
 
  #SIRD_Logoff($hash);

  $hash->{CHANGED}[0] = $setcommand;
  $hash->{READINGS}{lastcommand}{TIME} = TimeNow();
  $hash->{READINGS}{lastcommand}{VAL} = $setcommand." ".$params;
 
  return undef;
}
###############################
sub SIRD_Login($) {
  my ($hash) = @_;
  my $ref;
  Log $hash->{logLevel},"SIRD try to Login @".$hash->{IP};

 
    my $response = SIRD_Com($hash,"CREATE_SESSION?pin=".$hash->{PASSWORD},0,0,0);
if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);

if ($ref->{status} eq 'FS_OK')
{
$hash->{SESSIONID} = $ref->{sessionId};
Log $hash->{logLevel},"SIRD Login successful!";
};
};
return 1;
}
###############################
sub SIRD_GetStatus($$) {
  my ($hash, $local) = @_;
  my $name = $hash->{NAME};
  my $helper;
  $hash->{logLevel} = GetLogLevel($name);
 
  #if $local is set to 1 just fetch informations from device without interrupting InternalTimer
  $local = 0 unless(defined($local));
  InternalTimer(gettimeofday()+$hash->{INTERVAL}, "SIRD_GetStatus", $hash,0) unless($local == 1);
 
  return "" if(!defined($hash->{IP}) or !defined($hash->{INTERVAL}));
   
  # Prüfen ob SID gültig
  $helper = SIRD_GetPower($hash);

   
  if (!$helper ){
  ### catch block
  SIRD_Login($hash);
  };
  SIRD_GetPower($hash);

  if ($hash->{STATE} eq "on")
  {
 
SIRD_GetVolume($hash);
SIRD_GetMute($hash);
SIRD_GetInput($hash);
SIRD_GetInfoName($hash);
SIRD_GetInfoText($hash);
SIRD_GetRemoteState($hash);
SIRD_GetPlayStatus($hash);
SIRD_GetShuffle($hash);
SIRD_GetRepeat($hash);
SIRD_GetInfoAlbum($hash);
SIRD_GetInfoArtist($hash);
SIRD_GetPlayRate($hash);
SIRD_GetPlayPos($hash);
SIRD_GetInfoDur($hash);
SIRD_GetInfoGraphicURI($hash);
SIRD_GetSignalStrength($hash);


  }
else
{
  #delete $hash->{READINGS};
}
 
  return undef;
}
###############################
sub SIRD_GetPower($) {
#  cachable
#  notifying
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.sys.power",1,0,0);
 
  my $ref;
  my $helper = 'off';
  my $presence = 'absent';
 
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ($ref->{value}->{u8} == 1)
{
$helper = 'on';
$presence = 'present';
}
else
{
$helper = 'off';
$presence = 'present';
}
}
    }
else
{
$helper ='off';
$presence = 'absent';
$response =0;
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "presence", $presence , 1);
readingsSingleUpdate($hash, "power", $helper , 1);
readingsEndUpdate($hash, 0);
if ($presence eq "absent")
{
$helper = $presence;
}
$hash->{STATE} = $helper;


  return $response;
}
###############################
sub SIRD_GetVolume($) {
#  cachable
#  notifying
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.sys.audio.volume",1,0,0);
  my $ref;
  ## Überprüfen ob Abfrage in Ordnung war
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
if ($ref->{status} eq 'FS_OK')
{
readingsBeginUpdate($hash);
# volumeStraight 0 ... 20
readingsSingleUpdate($hash, "volumeStraight", $ref->{value}->{u8}, 1);
# volume 0 ... 100
readingsSingleUpdate($hash, "volume", 5*$ref->{value}->{u8}, 1);
readingsEndUpdate($hash, 0);
}
}
   return undef;
}
###############################
sub SIRD_GetMute($) {
#  cachable
#  notifying
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.sys.audio.mute",1,0,0);
  my $ref ;
  my $helper = 'off';
 
if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ($ref->{value}->{u8} == 1)
{
$helper = "on";
}
else
{
$helper = "off";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "mute", $helper , 1);
readingsEndUpdate($hash, 0);
}
}
   return undef;
}
###############################
sub SIRD_GetShuffle($) {

#  notifying
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.shuffle",1,0,0);
  my $ref ;
  my $helper = 'off';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ($ref->{value}->{u8} == 1)
{
$helper = 'on';
}
else
{
$helper = 'off';
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "shuffle", $helper , 1);
readingsEndUpdate($hash, 0);
}
  }
   return undef;
}
###############################
sub SIRD_GetRepeat($) {

#  notifying
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.repeat",1,0,0);
  my $ref ;
  my $helper = 'off';
 
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ($ref->{value}->{u8} == 1)
{
$helper = 'on';
}
else
{
$helper = 'off';
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "repeat", $helper , 1);
readingsEndUpdate($hash, 0);
}
  }
   return undef;
}
###############################
sub SIRD_GetFriendlyName($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.sys.info.friendlyName",1,0,0);
  my $ref ;
  my $helper = ' ';
 
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "friendlyName", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}

  return undef;
}
###############################
sub SIRD_GetVersion($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.sys.info.version",1,0,0);
  my $ref ;
  my $helper = ' ';
 
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "version", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
###############################
sub SIRD_GetInfoName($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.info.name",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "currentTitle", SIRD_xml2txt($helper) , 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
###############################
sub SIRD_GetInfoText($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.info.text",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "InfoText", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
###############################
sub SIRD_GetInfoAlbum($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.info.album",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "currentAlbum", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
###############################
sub SIRD_GetInfoArtist($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.info.artist",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "currentArtist", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
##############################
sub SIRD_GetInfoGraphicURI($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.info.graphicUri",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "graphicUri", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
##############################
sub SIRD_GetPlayPos($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.position",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')

#Zeit von 1000stel Sekunden in Minuten umwandeln xx:yy
$helper = " ".int( $ref->{value}->{u32} / 60000).":".sprintf("%02d", (int( $ref->{value}->{u32} / 1000)-(int( $ref->{value}->{u32} / 60000)*60)));
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "currentPosition", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
##############################
sub SIRD_GetInfoDur($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.info.duration",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
#Zeit von 1000stel Sekunden in Minuten umwandeln xx:yy
$helper = " ".int( $ref->{value}->{u32} / 60000).":".sprintf("%02d", (int( $ref->{value}->{u32} / 1000)-(int( $ref->{value}->{u32} / 60000)*60)));
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "currentDuration", $helper, 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
###############################
sub SIRD_GetPlayRate($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.rate",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "playRate", $ref->{value}->{s8}, 1);
readingsEndUpdate($hash, 0);
}
  }
  return undef;
}
###############################
sub SIRD_GetFrequency($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.frequency",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "Frequency", $ref->{value}->{u32}, 1);
readingsEndUpdate($hash, 0);
}
}
   return undef;
}
###############################
sub SIRD_GetSignalStrength($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.signalStrength",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "Signalstrength", $ref->{value}->{u8}, 1);
readingsEndUpdate($hash, 0);
}
}
   return undef;
}
###############################
sub SIRD_GetRemoteState($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.nav.state",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ($ref->{value}->{u8} == 1)
{
$helper = "on";
}
else
{
$helper = "off";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "RemoteState", $helper , 1);
readingsEndUpdate($hash, 0);
}
}
   return undef;
}
###############################
sub SIRD_GetInput($) {
#  cachable
#  notifying

  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.sys.mode",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
readingsBeginUpdate($hash);
if    (int($ref->{value}->{u32}) == 0)
{
$helper = "InternetRadio";
}
elsif (int($ref->{value}->{u32}) == 1)
{
$helper = "MediaPlayer";
}
elsif (int($ref->{value}->{u32}) == 2)
{
$helper = "DAB-Radio";
}
elsif (int($ref->{value}->{u32}) == 3)
{
$helper = "FM-Radio";
}
elsif (int($ref->{value}->{u32}) == 4)
{
$helper = "AUX";
}
else
{
$helper = "Unknown";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "input", $helper, 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
###############################
sub SIRD_GetNotify($){
  my ($hash) = @_;
  my $response = SIRD_Com ($hash,"GET_NOTIFIES?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID},0,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if (exists $ref->{"netRemote.sys.power"})
{
if ($ref->{"netRemote.sys.power"}->{value}->{u8} == 1)
{
$helper = "on";
}
else
{
$helper = "off";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "power", $helper , 1);
readingsEndUpdate($hash, 0);
$hash->{STATE} = $helper;
}


if (exists $ref->{"netRemote.sys.audio.volume"})
{
readingsBeginUpdate($hash);
# volumeStraight 0 ... 20
readingsSingleUpdate($hash, "volumeStraigth", $ref->{"netRemote.sys.audio.volume"}->{value}->{u8}, 1);
#  volume 0 ... 100
readingsSingleUpdate($hash, "volume", 5*$ref->{"netRemote.sys.audio.volume"}->{value}->{u8}, 1);
readingsEndUpdate($hash, 0);
}


if (exists $ref->{"netRemote.sys.audio.mute"})
{
if ($ref->{"netRemote.sys.audio.mute"}->{value}->{u8} == 1)
{
$helper = "on";
}
else
{
$helper = "off";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "mute", $helper , 1);
readingsEndUpdate($hash, 0);

}


if (exists $ref->{"netRemote.play.repeat"})
{
if ($ref->{"netRemote.play.repeat"}->{value}->{u8} == 1)
{
$helper = "on";
}
else
{
$helper = "off";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "repeat", $helper , 1);
readingsEndUpdate($hash, 0);
}


if (exists $ref->{"netRemote.play.shuffle"})
{
if ($ref->{"netRemote.play.shuffle"}->{value}->{u8} == 1)
{
$helper = "on";
}
else
{
$helper = "off";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "shuffle", $helper , 1);
readingsEndUpdate($hash, 0);
}

if (exists $ref->{"netRemote.sys.mode"})
{
readingsBeginUpdate($hash);
if    (int($ref->{"netRemote.sys.mode"}->{value}->{u32}) == 0)
{
$helper = "InternetRadio";
}
elsif (int($ref->{"netRemote.sys.mode"}->{value}->{u32}) == 1)
{
$helper = "MediaPlayer";
}
elsif (int($ref->{"netRemote.sys.mode"}->{value}->{u32}) == 2)
{
$helper =  "DAB-Radio" ;
}
elsif (int($ref->{"netRemote.sys.mode"}->{value}->{u32}) == 3)
{
$helper = "FM-Radio";
}
elsif (int($ref->{"netRemote.sys.mode"}->{value}->{u32}) == 4)
{
$helper = "AUX";
}
else
{
$helper = "Unknown";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "input", $helper , 1);
readingsEndUpdate($hash, 0);
}

}

#netRemote.nav.status
#netRemote.play.status
#netRemote.nav.action.dabScan
#to be done
}
  return undef;
}
###############################
sub SIRD_GetPlayStatus($){
  #  cachable
  #  notifying
  my ($hash) = @_;
  my $helper = "unknown";
  my $response = SIRD_Com ($hash,"netRemote.play.status",1,0,0);
  my $ref ;
# my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if (int($ref->{value}->{u8}) == 0)
{
$helper = "idle";
}
elsif (int($ref->{value}->{u8}) == 1)
{
$helper = "buffering";
}
elsif (int($ref->{value}->{u8}) == 2)
{
$helper = "playing";
}
elsif (int($ref->{value}->{u8}) == 3)
{
$helper = "paused";
}
elsif (int($ref->{value}->{u8}) == 4)
{
$helper = "rebuffering";
}
elsif (int($ref->{value}->{u8}) == 5)
{
$helper = "error";
}
else
{
$helper =  "unknown";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "playStatus", $helper, 1);
readingsEndUpdate($hash, 0);
}
}
return undef;
}
###############################
sub SIRD_GetNavList($$$){
  my ($hash,$start,$end) = @_;
  my $helper = "unknown";
  my $response = SIRD_Com ($hash,"netRemote.nav.list",3,$start,$end);
  my $ref ;
  my $incer=0;
  my $v;
  my $k;
  my $dumper = new Dumpvalue;
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
delete $hash->{READINGS};
# $dumper->dumpValue(\\$ref);
for  my $item (@{ $ref->{'item'}}) {
$incer = $incer + 1;
    readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "NavList_".sprintf("%02d",$incer)."_key", $item->{key}, 1);

readingsSingleUpdate($hash, "NavList_".sprintf("%02d",$incer)."_name", @{$item->{'field'}}[0]->{c8_array}, 1);
#print  @{%$item->{field}}[0]->{c8_array};
readingsSingleUpdate($hash, "NavList_".sprintf("%02d",$incer)."_type", @{$item->{'field'}}[1]->{u8}, 1);
readingsSingleUpdate($hash, "NavList_".sprintf("%02d",$incer)."_subtype", @{$item->{'field'}}[2]->{u8}, 1);
readingsEndUpdate($hash, 0);
# $dumper->dumpValue(\\$item);
}

}
}
return undef;
}
###############################
sub SIRD_GetDABScan($){
  #notifying
  my ($hash) = @_;
  my $helper = "unknown";
  my $response = SIRD_Com ($hash,"netRemote.nav.action.dabScan",1,0,0);
  my $ref ;
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ($ref->{value}->{u8} == 0)
{
$helper = "idle";
}
else
{
$helper = "scan";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "DABScan", $helper , 1);
readingsEndUpdate($hash, 0);
}
}
return undef;
}
###############################
sub SIRD_Logoff($) {
  my ($hash) = @_;

  #$quiet, $url, $timeout, $data, $noshutdown, $loglevel
  #CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/login.html", 10, "", 0, $hash->{logLevel});
  return 1;
}
###############################
sub SIRD_Define($$) {
  my ($hash, $def) = @_;
  my @a = split("[ \t][ \t]*", $def);
  my $u = "wrong syntax: define <name> SIRD IP Password [interval]";
  return $u if(int(@a) < 3);
   
  $hash->{IP} = $a[2];
  if(int(@a) == 5 || int(@a) == 4)
  {
    $hash->{PASSWORD} = $a[3]; 
  }
  else
  {
    $hash->{PASSWORD} = "";
  }
  $hash->{logLevel} = 3 ;
  my $result = SIRD_Login($hash);
  if($result == 1)
  {
    $hash->{STATE} = "initialized";
   
  }
  if(defined($a[4]) and $a[4] > 10) {
    $hash->{INTERVAL}=$a[4];
  }
  else{
    $hash->{INTERVAL}=30;
  }
  InternalTimer(gettimeofday() + 10, "SIRD_GetStatus", $hash ,0);
  return undef;
}
sub SIRD_Com ($$$$$) {

my ($hash, $Command, $mode, $value, $value1) = @_;
my $name = $hash->{name};
my $helper ;

my $response = '';
if ($mode==0)  #nonspecific
{
$helper = "http://".$hash->{IP}.":80/fsapi/".$Command;
$response = GetFileFromURL($helper,10,"",1,5);
}
elsif($mode==1) # GET
{
$helper = "http://".$hash->{IP}.":80/fsapi/GET/".$Command."?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID};
$response = GetFileFromURL($helper,2,"",1,5);
}
elsif ($mode==2) # SET
{
$helper = "http://".$hash->{IP}.":80/fsapi/SET/".$Command."?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}."&value=".$value;
$response = GetFileFromURL($helper,2,"",1,5);
}
elsif ($mode==3) # GETLIST
{
$helper = "http://".$hash->{IP}.":80/fsapi/LIST_GET_NEXT/".$Command."/".$value."?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}."&maxItems=".$value1;
$response = GetFileFromURL($helper,2,"",1,5);
}
Log3 $hash, 5, "SIRD: URL : '$helper' ";
Log3 $hash, 5, "SIRD: response from device: '$response' ";
return $response;
}
sub SIRD_xml2txt($)
{
# stolen from   71_YAMAHA_AVR.pm
# sub YAMAHA_AVR_html2txt($)

    my ($string) = @_;
    $string =~ s/&nbsp;/ /g;
    $string =~ s/&amp;/&/g;
    $string =~ s/(\xe4|&auml;)/ä/g;
    $string =~ s/(\xc4|&Auml;)/Ä/g;
    $string =~ s/(\xf6|&ouml;)/ö/g;
    $string =~ s/(\xd6|&Ouml;)/Ö/g;
    $string =~ s/(\xfc|&uuml;)/ü/g;
    $string =~ s/(\xdc|&Uuml;)/Ü/g;
    $string =~ s/(\xdf|&szlig;)/ß/g;
    $string =~ s/<.+?>//g;
    $string =~ s/(^\s+|\s+$)//g;
$string =~ s/(\s+$)//g;
    return $string;
}
1;





EDIT:

Vielleicht hat wer noch eine Idee das schöner besser oder richtiger zu machen. Bin da im Moment Ideenlos!


MfG

Schroediman

automatisierer

 ::)Idee:

die Namen in Klartext hinter NavActionSelItem in Klartext auswählen zu können, dass wäre eine coole Sache.

Ich muss mal wieder ein LOB aussprechen!!

schroediman

Hi automatisierer,

wenn mir wer sagt wie und ob das geht, wird das auch noch gemacht. 8)
Kennst Du ein Modul wo sich die vorgegebenen Werte für die Set-Kommandos dynamisch ändern. Dann könnte man von diesem Modul lernen.

Ich hab nur nach dem rumprobieren mit dem $hash-Gedöns um das in die readings zu kriegen ca 4 -Stunden verbracht.  Ich weiss gar nicht ob die Readings so gelöscht werden dürfen. Ist auf jeden Fall sehr unsauber.
Ich wollte das nur ein bischen funktionell abschliessen. Und dabei festgestellt das ich diese $hashes immer noch nicht mag.

Anscheinend war meine kurze Anleitung verständlich? 8)

Mal sehen was AKA-868 sagt, schliesslich ist das eigentlich ""sein""  Modul,  ::) . Ich wollte nur Testen.
Hab ich ja getan und eine minimale klitze kleine Optimierung  eingebaut. ;D Und diese ihm dann zur Verfügung gestellt. Ich hoffe natürlich, er wird diese berücksichtigen.  ;D

Ne Suchfunktion ist denke ich auch noch möglich.

Benutzt eigentlich wer den FM-Radiomodus ??????


MfG

Schroediman



automatisierer

Hi,
Zitat von: schroediman am 04 Februar 2015, 14:42:10
wenn mir wer sagt wie und ob das geht, wird das auch noch gemacht. 8)

Kennst Du ein Modul wo sich die vorgegebenen Werte für die Set-Kommandos dynamisch ändern. Dann könnte man von diesem Modul lernen.
Werde ich mal überprüfen...

Zitat
Anscheinend war meine kurze Anleitung verständlich? 8)
jap

Zitat
Mal sehen was AKA-868 sagt, schliesslich ist das eigentlich ""sein""  Modul,  ::) . Ich wollte nur Testen.
Hab ich ja getan und eine minimale klitze kleine Optimierung  eingebaut. ;D Und diese ihm dann zur Verfügung gestellt. Ich hoffe natürlich, er wird diese berücksichtigen.  ;D
Das mit dem "nur Testen" schwebt mir auch noch vor, dafür ists schon ganz gut geworden. ;D

Zitat
Benutzt eigentlich wer den FM-Radiomodus ??????

ich nicht...

Ich hatte eigentlich nach dem Kauf der Radios vor mich mit Perl zu beschäftigen und als "Lernprojekt" ein solches Modul zu entwickeln.
Allerdings bin ich mir nicht sicher ob ich das hin bekommen, oder mich damit nur hoffnungslos übernommen hätte.

Gruß
Ingo

schroediman

Hi, hab mal weiter getestet 8)

muss jetzt ins Bett

Irgendwo hab ich mal Enums für Type und Subtype in den Listen gefunden.
Damit weiss man jetzt auch so ein bischen mehr beim Navigieren durch den Server.


playCaps und navCaps sind jetzt auch in den readings
Wenn wir die Werte deuten können wird es möglich bestimmte Ops darüber freizugeben oder zu unterdrücken.
VolumeSteps kommt auch aus dem Radio hochgelesen. scheint nur lesbar zu sein ob wir das brauchen oder wieder rausschmeissen weiss ich noch nicht.

Gute Nacht schroediman




package main;

use strict;
use warnings;
use HttpUtils;
use XML::Simple qw(:strict);

use Dumpvalue;
use Time::HiRes qw(gettimeofday sleep);

sub
SIRD_Initialize($)
{
  my ($hash) = @_;
  $hash->{Clients}   = ":EGPM:";
  $hash->{GetFn}     = "SIRD_Get";
  $hash->{SetFn}     = "SIRD_Set";
  $hash->{DefFn}     = "SIRD_Define";
  $hash->{AttrList}  = ""
}

###################################
sub SIRD_Get($@)
{
    my ($hash, @a) = @_;
    my $what;
my $helper= "";

    return "argument is missing" if(int(@a) != 2);
   
    $what = $a[1];
   
    if($what =~ /^(lastcommand|power|presence|volume|volumeStraight|mute|repeat|shuffle|input|currentArtist|currentAlbum|currentTitle|playStatus|state)$/)
    {
if(defined($hash->{READINGS}{$what}))
{
   return $hash->{READINGS}{$what}{VAL};
}
else
{
if ($what eq "state")
{
if ($hash->{READINGS}{"presence"}{VAL} ne "absent")
{
$helper = $hash->{READINGS}{"power"}{VAL};
}
else
{
$helper = $hash->{READINGS}{"presence"}{VAL};
}
return $helper;
}
else
{
return "reading not found: $what";
}

}
}
   
   
return "Unknown argument $what, choose one of lastcommand:noArg power:noArg presence:noArg volume:noArg volumeStraight:noArg mute:noArg repeat:noArg shuffle:noArg "
   ."input:noArg currentArtist:noArg currentAlbum:noArg currentTitle:noArg playStatus:noArg state:noArg ".(exists($hash->{READINGS}{output})?" output:noArg":"");

}

##SET#################################
sub SIRD_Set($@)
{
  my ($hash, @a) = @_;

  return "no set value specified" if(int(@a) < 2);
  return "Unknown argument $a[1], choose one of on:noArg off:noArg play:noArg pause:noArg stop:noArg next:noArg previous:noArg ".
"volume:slider,0,1,100 volumeStraight:slider,0,1,20 mute:on,off,toggle shuffle:on,off repeat:on,off input:InternetRadio,MediaPlayer,DAB-Radio,FM-Radio,AUX ".
"statusRequest:noArg RemoteState:on,off clearreadings:noArg FriendlyNameRequest:noArg VersionRequest:noArg InfoTextRequest:noArg InfoNameRequest:noArg ".
         "FrequencyRequest:noArg SignalStrengthRequest:noArg NavListRequest NavActionSelItem NavActionNavi NavCapsRequest DABScanRequest:noArg" if($a[1] eq "?");

  my $name = shift @a;
  my $setcommand = shift @a;
  my $params = join(" ", @a);
  my $helper = 0;
  my $logLevel = GetLogLevel($name);
  Log $logLevel, "SIRD set $name (". $hash->{IP}. ") $setcommand $params";

  $helper=SIRD_GetPower($hash);
   
  if (!$helper){
  ### catch block
  SIRD_Login($hash);
  };
 
  if($setcommand eq "on")
  {
eval{
SIRD_Com ($hash,"netRemote.sys.power?pin=",2,1,0);
};
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
  SIRD_GetPower($hash);
  }
 
  elsif($setcommand eq "off")
  {
eval{
SIRD_Com ($hash,"netRemote.sys.power?pin=",2,0,0);
};
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
  SIRD_GetPower($hash);
  } 
 
  elsif($setcommand eq "input")
  {
if ($params eq "InternetRadio")
{
$helper = 0;
}
elsif ($params eq "MediaPlayer")
{
$helper = 1;
}
elsif ($params eq "DAB-Radio")
{
$helper = 2;
}
elsif ($params eq "FM-Radio")
{
$helper = 3;
}
elsif ($params eq "AUX")
{
$helper = 4;
}
else
{
Log 1, "SIRD Command input wrong Parameter: ".$params;
return 0;
}
eval{
SIRD_Com ($hash,"netRemote.sys.mode",2,$helper,0);
  };
 
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };

SIRD_GetInput($hash);
 
  } 
 
  elsif($setcommand eq "volume")
  {
my $helper = int($params/5);
eval{ 
SIRD_Com ($hash,"netRemote.sys.audio.volume",2,$helper,0);
  };
if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
    ## Lautstärke zurücklesen
SIRD_GetVolume($hash);
  }
 
  elsif($setcommand eq "volumeStraight")
  {
my $helper = int($params);
eval{ 
SIRD_Com ($hash,"netRemote.sys.audio.volume",2,$helper,0);
  };
  ## Lautstärke zurücklesen

if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
  SIRD_GetVolume($hash);
  }
  elsif($setcommand eq "mute")
  {
if ($params eq "on")
{
$helper = 1;
}
elsif ($params eq "off")
{
$helper = 0;
}
elsif ($params eq "toggle")
{
if (ReadingsVal($name, "mute", "0") eq "on")
{
$helper = 0;
}
elsif (ReadingsVal($name, "mute", "0") eq "off")
{
$helper = 1;
}
}
else
{
Log 1, "SIRD Command Mute wrong Parameter: ".$params;
return 0;
}
eval{
SIRD_Com ($hash,"netRemote.sys.audio.mute",2,$helper,0);

  };
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
  SIRD_GetMute($hash);
  } 
  elsif($setcommand eq "stop")
  {
eval{
SIRD_Com ($hash,"netRemote.play.control",2,0,0);
};
if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
};
  }
  elsif($setcommand eq "play")
  {
eval{
SIRD_Com ($hash,"netRemote.play.control",2,1,0);
};
if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
};
  }
  elsif($setcommand eq "pause")
  {
eval{
SIRD_Com ($hash,"netRemote.play.control",2,2,0);
};
if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
};
  }
  elsif($setcommand eq "next")
  {
eval{
SIRD_Com ($hash,"netRemote.play.control",2,3,0);
};
if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
};
  }
  elsif($setcommand eq "previous")
  {
eval{
SIRD_Com ($hash,"netRemote.play.control",2,4,0);
};
if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
};
  }
  elsif($setcommand eq "statusRequest" )
  {
   SIRD_GetStatus($hash,1);
  }
  elsif($setcommand eq "shuffle")
  {
if ($params eq "on")
{
$helper = 1;
}
elsif ($params eq "off")
{
$helper = 0;
}
else
{
Log 1, "SIRD Command shuffle wrong Parameter: ".$params;
return 0;
}
eval{
SIRD_Com ($hash,"netRemote.play.shuffle",2,$helper,0);
  };
 
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };

SIRD_GetShuffle($hash);
 
  } 
  elsif($setcommand eq "repeat")
  {
 
if ($params eq "on")
{
$helper = 1;
}
elsif ($params eq "off")
{
$helper = 0;
}
else
{
Log 1, "SIRD Command repeat wrong Parameter: ".$params;
return 0;
}
eval{
SIRD_Com ($hash,"netRemote.play.repeat",2,$helper,0);
  };
 
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };

SIRD_GetRepeat($hash);
 
  } 
  elsif($setcommand eq "NavActionSelItem")
  {
eval{
SIRD_Com ($hash,"netRemote.nav.action.selectItem",2,$params,0);
  };
 
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };  
  } 
  elsif($setcommand eq "NavActionNavi")
  {
eval{
SIRD_Com ($hash,"netRemote.nav.action.navigate",2,$params,0);
  };
 
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };  
  } 
  elsif($setcommand eq "RemoteState")
  {
if ($params eq "on")
{
$helper = 1;
}
elsif ($params eq "off")
{
$helper = 0;
}
else
{
Log 1, "SIRD Command RemoteState wrong Parameter: ".$params;
return 0;
}
eval{ 
SIRD_Com ($hash,"netRemote.nav.state",2,$helper,0);
  };
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
  SIRD_GetRemoteState($hash);
  }
  elsif($setcommand eq "FriendlyNameRequest" )
  {
   SIRD_GetFriendlyName($hash);
  }
  elsif($setcommand eq "VersionRequest")
  {
   SIRD_GetVersion($hash);
  }
  elsif($setcommand eq "InfoTextRequest")
  {
   SIRD_GetInfoText($hash);
  }
  elsif($setcommand eq "InfoNameRequest")
  {
   SIRD_GetInfoName($hash);
  }
  elsif($setcommand eq "FrequencyRequest")
  {
   SIRD_GetFrequency($hash);
  }
  elsif($setcommand eq "SignalStrengthRequest")
  {
   SIRD_GetSignalStrength($hash);
  }
  elsif($setcommand eq "NavCapsRequest")
  {
   SIRD_GetNavCaps($hash);
  }
  elsif($setcommand eq "NavListRequest")
  {
SIRD_GetNavList($hash,$params,$params+20);
  }
  elsif($setcommand eq "DABScanRequest")
  {
SIRD_GetDABScan($hash);
  } 
  elsif($setcommand eq "clearreadings")
  {
   delete $hash->{READINGS};
  }
  else
  {
     return "unknown argument $setcommand, choose one of on off play pause stop next previous ".
"volume volumeStraight mute shuffle repeat input ".
"statusRequest RemoteState clearreadings FriendlyNameRequest VersionRequest InfoTextRequest: InfoNameRequest ".
         "FrequencyRequest SignalStrengthRequest NavListRequest NavActionSelItem NavActionNavi DABScanRequest";
  }
 
  #SIRD_Logoff($hash);

  $hash->{CHANGED}[0] = $setcommand;
  $hash->{READINGS}{lastcommand}{TIME} = TimeNow();
  $hash->{READINGS}{lastcommand}{VAL} = $setcommand." ".$params;
 
  return undef;
}
###############################
sub SIRD_Login($) {
  my ($hash) = @_;
  my $ref;
  Log $hash->{logLevel},"SIRD try to Login @".$hash->{IP};

 
    my $response = SIRD_Com($hash,"CREATE_SESSION?pin=".$hash->{PASSWORD},0,0,0);
if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);

if ($ref->{status} eq 'FS_OK')
{
$hash->{SESSIONID} = $ref->{sessionId};
Log $hash->{logLevel},"SIRD Login successful!";
};
};
return 1;
}
###############################
sub SIRD_GetStatus($$) {
  my ($hash, $local) = @_;
  my $name = $hash->{NAME};
  my $helper;
  $hash->{logLevel} = GetLogLevel($name);
 
  #if $local is set to 1 just fetch informations from device without interrupting InternalTimer
  $local = 0 unless(defined($local));
  InternalTimer(gettimeofday()+$hash->{INTERVAL}, "SIRD_GetStatus", $hash,0) unless($local == 1);
 
  return "" if(!defined($hash->{IP}) or !defined($hash->{INTERVAL}));
   
  # Prüfen ob SID gültig
  $helper = SIRD_GetPower($hash);

   
  if (!$helper ){
  ### catch block
  SIRD_Login($hash);
  };
  SIRD_GetPower($hash);

  if ($hash->{STATE} eq "on")
  {
 
SIRD_GetVolume($hash);
SIRD_GetMute($hash);
SIRD_GetInput($hash);
SIRD_GetInfoName($hash);
SIRD_GetInfoText($hash);
SIRD_GetRemoteState($hash);
SIRD_GetPlayStatus($hash);
SIRD_GetShuffle($hash);
SIRD_GetRepeat($hash);
SIRD_GetInfoAlbum($hash);
SIRD_GetInfoArtist($hash);
SIRD_GetPlayRate($hash);
SIRD_GetPlayPos($hash);
SIRD_GetInfoDur($hash);
SIRD_GetInfoGraphicURI($hash);
SIRD_GetSignalStrength($hash);
SIRD_GetNavCaps($hash);
SIRD_GetPlayCaps($hash);
SIRD_GetVolumeSteps($hash);
  }
else
{
  #delete $hash->{READINGS};
}
 
  return undef;
}
###############################
sub SIRD_GetPower($) {
#  cachable
#  notifying
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.sys.power",1,0,0);
 
  my $ref;
  my $helper = 'off';
  my $presence = 'absent';
 
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ($ref->{value}->{u8} == 1)
{
$helper = 'on';
$presence = 'present';
}
else
{
$helper = 'off';
$presence = 'present';
}
}
    }
else
{
$helper ='off';
$presence = 'absent';
$response =0;
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "presence", $presence , 1);
readingsSingleUpdate($hash, "power", $helper , 1);
readingsEndUpdate($hash, 0);
if ($presence eq "absent")
{
$helper = $presence;
}
$hash->{STATE} = $helper;


  return $response;
}
###############################
sub SIRD_GetVolume($) {
#  cachable
#  notifying
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.sys.audio.volume",1,0,0);
  my $ref;
  ## Überprüfen ob Abfrage in Ordnung war
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
if ($ref->{status} eq 'FS_OK')
{
readingsBeginUpdate($hash);
# volumeStraight 0 ... 20
readingsSingleUpdate($hash, "volumeStraight", $ref->{value}->{u8}, 1);
# volume 0 ... 100
readingsSingleUpdate($hash, "volume", 5*$ref->{value}->{u8}, 1);
readingsEndUpdate($hash, 0);
}
}
   return undef;
}
###############################
sub SIRD_GetVolumeSteps($) {
#  cachable
#  notifying
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.sys.caps.volumeSteps",1,0,0);
  my $ref;
  ## Überprüfen ob Abfrage in Ordnung war
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
if ($ref->{status} eq 'FS_OK')
{
readingsBeginUpdate($hash);
# volumeStraight 0 ... 20
readingsSingleUpdate($hash, "volumeSteps", $ref->{value}->{u8}, 1);
readingsEndUpdate($hash, 0);
}
}
   return undef;
}
###############################
sub SIRD_GetMute($) {
#  cachable
#  notifying
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.sys.audio.mute",1,0,0);
  my $ref ;
  my $helper = 'off';
 
if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ($ref->{value}->{u8} == 1)
{
$helper = "on";
}
else
{
$helper = "off";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "mute", $helper , 1);
readingsEndUpdate($hash, 0);
}
}
   return undef;
}
###############################
sub SIRD_GetShuffle($) {

#  notifying
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.shuffle",1,0,0);
  my $ref ;
  my $helper = 'off';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ($ref->{value}->{u8} == 1)
{
$helper = 'on';
}
else
{
$helper = 'off';
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "shuffle", $helper , 1);
readingsEndUpdate($hash, 0);
}
  }
   return undef;
}
###############################
sub SIRD_GetRepeat($) {

#  notifying
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.repeat",1,0,0);
  my $ref ;
  my $helper = 'off';
 
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ($ref->{value}->{u8} == 1)
{
$helper = 'on';
}
else
{
$helper = 'off';
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "repeat", $helper , 1);
readingsEndUpdate($hash, 0);
}
  }
   return undef;
}
###############################
sub SIRD_GetFriendlyName($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.sys.info.friendlyName",1,0,0);
  my $ref ;
  my $helper = ' ';
 
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "friendlyName", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}

  return undef;
}
###############################
sub SIRD_GetVersion($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.sys.info.version",1,0,0);
  my $ref ;
  my $helper = ' ';
 
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "version", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
###############################
sub SIRD_GetInfoName($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.info.name",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "currentTitle", SIRD_xml2txt($helper) , 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
###############################
sub SIRD_GetInfoText($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.info.text",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "InfoText", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
###############################
sub SIRD_GetInfoAlbum($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.info.album",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "currentAlbum", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
###############################
sub SIRD_GetInfoArtist($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.info.artist",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "currentArtist", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
##############################
sub SIRD_GetInfoGraphicURI($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.info.graphicUri",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "graphicUri", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
##############################
sub SIRD_GetPlayPos($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.position",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')

#Zeit von 1000stel Sekunden in Minuten umwandeln xx:yy
$helper = " ".int( $ref->{value}->{u32} / 60000).":".sprintf("%02d", (int( $ref->{value}->{u32} / 1000)-(int( $ref->{value}->{u32} / 60000)*60)));
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "currentPosition", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
##############################
sub SIRD_GetInfoDur($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.info.duration",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
#Zeit von 1000stel Sekunden in Minuten umwandeln xx:yy
$helper = " ".int( $ref->{value}->{u32} / 60000).":".sprintf("%02d", (int( $ref->{value}->{u32} / 1000)-(int( $ref->{value}->{u32} / 60000)*60)));
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "currentDuration", $helper, 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
###############################
sub SIRD_GetPlayRate($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.rate",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "playRate", $ref->{value}->{s8}, 1);
readingsEndUpdate($hash, 0);
}
  }
  return undef;
}
###############################
sub SIRD_GetPlayCaps($){
  my ($hash) = @_;
  my $helper = "unknown";
  my $response = SIRD_Com ($hash,"netRemote.play.caps",1,$0,0);
  my $ref ;
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "playCaps", $ref->{value}->{u32}, 1);
readingsEndUpdate($hash, 0);
}
}
return undef;
}
###############################
sub SIRD_GetFrequency($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.frequency",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "Frequency", $ref->{value}->{u32}, 1);
readingsEndUpdate($hash, 0);
}
}
   return undef;
}
###############################
sub SIRD_GetSignalStrength($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.signalStrength",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "Signalstrength", $ref->{value}->{u8}, 1);
readingsEndUpdate($hash, 0);
}
}
   return undef;
}
###############################
sub SIRD_GetRemoteState($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.nav.state",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ($ref->{value}->{u8} == 1)
{
$helper = "on";
}
else
{
$helper = "off";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "RemoteState", $helper , 1);
readingsEndUpdate($hash, 0);
}
}
   return undef;
}
###############################
sub SIRD_GetInput($) {
#  cachable
#  notifying

  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.sys.mode",1,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
readingsBeginUpdate($hash);
if    (int($ref->{value}->{u32}) == 0)
{
$helper = "InternetRadio";
}
elsif (int($ref->{value}->{u32}) == 1)
{
$helper = "MediaPlayer";
}
elsif (int($ref->{value}->{u32}) == 2)
{
$helper = "DAB-Radio";
}
elsif (int($ref->{value}->{u32}) == 3)
{
$helper = "FM-Radio";
}
elsif (int($ref->{value}->{u32}) == 4)
{
$helper = "AUX";
}
else
{
$helper = "Unknown";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "input", $helper, 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
###############################
sub SIRD_GetNotify($){
  my ($hash) = @_;
  my $response = SIRD_Com ($hash,"GET_NOTIFIES?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID},0,0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if (exists $ref->{"netRemote.sys.power"})
{
if ($ref->{"netRemote.sys.power"}->{value}->{u8} == 1)
{
$helper = "on";
}
else
{
$helper = "off";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "power", $helper , 1);
readingsEndUpdate($hash, 0);
$hash->{STATE} = $helper;
}


if (exists $ref->{"netRemote.sys.audio.volume"})
{
readingsBeginUpdate($hash);
# volumeStraight 0 ... 20
readingsSingleUpdate($hash, "volumeStraigth", $ref->{"netRemote.sys.audio.volume"}->{value}->{u8}, 1);
#  volume 0 ... 100
readingsSingleUpdate($hash, "volume", 5*$ref->{"netRemote.sys.audio.volume"}->{value}->{u8}, 1);
readingsEndUpdate($hash, 0);
}


if (exists $ref->{"netRemote.sys.audio.mute"})
{
if ($ref->{"netRemote.sys.audio.mute"}->{value}->{u8} == 1)
{
$helper = "on";
}
else
{
$helper = "off";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "mute", $helper , 1);
readingsEndUpdate($hash, 0);

}


if (exists $ref->{"netRemote.play.repeat"})
{
if ($ref->{"netRemote.play.repeat"}->{value}->{u8} == 1)
{
$helper = "on";
}
else
{
$helper = "off";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "repeat", $helper , 1);
readingsEndUpdate($hash, 0);
}


if (exists $ref->{"netRemote.play.shuffle"})
{
if ($ref->{"netRemote.play.shuffle"}->{value}->{u8} == 1)
{
$helper = "on";
}
else
{
$helper = "off";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "shuffle", $helper , 1);
readingsEndUpdate($hash, 0);
}

if (exists $ref->{"netRemote.sys.mode"})
{
readingsBeginUpdate($hash);
if    (int($ref->{"netRemote.sys.mode"}->{value}->{u32}) == 0)
{
$helper = "InternetRadio";
}
elsif (int($ref->{"netRemote.sys.mode"}->{value}->{u32}) == 1)
{
$helper = "MediaPlayer";
}
elsif (int($ref->{"netRemote.sys.mode"}->{value}->{u32}) == 2)
{
$helper =  "DAB-Radio" ;
}
elsif (int($ref->{"netRemote.sys.mode"}->{value}->{u32}) == 3)
{
$helper = "FM-Radio";
}
elsif (int($ref->{"netRemote.sys.mode"}->{value}->{u32}) == 4)
{
$helper = "AUX";
}
else
{
$helper = "Unknown";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "input", $helper , 1);
readingsEndUpdate($hash, 0);
}

}

#netRemote.nav.status
#netRemote.play.status
#netRemote.nav.action.dabScan
#to be done
}
  return undef;
}
###############################
sub SIRD_GetPlayStatus($){
  #  cachable
  #  notifying
  my ($hash) = @_;
  my $helper = "unknown";
  my $response = SIRD_Com ($hash,"netRemote.play.status",1,0,0);
  my $ref ;
# my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if (int($ref->{value}->{u8}) == 0)
{
$helper = "idle";
}
elsif (int($ref->{value}->{u8}) == 1)
{
$helper = "buffering";
}
elsif (int($ref->{value}->{u8}) == 2)
{
$helper = "playing";
}
elsif (int($ref->{value}->{u8}) == 3)
{
$helper = "paused";
}
elsif (int($ref->{value}->{u8}) == 4)
{
$helper = "rebuffering";
}
elsif (int($ref->{value}->{u8}) == 5)
{
$helper = "error";
}
else
{
$helper =  "unknown";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "playStatus", $helper, 1);
readingsEndUpdate($hash, 0);
}
}
return undef;
}
###############################
sub SIRD_GetNavCaps($){
  my ($hash) = @_;
  my $helper = "unknown";
  my $response = SIRD_Com ($hash,"netRemote.nav.caps",1,$0,0);
  my $ref ;
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "navCaps", $ref->{value}->{u32}, 1);
readingsEndUpdate($hash, 0);
}
}
return undef;
}
###############################
sub SIRD_GetNavList($$$){
  my ($hash,$start,$end) = @_;
  my $helper = "unknown";
  my $x;
 
  my $response = SIRD_Com ($hash,"netRemote.nav.list",3,$start,$end);
  my $ref ;
  my $incer=0;
  my $dumper = new Dumpvalue;
 
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
delete $hash->{READINGS};
#$dumper->dumpValue(\\$ref->{'item'});
if ( ref($ref->{'item'}) eq "ARRAY"){
for my  $item (@{$ref->{'item'}}) {
$incer = $incer + 1;
    readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "NavList_".sprintf("%02d",$incer)."_key", $item->{key}, 1);
readingsSingleUpdate($hash, "NavList_".sprintf("%02d",$incer)."_name", @{$item->{'field'}}[0]->{c8_array}, 1);
$x=@{$item->{'field'}}[1]->{u8};
if    ( $x == 0) {
$helper = "Directory"; }
elsif ( $x == 1) {
$helper = "PlayableItem"; }
elsif ( $x == 2) {
$helper = "SearchDirectory"; }
elsif ( $x == 3) {
$helper = "Unknown"; }
elsif ( $x == 4) {
$helper = "FetchErrItem"; }
else {
$helper = "Unknown"; }
readingsSingleUpdate($hash, "NavList_".sprintf("%02d",$incer)."_type", $helper, 1);

$x=@{$item->{'field'}}[2]->{u8};
if    ( $x == 0) {
$helper = "None"; }
elsif ( $x == 1) {
$helper = "Station"; }
elsif ( $x == 2) {
$helper = "Podcast"; }
elsif ( $x == 3) {
$helper = "Track"; }
else {
$helper = "Unknown"; }
readingsSingleUpdate($hash, "NavList_".sprintf("%02d",$incer)."_subtype", $helper, 1);
readingsEndUpdate($hash, 0);
# $dumper->dumpValue(\\$item);
}

}

}
}
return undef;
}
###############################
sub SIRD_GetDABScan($){
  #notifying
  my ($hash) = @_;
  my $helper = "unknown";
  my $response = SIRD_Com ($hash,"netRemote.nav.action.dabScan",1,0,0);
  my $ref ;
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ($ref->{value}->{u8} == 0)
{
$helper = "idle";
}
else
{
$helper = "scan";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "DABScan", $helper , 1);
readingsEndUpdate($hash, 0);
}
}
return undef;
}
###############################
sub SIRD_Logoff($) {
  my ($hash) = @_;

  #$quiet, $url, $timeout, $data, $noshutdown, $loglevel
  #CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/login.html", 10, "", 0, $hash->{logLevel});
  return 1;
}
###############################
sub SIRD_Define($$) {
  my ($hash, $def) = @_;
  my @a = split("[ \t][ \t]*", $def);
  my $u = "wrong syntax: define <name> SIRD IP Password [interval]";
  return $u if(int(@a) < 3);
   
  $hash->{IP} = $a[2];
  if(int(@a) == 5 || int(@a) == 4)
  {
    $hash->{PASSWORD} = $a[3]; 
  }
  else
  {
    $hash->{PASSWORD} = "";
  }
  $hash->{logLevel} = 3 ;
  my $result = SIRD_Login($hash);
  if($result == 1)
  {
    $hash->{STATE} = "initialized";
   
  }
  if(defined($a[4]) and $a[4] > 10) {
    $hash->{INTERVAL}=$a[4];
  }
  else{
    $hash->{INTERVAL}=30;
  }
  InternalTimer(gettimeofday() + 10, "SIRD_GetStatus", $hash ,0);
  return undef;
}
###############################
sub SIRD_Undefine($$){
  my($hash, $name) = @_;
 
  # Stop the internal GetStatus-Loop and exist
  RemoveInternalTimer($hash);
  return undef;
}
###############################
sub SIRD_Com ($$$$$) {
my ($hash, $Command, $mode, $value, $value1) = @_;
my $name = $hash->{name};
my $helper ;

my $response = '';
if ($mode==0)  #nonspecific
{
$helper = "http://".$hash->{IP}.":80/fsapi/".$Command;
$response = GetFileFromURL($helper,10,"",1,5);
}
elsif($mode==1) # GET
{
$helper = "http://".$hash->{IP}.":80/fsapi/GET/".$Command."?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID};
$response = GetFileFromURL($helper,2,"",1,5);
}
elsif ($mode==2) # SET
{
$helper = "http://".$hash->{IP}.":80/fsapi/SET/".$Command."?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}."&value=".$value;
$response = GetFileFromURL($helper,2,"",1,5);
}
elsif ($mode==3) # GETLIST
{
$helper = "http://".$hash->{IP}.":80/fsapi/LIST_GET_NEXT/".$Command."/".$value."?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}."&maxItems=".$value1;
$response = GetFileFromURL($helper,2,"",1,5);
}
Log3 $hash, 5, "SIRD: URL : '$helper' ";
Log3 $hash, 5, "SIRD: response from device: '$response' ";
return $response;
}
###############################
sub SIRD_xml2txt($)
{
# stolen from   71_YAMAHA_AVR.pm
# sub YAMAHA_AVR_html2txt($)

    my ($string) = @_;
    $string =~ s/&nbsp;/ /g;
    $string =~ s/&amp;/&/g;
    $string =~ s/(\xe4|&auml;)/ä/g;
    $string =~ s/(\xc4|&Auml;)/Ä/g;
    $string =~ s/(\xf6|&ouml;)/ö/g;
    $string =~ s/(\xd6|&Ouml;)/Ö/g;
    $string =~ s/(\xfc|&uuml;)/ü/g;
    $string =~ s/(\xdc|&Uuml;)/Ü/g;
    $string =~ s/(\xdf|&szlig;)/ß/g;
    $string =~ s/<.+?>//g;
    $string =~ s/(^\s+|\s+$)//g;
$string =~ s/(\s+$)//g;
    return $string;
}
1;




automatisierer

Moin,
hab den Wald vor lauter Bäumen nicht gesehen... Beim ENIGMA2 Modul kann man die Kanäle per Liste auswählen, da kannst du also abgucken.
Gruß
Ingo

AK-868

Hallo Schroedimann,

also das ist dein Modul jetzt.... ich glaub ich muss nen anderes machen wo ich was lernen kann... Dein Tempo ist einfach zu hoch. :-)

Irgendwie müsste ich dann einfach mal ruhe haben und nicht am Laptop aufm Sofa...wo der Tag dem ende zu geht.

Mein Job spannt mich derzeit auch mit extrem viel neuem Zeug ein. Da ist mein Kopf merkwürdigerweise am Limit.

Ich schaffs derzeit nicht mal meine Bugs die sonst noch in meiner cfg sind zu beseitigen.

Super Arbeit auf jeden Fall ich hab schon eine Menge gelernt bei der Sache. Wie du weißt ist das mein Einsteiger Projekt gewesen und hab bei Null angefangen.

Ich danke in jedem Fall Dir dem Automatisierer Markus vom yamaha modul und Ericl und für eure  Mühen!

Testen muss ich auch noch.

Grüße!
Andre





Hardware FHEM:
Neue Fritzbox 7390 keine Labor von AVM
Konfigurationsadapter Lan
Funk-Schließerkontaktschnittstellen
Funk-Fenster/Türkontakt
Funk-Schaltaktoren UP ein und zweifach
Funk-Jalousieaktoren
Funk-Rauchmelder


schroediman

Hi AK-868,
ich wollte Dich eigentlich nicht so überrumpeln, sorry dafür.

Ich muss auch erst wieder auf Arbeit gas geben, von daher werd ich noch einige Zeit brauchen um das Modul in Richtung fertig zu kriegen.

Ich bin schon auf deine Erfahrungen mit dem NEUEN Lidl-Radio interessiert. Was ist denn da überhaupt anders dran ausser den beleuchteten Drehknöpfen?

Von daher wird das Tempo jetzt auch drastisch nachlassen.
Wenn Du dich weiter beteiligen willst oder Fragen hast gerne.

Sorry dafür nocheinmal.

@automatisierer,
ja da hast Du recht, aus dem Enigma-modul scheinen wir noch einiges lernen zu können.


MfG

Sebastian


Markus Bloch

Zitat von: AK-868 am 12 Januar 2015, 17:06:17
Wenn her Bloch das liest... Wie bekommst du mit wie der status vom Yamaha ist wenn er aus gemacht wird. IR-Fernbedienung?
Ständig auslesen?

Ständig auslesen aller X Sekunden. Der Yamaha bleibt ansprechbar, auch wenn er aus ist (standby) sofern in den Einstellungen des Receivers "Network Standby" aktiviert ist. Somit antwortet der Yamaha mir und sagt, dass er sich im standby befindet.

Developer für Module: YAMAHA_AVR, YAMAHA_BD, FB_CALLMONITOR, FB_CALLLIST, PRESENCE, Pushsafer, LGTV_IP12, version

aktives Mitglied des FHEM e.V. (Technik)

AK-868

Hallo,

auf der Fritzbox, läuft das Teil nicht. Kann dein Modul nicht Testen.

apt-get läuft nicht auf der Box.

Muss also ein RPI her ;)

grüße
Hardware FHEM:
Neue Fritzbox 7390 keine Labor von AVM
Konfigurationsadapter Lan
Funk-Schließerkontaktschnittstellen
Funk-Fenster/Türkontakt
Funk-Schaltaktoren UP ein und zweifach
Funk-Jalousieaktoren
Funk-Rauchmelder


schroediman

Zitat
Hallo,

auf der Fritzbox, läuft das Teil nicht. Kann dein Modul nicht Testen.

apt-get läuft nicht auf der Box.

Muss also ein RPI her ;)

grüße



Generell ist es schon eine gute Idee seinem Haus einen eigenen Server zu gönnen. Es kommen gerde Interessante Nachfolger für RPI und BananaPI auf den Markt.


allerdings, was fehlt Dir genau auf deiner Fritzbox-instllation?
evtl hilft das hier: http://www.fhemwiki.de/wiki/Unicode_FritzBox

oder ist es ds xML::Simple  ???

MfG

Schroediman 8)

AK-868

Hi,

ich hab mir gerade den neuen quad core pi gekauft.. Mal sehen was der kann ;)

Grüße
Hardware FHEM:
Neue Fritzbox 7390 keine Labor von AVM
Konfigurationsadapter Lan
Funk-Schließerkontaktschnittstellen
Funk-Fenster/Türkontakt
Funk-Schaltaktoren UP ein und zweifach
Funk-Jalousieaktoren
Funk-Rauchmelder