# $Id: 17_SIRD.pm 41052 2017-03-28 16:41:14Z joergbackus $
####################################################################################################
package main;

use strict;
use warnings;
use HttpUtils;
use Encode;
use Scalar::Util qw(looks_like_number);
use XML::Simple qw(:strict);
no warnings 'uninitialized';

#local $ENV{XML_SIMPLE_PREFERRED_PARSER} = 'XML::Parser';

use Time::HiRes qw(gettimeofday sleep);

sub SIRD_Initialize($)
{
  my ($hash) = @_;
  $hash->{GetFn}    = "SIRD_Get";
  $hash->{SetFn}    = "SIRD_Set";
  $hash->{DefFn}    = "SIRD_Define";
  $hash->{AttrList} = "volumeStep navListItems presetListRequestMode " . $readingFnAttributes;
#      $attr{$name}{"presetListRequestMode"} = "0" unless(defined($attr{$name}{"presetListRequestMode"}));
#  $hash->{AttrList} = "volumeStep navListItems " . $readingFnAttributes;
  Log 2, "SIRD Init module";

}
###############################
sub SIRD_Com ($$$$$);
sub SIRD_space2sub ($);
sub SIRD_Login($);
sub SIRD_Login($)
{
  my ($hash) = @_;
  my $ref;
  my $response = "";
  my $responseHelper = "false";

# Log $hash->{logLevel}, "SIRD try to Login @" . $hash->{IP};
  Log 5, "SIRD try to Login @" . $hash->{IP};
  $response = SIRD_Com( $hash, "CREATE_SESSION?pin=" . $hash->{PASSWORD}, 0, 0, 0 );
  $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
    my $refXML = eval {
      XMLin( $response, KeyAttr => {}, ForceArray => [] );
    };
    if($@) {
      $responseHelper = "false";
#Log 1, "Login: XML-Error: ".$@;
    }
  if ( $responseHelper eq "true" )
  {
    $responseHelper = "false";
#  XMLin('<bad>not well formed');
################################################################

    $ref = XMLin( $response, KeyAttr => {}, ForceArray => [] );

    if ( $ref->{status} eq 'FS_OK' )
    {
      $hash->{SESSIONID} = $ref->{sessionId};
#      Log $hash->{logLevel}, "SIRD Login successful!";
       Log 5, "SIRD Login successful!";
    }
  }
  return 1;
}
###############################
sub SIRD_Power($$);
sub SIRD_Power($$)
{

  #  cachable
  #  notifying
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref = "";
  my $refHelper = "false";
  my $helper   = ' ';
  my $presence = 'absent';
  my $modulversion1 = "17_SIRD.pm V 0.60 Beta (Date: 07.05.2017)";
  my $modulversion2 = "";
  my $FC = '0';
  
  if ( !defined( $hash->{helper}->{functionRun} )) {
    $hash->{helper}->{functionRun} = "true";
  }
  if ( !defined( $hash->{helper}->{FunctionCounter} )) {
    $hash->{helper}->{FunctionCounter} = '0';
  }
  if ( $hash->{helper}->{functionRun} eq "true" ) {
    $FC = $hash->{helper}->{FunctionCounter};
    if ( $FC >= '5' ) {
      $FC = '0';
      $hash->{helper}->{functionRun} = "false";
    }  
  }

  if ( $hash->{READINGS}{"Modulversion"}{VAL} ne $modulversion1 && $hash->{READINGS}{"power"}{VAL} eq "on") {
      delete $hash->{helper}->{testversion};
      $hash->{helper}->{testversion} = $modulversion1;
      $modulversion2 = $hash->{helper}->{testversion};
      readingsSingleUpdate( $hash, "Modulversion", $modulversion2, 1 );
  }

  if ( $params eq "on" || $params eq "off" )
  {
    if ( $params eq "on" )
    {
      $helper = '1';
    }
    elsif ( $params eq "off" )
    {
      $helper = '0';
    }
    eval { SIRD_Com( $hash, "netRemote.sys.power?pin=", 2, $helper, 0 ); };
    if ($@)
    {
      ### catch block(jb)
      Log 1, "SIRD Power set error: $@";
      return;
    }
    SIRD_Power( $hash, -1 );
  }
  elsif ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.sys.power", 1, 0, 0 );
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
      $ref = XMLin( $response, KeyAttr => {}, ForceArray => [] );
      $refHelper = "true" if ! $ref || ( $ref->{status} eq 'FS_OK' );
      ## Überprüfen ob Abfrage in Ordnung war
      if ( $refHelper eq "true" )
      {
        $refHelper = "false";
        if ( $ref->{value}->{u8} == 1 )
        {
          $helper   = "on";
          $presence = "present";
        }
        else
        {
          $helper   = "off";
          $presence = "present";
        }
        $response = "OK";
      }
    }
    else
    {
      $helper   = "off";
      $presence = "absent";
      $response = "";
    }
    if ( $hash->{READINGS}{"presence"}{VAL} ne $presence )
    {
      readingsSingleUpdate( $hash, "presence", $presence, 1 );
    }
    if ( $hash->{READINGS}{"power"}{VAL} ne $helper )
    {
      readingsSingleUpdate( $hash, "power", $helper, 1 );
    }

    # state setzen
    if ( $presence eq "absent" )
    {
      $helper = $presence;
    }
    if ( $hash->{STATE} ne $helper )
    {
      $hash->{STATE} = $helper;
    }
    return $response;
  }
  else
  {
    Log 1, "SIRD Command Power wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_Volume($$);
sub SIRD_Volume($$)
{

  #  cachable
  #  notifying
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';

  if ( int($params) >= 0 && int($params) <= 20 )
  {
    eval { SIRD_Com( $hash, "netRemote.sys.audio.volume", 2, $params, 0 ); };
    if ($@)
    {
      ### catch block
      Log 1, "SIRD Volume set error: $@";
      return;
    }
    SIRD_Volume( $hash, -1 );
  }
  elsif ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.sys.audio.volume", 1, 0, 0 );
#    if ($response eq "exit") {
#      exit 1;
#    }
    ## Überprüfen ob Abfrage in Ordnung war
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "Volume: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
      $ref = XMLin( $response, KeyAttr => {}, ForceArray => [] );
      if ( $ref->{status} eq 'FS_OK' )
      {
        $helper = encode_utf8( sprintf "%s", int( $ref->{value}->{u8} ) );
        if ( $hash->{READINGS}{"volumeStraight"}{VAL} ne $helper && $hash->{READINGS}{"power"}{VAL} eq "on")
        {
          # volumeStraight 0 ... 20
          readingsSingleUpdate( $hash, "volumeStraight", $helper, 1 );
        }
        $helper = encode_utf8( sprintf "%s", 5 * int( $ref->{value}->{u8} ) );
        if ( $hash->{READINGS}{"volume"}{VAL} ne $helper && $hash->{READINGS}{"power"}{VAL} eq "on")
        {
          # volume 0 ... 100
          readingsSingleUpdate( $hash, "volume", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command Volume Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_VolumeSteps($$);
sub SIRD_VolumeSteps($$)
{

  #  cachable
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';
  ##########################################
  # read only
  ##########################################
  if ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.sys.caps.volumeSteps", 1, 0, 0 );
    ## Überprüfen ob Abfrage in Ordnung war
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "VolumeSteps: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
      $ref = XMLin( $response, KeyAttr => {}, ForceArray => [] );
      if ( $ref->{status} eq 'FS_OK' )
      {
        $helper = encode_utf8( sprintf "%s", ( $ref->{value}->{u8} ) );
        if ( $hash->{READINGS}{"volumeSteps"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "volumeSteps", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command VolumeSteps wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_Mute($$);
sub SIRD_Mute($$)
{

  #  cachable
  #  notifying
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';

  if ( $params eq "on" || $params eq "off" )
  {
    if ( $params eq "on" )
    {
      $helper = '1';
    }
    elsif ( $params eq "off" )
    {
      $helper = '0';
    }
    eval { SIRD_Com( $hash, "netRemote.sys.audio.mute", 2, $helper, 0 ); };
    if ($@)
    {
      ### catch block
      Log 1, "SIRD Mute set error: $@";
      return 0;
    }
    SIRD_Mute( $hash, -1 );
  }
  elsif ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.sys.audio.mute", 1, 0, 0 );
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "Mute: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
      ## Überprüfen ob Abfrage in Ordnung war
      $ref = XMLin( $response, KeyAttr => {}, ForceArray => [] );
      if ( $ref->{status} eq 'FS_OK' )
      {
        if ( $ref->{value}->{u8} == 1 )
        {
          $helper = encode_utf8("on");
        }
        else
        {
          $helper = encode_utf8("off");
        }
        if ( $hash->{READINGS}{"mute"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "mute", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command Mute wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_Shuffle($$);
sub SIRD_Shuffle($$)
{

  #  notifying
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';

  if ( $params eq "on" || $params eq "off" )
  {
    if ( $params eq "on" )
    {
      $helper = '1';
    }
    elsif ( $params eq "off" )
    {
      $helper = '0';
    }
    eval { SIRD_Com( $hash, "netRemote.play.shuffle", 2, $helper, 0 ); };
    if ($@)
    {
      ### catch block
      Log 1, "SIRD Shuffle set error: $@";
      return 0;
    }
    SIRD_Shuffle( $hash, -1 );
  }
  elsif ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.play.shuffle", 1, 0, 0 );
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "Shuffle: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
      $ref = XMLin( $response, KeyAttr => {}, ForceArray => [] );
      ## Überprüfen ob Abfrage in Ordnung war
      if ( $ref->{status} eq 'FS_OK' )
      {
        if ( $ref->{value}->{u8} == 1 )
        {
          $helper = encode_utf8("on");
        }
        else
        {
          $helper = encode_utf8("off");
        }
        if ( $hash->{READINGS}{"shuffle"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "shuffle", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command Shuffle wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_Repeat($$);
sub SIRD_Repeat($$)
{

  #  notifying
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';

  if ( $params eq "on" || $params eq "off" )
  {
    if ( $params eq "on" )
    {
      $helper = '1';
    }
    elsif ( $params eq "off" )
    {
      $helper = '0';
    }
    eval { SIRD_Com( $hash, "netRemote.play.repeat", 2, $helper, 0 ); };
    if ($@)
    {
      ### catch block
      Log 1, "SIRD Repeat set error: $@";
      return 0;
    }
    SIRD_Repeat( $hash, -1 );
  }
  elsif ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.play.shuffle", 1, 0, 0 );
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "Repeat: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
      $ref = XMLin( $response, KeyAttr => {}, ForceArray => [] );
      ## Überprüfen ob Abfrage in Ordnung war
      if ( $ref->{status} eq 'FS_OK' )
      {
        if ( $ref->{value}->{u8} == 1 )
        {
          $helper = encode_utf8("on");
        }
        else
        {
          $helper = encode_utf8("off");
        }
        if ( $hash->{READINGS}{"repeat"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "repeat", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command Repeat wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_FriendlyName($$);
sub SIRD_FriendlyName($$)
{
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';
  ##########################################
  # read only
  ##########################################
  if ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.sys.info.friendlyName", 1, 0, 0 );
#    if ($response eq "exit") {
#      exit 1;
#    }
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "FriendlyName: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
      $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 = encode_utf8( SIRD_xml2txt( $ref->{value}->{c8_array} ) );
        }
        if ( $hash->{READINGS}{"friendlyName"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "friendlyName", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command FriendlyName wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_Version($$);
sub SIRD_Version($$)
{
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';
  ##########################################
  # read only
  ##########################################
  if ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.sys.info.version", 1, 0, 0 );
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "Version: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
      $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 = encode_utf8( SIRD_xml2txt( $ref->{value}->{c8_array} ) );
        }
        if ( $hash->{READINGS}{"version"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "version", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command Version wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_ID($$);
sub SIRD_ID($$)
{
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';
  ##########################################
  # read only
  ##########################################
  if ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.sys.info.radioID", 1, 0, 0 );
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "ID: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
      $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 = encode_utf8( SIRD_xml2txt( $ref->{value}->{c8_array} ) );
        }
        if ( $hash->{READINGS}{"radioID"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "radioID", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command ID wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_Date($$);
sub SIRD_Date($$)
{
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';
  ##########################################
  # read only at the Moment
  ##########################################
  if ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.sys.clock.localDate", 1, 0, 0 );
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "Date: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
      $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 = encode_utf8(
                           SIRD_xml2txt(
                                 substr( $ref->{value}->{c8_array}, 6, 2 ) . "."
                               . substr( $ref->{value}->{c8_array}, 4, 2 ) . "."
                               . substr( $ref->{value}->{c8_array}, 0, 4 )
                           )
          );
        }
        if ( $hash->{READINGS}{"localDate"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "localDate", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command Date wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_Time($$);
sub SIRD_Time($$)
{
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';
  ##########################################
  # read only at the Moment
  ##########################################
  if ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.sys.clock.localTime", 1, 0, 0 );
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#        Log 1, "Time: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
      $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 = encode_utf8(
                           SIRD_xml2txt(
                                 substr( $ref->{value}->{c8_array}, 0, 2 ) . ":"
                               . substr( $ref->{value}->{c8_array}, 2, 2 ) . ":"
                               . substr( $ref->{value}->{c8_array}, 4, 2 )
                           )
          );
        }
        if ( $hash->{READINGS}{"localTime"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "localTime", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command Time wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_InfoName($$);
sub SIRD_InfoName($$)
{
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';
  ##########################################
  # read only
  ##########################################
  if ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.play.info.name", 1, 0, 0 );
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "InfoName: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
      $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 = encode_utf8( SIRD_xml2txt( $ref->{value}->{c8_array} ) );
        }
        if ( $hash->{READINGS}{"currentTitle"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "currentTitle", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command InfoName wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_InfoText($$);
sub SIRD_InfoText($$)
{
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';
  ##########################################
  # read only
  ##########################################
  if ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.play.info.text", 1, 0, 0 );
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "InfoText: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
      $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 = encode_utf8( SIRD_xml2txt( $ref->{value}->{c8_array} ) );
        }
        if ( $hash->{READINGS}{"infoText"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "infoText", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command InfoText wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_InfoAlbum($$);
sub SIRD_InfoAlbum($$)
{
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';
  ##########################################
  # read only at the Moment
  ##########################################
  if ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.play.info.album", 1, 0, 0 );
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "InfoAlbum: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
      $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 = encode_utf8( SIRD_xml2txt( $ref->{value}->{c8_array} ) );
        }
        if ( $hash->{READINGS}{"currentAlbum"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "currentAlbum", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command InfoAlbum wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_InfoArtist($$);
sub SIRD_InfoArtist($$)
{
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';
  ##########################################
  # read only
  ##########################################
  if ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.play.info.artist", 1, 0, 0 );
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "InfoArtist: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
      $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 = encode_utf8( SIRD_xml2txt( $ref->{value}->{c8_array} ) );
        }
        if ( $hash->{READINGS}{"currentArtist"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "currentArtist", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command InfoArtist wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
##############################
sub SIRD_InfoGraphURI($$);
sub SIRD_InfoGraphURI($$)
{
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';
  ##########################################
  # read only
  ##########################################
  if ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.play.info.graphicUri", 1, 0, 0 );
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "InfoGraphURI: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
      $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 = encode_utf8( SIRD_xml2txt( $ref->{value}->{c8_array} ) );
        }
        if ( $hash->{READINGS}{"graphicUri"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "graphicUri", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command InfoGraphURI wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
##############################
sub SIRD_PlayPos($$);
sub SIRD_PlayPos($$)
{
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';
  ##########################################
  # read only
  ##########################################
  if ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.play.position", 1, 0, 0 );
#    if ($response eq "exit") {
#      exit 1;
#    }
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "PlayPos: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
#      else {
        $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 = encode_utf8(
                            SIRD_xml2txt(
                                  " " 
                                . int( $ref->{value}->{u32} / 60000 ) . ":"
                                . sprintf(
                                "%02d",
                                (
                                  int( $ref->{value}->{u32} / 1000 ) -
                                    ( int( $ref->{value}->{u32} / 60000 ) * 60 )
                                )
                                )
                            )
        );
        if ( $hash->{READINGS}{"currentPosition"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "currentPosition", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command PlayPos wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
##############################
sub SIRD_Duration($$);
sub SIRD_Duration($$)
{
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';
  ##########################################
  # read only
  ##########################################
  if ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.play.info.duration", 1, 0, 0 );
#    if ($response eq "exit") {
#      exit 1;
#    }
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "Duration: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
#      else {
        $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 = encode_utf8(
                            SIRD_xml2txt(
                                  " " 
                                . int( $ref->{value}->{u32} / 60000 ) . ":"
                                . sprintf(
                                "%02d",
                                (
                                  int( $ref->{value}->{u32} / 1000 ) -
                                    ( int( $ref->{value}->{u32} / 60000 ) * 60 )
                                )
                                )
                            )
        );
        if ( $hash->{READINGS}{"currentDuration"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "currentDuration", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command Duration wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_PlayRate($$);
sub SIRD_PlayRate($$)
{
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref = "";
  my $refHelper = "false";
  my $helper = ' ';
  my $helperH = "false";
  ##########################################
  # read only at the moment
  ##########################################(jb)
  if ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.play.rate", 1, 0, 0 );
###    Log 1, "Playrate Response: ".$response;
#    if ($response eq "exit") {
#      exit 1;
#    }
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "PlayRate: XML-Error: ".$@;
      }
#    if ( $response =~ /fsapiResponse/ )(jb)
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
#      else {
        $ref = XMLin( $response, KeyAttr => {}, ForceArray => [] );
#      }
      $refHelper = "true" if ! $ref || ( $ref->{status} eq "FS_OK" );
      ## Überprüfen ob Abfrage in Ordnung war
#      if ( $ref->{status} eq 'FS_OK' )
      if ( $refHelper eq "true" )
      {
        $refHelper = "false";
        # FALSE 1
##        $helperH = "true" if (! $ref->{value}->{s8} );
##        if ($helperH eq "true") {
##          $helperH = "false";
##    Log 1, "Playrate Helper 1: ".$helper;
          $helper = encode_utf8( sprintf "%s", ( $ref->{value}->{s8} ) );
##    Log 1, "Playrate Helper 2: ".$helper;
#          Log 1, "Nerv-Helper: ".$helper;
          # FALSE 1
#          if ( $hash->{READINGS}{"playRate"}{VAL} ne $helper && $helper ne "<pre> </pre>")
          if ( $hash->{READINGS}{"playRate"}{VAL} ne $helper)
          {
##    Log 1, "Playrate Helper 5: ".$helper;
            readingsSingleUpdate( $hash, "playRate", $helper, 1 );
          }
##        }
      }

    }
  }
  else
  {
    Log 1, "SIRD Command PlayRate wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_PlayCaps($$);
sub SIRD_PlayCaps($$)
{
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = "";
  ##########################################
  # read only
  ##########################################
  if ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.play.caps", 1, 0, 0 );
#    if ($response eq "exit") {
#      exit 1;
#    }
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "PlayCaps: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
#      else {
        $ref = XMLin( $response, KeyAttr => {}, ForceArray => [] );
#      }
      ## Überprüfen ob Abfrage in Ordnung war
      if ( $ref->{status} eq 'FS_OK' )

      {
        if ( ( int( $ref->{value}->{u32} ) & 1 ) > 0 )
        {
          $helper = $helper . "pause|";
        }
        if ( ( int( $ref->{value}->{u32} ) & 2 ) > 0 )
        {
          $helper = $helper . "stop|";
        }
        if ( ( int( $ref->{value}->{u32} ) & 4 ) > 0 )
        {
          $helper = $helper . "skipNext|";
        }
        if ( ( int( $ref->{value}->{u32} ) & 8 ) > 0 )
        {
          $helper = $helper . "skipPrevious|";
        }
        if ( ( int( $ref->{value}->{u32} ) & 16 ) > 0 )
        {
          $helper = $helper . "fastForward|";
        }
        if ( ( int( $ref->{value}->{u32} ) & 32 ) > 0 )
        {
          $helper = $helper . "rewind|";
        }
        if ( ( int( $ref->{value}->{u32} ) & 64 ) > 0 )
        {
          $helper = $helper . "shuffle|";
        }
        if ( ( int( $ref->{value}->{u32} ) & 128 ) > 0 )
        {
          $helper = $helper . "repeat|";
        }
        if ( ( int( $ref->{value}->{u32} ) & 256 ) > 0 )
        {
          $helper = $helper . "seek|";
        }
        if ( ( int( $ref->{value}->{u32} ) & 512 ) > 0 )
        {
          $helper = $helper . "applyFeedback|";
        }
        if ( ( int( $ref->{value}->{u32} ) & 1024 ) > 0 )
        {
          $helper = $helper . "scrobbling|";
        }
        if ( ( int( $ref->{value}->{u32} ) & 2048 ) > 0 )
        {
          $helper = $helper . "addPreset|";
        }
        chop($helper);
        $helper = encode_utf8($helper);

        if ( $hash->{READINGS}{"playCaps"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "playCaps", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command PlayCaps wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_Frequency($$);
sub SIRD_Frequency($$)
{
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';
  ##########################################
  # read only
  ##########################################
  if ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.play.frequency", 1, 0, 0 );
#    if ($response eq "exit") {
#      exit 1;
#    }
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "Frequency: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
#      else {
        $ref = XMLin( $response, KeyAttr => {}, ForceArray => [] );
#      }
      ## Überprüfen ob Abfrage in Ordnung war
      if ( $ref->{status} eq 'FS_OK' )
      {
        $helper =
          encode_utf8( sprintf( "%.2f", ( $ref->{value}->{u32} / 1000 ) ) );
        if ( $hash->{READINGS}{"frequency"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "frequency", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command Frequency wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_SignalStrength($$);
sub SIRD_SignalStrength($$)
{
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';
  ##########################################
  # read only
  ##########################################
  if ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.play.signalStrength", 1, 0, 0 );
#    if ($response eq "exit") {
#      exit 1;
#    }
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "SignalStrength: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
#      else {
        $ref = XMLin( $response, KeyAttr => {}, ForceArray => [] );
#      }
      ## Überprüfen ob Abfrage in Ordnung war
      if ( $ref->{status} eq 'FS_OK' )
      {
        $helper = encode_utf8( sprintf "%s", ( $ref->{value}->{u8} ) );
        if ( $hash->{READINGS}{"signalStrength"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "signalStrength", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command signalStrength wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_RemoteState($$);
sub SIRD_RemoteState($$)
{
  my ( $hash, $params ) = @_;
  my $response = "";
  my $responseHelper = "false";
  my $ref;
  my $helper = ' ';

  if ( $params eq "on" || $params eq "off" )
  {
    if ( $params eq "on" )
    {
      $helper = '1';
    }
    elsif ( $params eq "off" )
    {
      $helper = '0';
    }
    eval { SIRD_Com( $hash, "netRemote.nav.state", 2, $helper, 0 ); };
    if ($@)
    {
      ### catch block
      Log 1, "SIRD RemoteState set error: $@";
      return 0;
    }
    SIRD_RemoteState( $hash, -1 );
  }
  elsif ( $params eq '-1' )
  {
    $response = SIRD_Com( $hash, "netRemote.nav.state", 1, 0, 0 );
#    if ($response eq "exit") {
#      exit 1;
#    }
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "RemoteState: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
#      else {
        $ref = XMLin( $response, KeyAttr => {}, ForceArray => [] );
#      }
      ## Überprüfen ob Abfrage in Ordnung war
      if ( $ref->{status} eq 'FS_OK' )
      {
        if ( $ref->{value}->{u8} == 1 )
        {
          $helper = encode_utf8("on");
        }
        else
        {
          $helper = encode_utf8("off");
        }
        if ( $hash->{READINGS}{"remoteState"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "remoteState", $helper, 1 );
        }
      }
    }
  }
  else
  {
    Log 1, "SIRD Command RemoteState wrong Parameter: " . $params;
    return 0;
  }
  return undef;
}
###############################
sub SIRD_Input($$);
sub SIRD_Input($$)
{

  #  cachable
  #  notifying
  my ( $hash, $params ) = @_;
  my $response = "";
  my $refXMLinput = "";
  my $responseHelper = "false";
  my $ref;
  my $ref2;
  my $helper = ' ';
  my $helper2 = "";

  if ( defined( $hash->{helper}->{functionRun} )) {
    if ( $params ne '-1' ) {
      $hash->{helper}->{functionRun} = "true";
    }
    if ( $hash->{helper}->{functionRun} eq "true" ) {
      if ($hash->{Model} eq "SIRD-AUTOMATIC" ) {
        if ( defined( $hash->{helper}->{inputAll} )) {
          if ( $hash->{helper}->{inputAll} ne "0" ) {
            my $idxInput = '0';
            my @valIn = split(',', $hash->{helper}->{inputAll});
              foreach my $valIn1 (@valIn) {
              if ($params eq $valIn1) {
                $helper = $idxInput;
                $helper2 = $valIn1;
              }
              $idxInput++;
            }
            $idxInput = '0';
          }
        }
      }
    }
  }
  if ( $params eq $helper2 ) {
    eval { SIRD_Com( $hash, "netRemote.sys.mode", 2, $helper, 0 ); };
    if ($@)
    {
      ### catch block
      Log 1, "SIRD Input set error: $@";
      return 0;
    }
    SIRD_Input( $hash, -1 );
  }
  elsif ( $params eq '-1' ) {
    if ( defined( $hash->{helper}->{functionRun} )) {
      if ( $hash->{helper}->{functionRun} eq "true" ) {
        if ($hash->{Model} eq "SIRD-AUTOMATIC" ) {
          $response = SIRD_Com( $hash, "netRemote.sys.mode", 1, 0, 0 );
          my $response2 = SIRD_Com( $hash, "netRemote.sys.caps.validModes/-1", 4, 0, 100 );
          $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
          my $refXML = eval {
            XMLin( $response, KeyAttr => {}, ForceArray => [] );
          };
          if($@) {
            $responseHelper = "false";
          }
          if ( $responseHelper eq "true" )
          {
            my $responseXMLinput = "";
            my $listpos1 = '0';
            my $listpos2 = '0';
            my $listNamePos1 = '0';
            my $listNamePos2 = '0';
            my $listName2 = "";
            my $listName3 = "";
            my $idxInput = '0';
            my $substr1 = '0';
            my $substr2 = '0';
            my $substr3 = '0';
            my $substr4 = '0';

            $responseHelper = "false";
            $ref = XMLin( $response, KeyAttr => {}, ForceArray => [] );
            $ref2 = XMLin( $response2, KeyAttr => {}, ForceArray => [] );
            ## Überprüfen ob Abfrage in Ordnung war
            if ( $ref->{status} eq 'FS_OK' && $ref2->{status} eq 'FS_OK' )
            {
              if (! defined( $hash->{helper}->{input1}) || ($hash->{helper}->{input1} ne $ref)) {
                $hash->{helper}->{input1} = $ref;
              }
              if (! defined( $hash->{helper}->{input2}) || ($hash->{helper}->{input2} ne $response2)) {
                $hash->{helper}->{input2} = $response2;
              }
              $responseXMLinput = $hash->{helper}->{input2};
#Log 1, "ResponseXMLinput: ".$responseXMLinput;              
              if ( defined( $hash->{helper}->{input1} )
              && defined( $hash->{helper}->{input2} )
              && ref( $hash->{helper}->{input1}->{value} ) eq "HASH" )
              {
                if ( $hash->{helper}->{input1}->{'status'} eq "FS_OK" )
                {
                  $responseXMLinput  = $hash->{helper}->{input2};
                  if ($responseXMLinput =~ /streamable/) {
                    $substr1 = '0';
                    $substr2 = '31';
                    $substr3 = '0';
                    $substr4 = '43';
                  }
                  else {
                    $substr1 = '0';
                    $substr2 = '31';
                    $substr3 = '0';
                    $substr4 = '21';
                  }
                  while ($responseXMLinput =~ /table"><u8>|labe|l"><c8_array>|streamable|<\/c8_array><\/field>\n\n/g) {
                    if ( $listpos1 eq '0' && $listpos2 eq '0' && $listNamePos1 eq '0' && $listNamePos2 eq '0' ) {
                      $listpos1 = pos ($responseXMLinput) + $substr1;
                    }
                    elsif ( $listpos1 ne '0' && $listpos2 eq '0' && $listNamePos1 eq '0' && $listNamePos2 eq '0'  ) {
                      $listpos2 = pos ($responseXMLinput) - $substr2;
                    }
                    elsif ( $listpos1 ne '0' && $listpos2 ne '0' && $listNamePos1 eq '0' && $listNamePos2 eq '0'  ) {
                      $listNamePos1 = pos ($responseXMLinput) + $substr3;
                    }
                    elsif ( $listpos1 ne '0' && $listpos2 ne '0' && $listNamePos1 ne '0' && $listNamePos2 eq '0'  ) {
                      $listNamePos2 = pos ($responseXMLinput) - $substr4;
                    }
                    if ( $listpos1 ne '0' && $listpos2 ne '0' && $listNamePos1 ne '0' && $listNamePos2 ne '0'  ) {
                      my $listpos3 = $listpos2 - $listpos1;
                      my $listNamePos3 = $listNamePos2 - $listNamePos1;
                      my $select1 = substr($responseXMLinput,$listpos1,$listpos3);
                      my $listName1 = substr($responseXMLinput,$listNamePos1,$listNamePos3);
                      $listName1 = SIRD_space2sub ($listName1);
                      if ($select1 == '1' ) {
                        $listName2 .= "<".$listName1.">";
                      }
                      if ( $listName3 ne "" && $select1 == '1') {
                        $listName3 .= ",";
                      }
                      if ($select1 == '1' ) {
                        $listName3 .= $listName1;
                      }
                      $listpos1 = '0';
                      $listpos2 = '0';
                      $listNamePos1 = '0';
                      $listNamePos2 = '0';
                    }
                  }
                  if ( !defined( $hash->{helper}->{inputRead} )) {
                    $hash->{helper}->{inputRead} = "0";
                  }
                  if ( !defined( $hash->{helper}->{inputAll} )) {
                    $hash->{helper}->{inputAll} = "0";
                  }
                  if ($listName2 ne "" && $hash->{helper}->{inputRead} ne $listName2) {
                    $hash->{helper}->{inputRead} = $listName2;
                  }
                  if ($listName3 ne "" && $hash->{helper}->{inputAll} ne $listName3) {
                    $hash->{helper}->{inputAll} = $listName3;
                    $hash->{helper}->{browserRefresh} = "true";
                  }
                  my @valIn = split(',', $listName3);
                  foreach my $valIn1 (@valIn) {
                   if ($idxInput == int( $ref->{value}->{u32} )) {
                     $helper = $valIn1;
                   }
                    $idxInput++;
                  }
                  $idxInput = '0';
##########################################################################################################################################  
#Log 1, $ref->{value}->{u32};
#Log 1, $helper;
                  if ( $hash->{Model} eq "sird" )
                  {
                    if ( int( $ref->{value}->{u32} ) == 0 )
                    {
                      $helper = "InternetRadio";
                    }
                  }
##########################################################################################################################################
                  $helper = encode_utf8($helper);
                  if ( !defined( $hash->{READINGS}->{input} )) {
                    readingsSingleUpdate( $hash, "input", "0", 1 );
                  }
                  if ( !defined( $hash->{READINGS}->{inputSelectable} )) {
                    readingsSingleUpdate( $hash, "inputSelectable", "0", 1 );
                  }
                  if ($hash->{READINGS}{"input"}{VAL} ne $helper ) {
                    readingsSingleUpdate( $hash, "input", $helper, 1 );
                  }
                  if ($hash->{READINGS}{"inputSelectable"}{VAL} ne $hash->{helper}->{inputRead} ) {
                    readingsSingleUpdate( $hash, "inputSelectable", $hash->{helper}->{inputRead}, 1 );
                  }
                }
                else
                {
                  Log 1, "SIRD Command Input wrong Parameter: " . $params;
                  return 0;
                }
                return undef;
              }
            }   
	      }
        }
      }
	}
#  }
#  if ( $params eq '-1' )
#  {
###############################
    sub SIRD_GetNotify($);
    sub SIRD_GetNotify($)
    {
      my ($hash) = @_;
      my $response =
        SIRD_Com(
                  $hash,
                  "GET_NOTIFIES?pin="
                    . $hash->{PASSWORD} . "&sid="
                    . $hash->{SESSIONID},
                  0,
                  0,
                  0
        );
      my $responseHelper = "false";
      my $ref;
      my $helper = "";
      my $incer  = 0;
      my $helpref;
#    if ($response eq "exit") {
#      exit 1;
#    }
    $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      my $refXML = eval {
        XMLin( $response, KeyAttr => {}, ForceArray => [] );
      };
      if($@) {
        $responseHelper = "false";
#Log 1, "GetNotify: XML-Error: ".$@;
      }
    if ( $responseHelper eq "true" )
    {
      $responseHelper = "false";
#      else {
        $ref = XMLin( $response, KeyAttr => {}, ForceArray => [] );
#      }
        ## Überprüfen ob Abfrage in Ordnung war
        if ( $ref->{status} eq 'FS_OK' )
        {

          if ( ref( $ref->{'notify'} ) eq "ARRAY" )
          {
            for my $notify ( @{ $ref->{'notify'} } )
            {

              $helpref = $notify;
              SIRD_NotifyHelper( $hash, $helpref );
            }
          }
          elsif ( ref( $ref->{'notify'} ) eq "HASH" )
          {
            $helpref = $ref->{notify};
            SIRD_NotifyHelper( $hash, $helpref );
          }

        }
      }
      return undef;
    }
###############################
    sub SIRD_NotifyHelper ($$);
    sub SIRD_NotifyHelper ($$)
    {
      my ( $hash, $notify ) = @_;
      my $helper   = "";
      my $presence = "";

      # POWER$
      #readingsBeginUpdate($hash);

      # if ($ref->{"netRemote.sys.power"}->{value}->{u8} == 1)
      # {
      #	$helper = "on";
      # }
      # else
      # {
      # $helper = "off";
      # }
      # readingsBeginUpdate($hash);
      # if ($hash->{READINGS}{"presence"}{VAL} ne  $presence)
      # {
      # readingsBulkUpdate($hash, "presence", $presence , 1);
      # }
      # if ($hash->{READINGS}{"power"}{VAL} ne $helper)
      # {
      # readingsBulkUpdate($hash, "power", $helper , 1);
      # }
      # readingsEndUpdate($hash, 0);
      # # STATE setzen
      # if ($presence eq "absent")
      # {
      # $helper = $presence;
      # }
      # if ($hash->{STATE} ne $helper)
      # {
      # $hash->{STATE} = $helper;
      # }
      # }

      # VOLUME
      if ( exists $notify->{node} && $notify->{node} eq 'netremote.sys.audio.volume' )
      {
        print "TestVol";
        if ( $hash->{READINGS}{"volumeStraight"}{VAL} != int( $notify->{value}->{u8} ) )
        {

          # volumeStraight 0 ... 20
          readingsSingleUpdate( $hash, "volumeStraight", $notify->{value}->{u8}, 1 );

          #  volume 0 ... 100
          readingsSingleUpdate( $hash, "volume", 5 * $notify->{value}->{u8}, 1 );

        }
      }

      # INFOTEXT
      if ( exists $notify->{node}
           && $notify->{node} eq 'netremote.play.info.text' )
      {
        print "TestInfoText";
        if ( !ref $notify->{value}->{c8_array} )
        {
          $helper = SIRD_xml2txt( $notify->{value}->{c8_array} );
        }
        if ( $hash->{READINGS}{"infoText"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "infoText", $helper, 1 );
        }
      }

      # INFONAME
      if ( exists $notify->{node}
           && $notify->{node} eq 'netremote.play.info.name' )
      {
        print "TestInfoName";
        if ( !ref $notify->{value}->{c8_array} )
        {
          $helper = SIRD_xml2txt( $notify->{value}->{c8_array} );
        }
        if ( $hash->{READINGS}{"currentTitle"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "currentTitle", $helper, 1 );
        }
      }

      # MUTE
      if ( exists $notify->{node}
           && $notify->{node} eq 'netremote.sys.audio.mute' )
      {
        print "TestMute";
        if ( $notify->{value}->{u8} == 1 )
        {
          $helper = "on";
        }
        else
        {
          $helper = "off";
        }
        if ( $hash->{READINGS}{"mute"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "mute", $helper, 1 );
        }
      }

      # REPEAT
      if ( exists $notify->{node}
           && $notify->{node} eq 'netremote.play.repeat' )
      {
        print "TestRepeat";
        if ( $notify->{value}->{u8} == 1 )
        {
          $helper = "on";
        }
        else
        {
          $helper = "off";
        }
        if ( $hash->{READINGS}{"repeat"}{VAL} ne $helper )
        {

          readingsSingleUpdate( $hash, "repeat", $helper, 1 );

        }
      }

      # SHUFFLE
      if ( exists $notify->{node}
           && $notify->{node} eq 'netremote.play.shuffle' )
      {
        print "TestShuffle";
        if ( $notify->{value}->{u8} == 1 )
        {
          $helper = "on";

        }
        else
        {
          $helper = "off";
        }
        if ( $hash->{READINGS}{"shuffle"}{VAL} ne $helper )
        {

          readingsSingleUpdate( $hash, "shuffle", $helper, 1 );
        }
      }

      # MODE bzw. input
      if ( exists $notify->{node} && $notify->{node} eq 'netremote.sys.mode' )
      {
        print "TestInput";
        if ( int( $notify->{value}->{u32} ) == 0 )
        {
          $helper = "InternetRadio";
        }
        elsif ( int( $notify->{value}->{u32} ) == 1 )
        {
          $helper = "Spotify";
        }
        elsif ( int( $notify->{value}->{u32} ) == 2 )
        {
          $helper = "MediaPlayer";
        }
        elsif ( int( $notify->{value}->{u32} ) == 3 )
        {
          $helper = "DAB-Radio";
        }
        elsif ( int( $notify->{value}->{u32} ) == 4 )
        {
          $helper = "FM-Radio";
        }
        elsif ( int( $notify->{value}->{u32} ) == 5 )
        {
          $helper = "AUX";
        }
        else
        {
          $helper = "Unknown";
        }
        if ( $hash->{READINGS}{"input"}{VAL} ne $helper )
        {

          readingsSingleUpdate( $hash, "input", $helper, 1 );
        }
      }

      # PLAYSTATUS
      if ( exists $notify->{node}
           && $notify->{node} eq 'netremote.play.status' )
      {
        print "TestPlay";
        if ( int( $notify->{value}->{u8} ) == 0 )
        {
          $helper = "idle";
        }
        elsif ( int( $notify->{value}->{u8} ) == 1 )
        {
          $helper = "buffering";
        }
        elsif ( int( $notify->{value}->{u8} ) == 2 )
        {
          $helper = "playing";
        }
        elsif ( int( $notify->{value}->{u8} ) == 3 )
        {
          $helper = "paused";
        }
        elsif ( int( $notify->{value}->{u8} ) == 4 )
        {
          $helper = "rebuffering";
        }
        elsif ( int( $notify->{value}->{u8} ) == 5 )
        {
          $helper = "error";
        }
        else
        {
          $helper = "unknown";
        }
        if ( $hash->{READINGS}{"playStatus"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "playStatus", $helper, 1 );
        }
      }

      # PLAYSERVICEIDS.ECC
      if ( exists $notify->{node}
           && $notify->{node} eq 'netremote.play.serviceIds.ecc' )
      {
        print "TestServiceids.ecc";
        if ( $hash->{READINGS}{"serviceIdsEcc"}{VAL} !=
             int( $notify->{value}->{u8} ) )
        {
          readingsSingleUpdate( $hash, "serviceIdsEcc", $notify->{value}->{u8},
                                1 );

        }
      }

      #netRemote.nav.status
      #netRemote.nav.action.dabScan
      #to be done
      #readingsEndUpdate($hash, 0);

      return undef;
    }
###############################
    sub SIRD_PlayMode($$);
    sub SIRD_PlayMode($$)
    {

      #  cachable
      #  notifying
      my ( $hash, $params ) = @_;
      my $response = "";
      my $responseHelper = "false";
      my $ref;
      my $helper = ' ';

      if (    $params eq "stop"
           || $params eq "play"
           || $params eq "pause"
           || $params eq "next"
           || $params eq "previous" )
      {
        if ( $params eq "stop" )
        {
          $helper = '0';
        }
        elsif ( $params eq "play" )
        {
          $helper = '1';
        }
        elsif ( $params eq "pause" )
        {
          $helper = '2';
        }
        elsif ( $params eq "next" )
        {
          $helper = '3';
        }
        elsif ( $params eq "previous" )
        {
          $helper = '4';
        }
        eval { SIRD_Com( $hash, "netRemote.play.control", 2, $helper, 0 ); };
        if ($@)
        {
          ### catch block
          Log 1, "SIRD PlayMode error: $@";
          return 0;
        }
      }
      elsif ( $params eq '-1' )
      {
        $response = SIRD_Com( $hash, "netRemote.play.status", 1, 0, 0 );
#        if ($response eq "exit") {
#          exit 1;
#        }
        $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
          my $refXML = eval {
            XMLin( $response, KeyAttr => {}, ForceArray => [] );
          };
          if($@) {
            $responseHelper = "false";
#Log 1, "PlayMode: XML-Error: ".$@;
          }
        if ( $responseHelper eq "true" )
        {
          $responseHelper = "false";
#          else {
            $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";
            }
            $helper = encode_utf8($helper);
            if ( $hash->{READINGS}{"playStatus"}{VAL} ne $helper )
            {
              readingsSingleUpdate( $hash, "playStatus", $helper, 1 );
            }
          }
        }
      }
      else
      {
        Log 1, "SIRD Command PlayStatus wrong Parameter: " . $params;
        return 0;
      }
      return undef;
    }
###############################
    sub SIRD_NavStatus($$);
    sub SIRD_NavStatus($$)
    {
      my ( $hash, $params ) = @_;
      my $response = "";
      my $responseHelper = "false";
      my $ref;
      my $helper = ' ';
      ##########################################
      # read only
      # notifying
      ##########################################
      if ( $params eq '-1' )
      {
        $response = SIRD_Com( $hash, "netRemote.nav.status", 1, $0, 0 );
#        if ($response eq "exit") {
#          exit 1;
#        }
        $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
          my $refXML = eval {
            XMLin( $response, KeyAttr => {}, ForceArray => [] );
          };
          if($@) {
            $responseHelper = "false";
#Log 1, "NavStatus: XML-Error: ".$@;
          }
        if ( $responseHelper eq "true" )
        {
          $responseHelper = "false";
#          else {
            $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 = "waiting";
            }
            elsif ( int( $ref->{value}->{u8} ) == 1 )
            {
              $helper = "ready";
            }
            elsif ( int( $ref->{value}->{u8} ) == 2 )
            {
              $helper = "fail";
            }
            elsif ( int( $ref->{value}->{u8} ) == 3 )
            {
              $helper = "fatalError";
            }
            elsif ( int( $ref->{value}->{u8} ) == 4 )
            {
              $helper = "readyRoot";
            }
            else
            {
              $helper = "unknown";
            }
            if ( $hash->{READINGS}{"navStatus"}{VAL} ne $helper )
            {
              readingsSingleUpdate( $hash, "navStatus", $helper, 1 );
            }
          }
        }
      }
      else
      {
        Log 1, "SIRD Command NavStatus wrong Parameter: " . $params;
        return 0;
      }
      return undef;
    }
###############################
    sub SIRD_NavCaps($$);
    sub SIRD_NavCaps($$)
    {
      my ( $hash, $params ) = @_;
      my $response = "";
      my $responseHelper = "false";
      my $ref;
      my $helper = ' ';
      ##########################################
      # read only
      ##########################################
      if ( $params eq '-1' )
      {
        $response = SIRD_Com( $hash, "netRemote.nav.caps", 1, $0, 0 );
#        if ($response eq "exit") {
#          exit 1;
#        }
        $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
          my $refXML = eval {
            XMLin( $response, KeyAttr => {}, ForceArray => [] );
          };
          if($@) {
            $responseHelper = "false";
#Log 1, "NavCaps: XML-Error: ".$@;
          }
        if ( $responseHelper eq "true" )
        {
          $responseHelper = "false";
#          else {
            $ref = XMLin( $response, KeyAttr => {}, ForceArray => [] );
#          }
          ## Überprüfen ob Abfrage in Ordnung war
          if ( $ref->{status} eq 'FS_OK' )
          {
            $helper = sprintf "%s", int( $ref->{value}->{u32} );
            if ( $hash->{READINGS}{"navCaps"}{VAL} ne $helper )
            {
              readingsSingleUpdate( $hash, "navCaps", $helper, 1 );
            }
          }
        }
      }
      else
      {
        Log 1, "SIRD Command NavCaps wrong Parameter: " . $params;
        return 0;
      }
      return undef;
    }
###############################
    sub SIRD_NavNumItems($$);
    sub SIRD_NavNumItems($$)
    {
      my ( $hash, $params ) = @_;
      my $response = "";
      my $responseHelper = "false";
      my $ref;
      my $helper = ' ';
      ##########################################
      # read only
      ##########################################
      if ( $params eq '-1' )
      {
        $response = SIRD_Com( $hash, "netRemote.nav.numItems", 1, $0, 0 );
        $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
          my $refXML = eval {
            XMLin( $response, KeyAttr => {}, ForceArray => [] );
          };
          if($@) {
            $responseHelper = "false";
          }
        if ( $responseHelper eq "true" )
        {
          $responseHelper = "false";
          $ref = XMLin( $response, KeyAttr => {}, ForceArray => [] );
          ## Überprüfen ob Abfrage in Ordnung war
          if ( $ref->{status} eq 'FS_OK' )
          {
            $helper = sprintf "%s", int( $ref->{value}->{s32} );
            if ( $hash->{READINGS}{"navNumItems"}{VAL} ne $helper )
            {
              readingsSingleUpdate( $hash, "navNumItems", $helper, 1 );
            }
          }
        }
      }
      else
      {
        Log 1, "SIRD Command NavNumItems wrong Parameter: " . $params;
        return 0;
      }
      return undef;
    }
###############################
    sub SIRD_NavList($$$);
    sub SIRD_NavList($$$)
    {
      my ( $hash, $start, $end ) = @_;
      my $helper = "unknown";
      my $response = SIRD_Com( $hash, "netRemote.nav.list", 3, $start, $end );
      my $responseHelper = "false";
      my $ref;

#Log 1, "Response: ".$response;              
      $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
        my $refXML = eval {
          XMLin( $response, KeyAttr => {}, ForceArray => [] );
        };
        if($@) {
          $responseHelper = "false";
        }
      if ( $responseHelper eq "true" )
      {
        $responseHelper = "false";
        $ref = XMLin( $response, KeyAttr => {}, ForceArray => [] );
        ## Überprüfen ob Abfrage in Ordnung war
        if ( $ref->{status} eq 'FS_OK' )
        {
          delete $hash->{helper}->{navList};
          $hash->{helper}->{navList} = $ref;
          if ($hash->{helper}->{navlistXML} ne $response) {
            $hash->{helper}->{navlistXML} = $response;
          }
        }
      }
      return undef;
    }
###############################
    sub SIRD_PresetList($$);
    sub SIRD_PresetList($$)
    {
      my ( $hash, $params ) = @_;
      my $response = "";
      my $responseHelper = "false";
      my $ref;
      my $helper = ' ';
      my $preset = "";
      my $presetList1  = "";
      my $presetList2  = "";
      my $presetListC  = '0';
      my $FC = '0';
      ##########################################
      # read only
      ##########################################
      if ( $hash->{helper}->{functionRun} eq "true" ) {
        if ( $params eq '-1' )
        {
          $response = SIRD_Com( $hash, "netRemote.nav.presets", 3, -1, 20 );
          $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
          my $refXML = eval {
            XMLin( $response, KeyAttr => {}, ForceArray => [] );
          };
          if($@) {
            $responseHelper = "false";
          }
          if ( $responseHelper eq "true" )
          {
            $responseHelper = "false";
            $ref = XMLin( $response, KeyAttr => {}, ForceArray => [] );
            ## Überprüfen ob Abfrage in Ordnung war
            if ( $ref->{status} eq 'FS_OK' )
            {
              delete $hash->{helper}->{preset};
              $hash->{helper}->{preset} = $ref;
              if ($hash->{helper}->{presetXML} ne $response) {
                $hash->{helper}->{presetXML} = $response;
              }
              if ( defined( $hash->{helper}->{preset} ) && ref( $hash->{helper}->{preset}->{item} ) eq "ARRAY" )
              {
                if ( ref( $hash->{helper}->{preset}->{'item'} ) eq "ARRAY" )
                {
                  for my $item ( @{ $hash->{helper}->{preset}->{'item'} } )
                  {
                    if ( exists $item->{'field'}->{c8_array} && ref( $item->{'field'}->{c8_array} ) ne "HASH" )
                    {
                      # Im HASH: Leerzeichen entfernen und in utf umwandeln
                      $item->{'field'}->{c8_array} = SIRD_xml2txt( SIRD_space2sub( $item->{'field'}->{c8_array} ) );
                    }
                    $presetListC++;
                    if ($presetListC >= 10) {
                      $presetListC = '0'
                    }
                    # $presetliste mit Kommas zusammenbauen
                    my $listName = $item->{'field'}->{c8_array};
                    while ($listName =~ /HASH/) {
                      $listName = "--PRESET-FREE--";
                    }
                    if ($presetListC >= 1 && $presetListC <= 5) {
                      $presetList1 .= "<P".$presetListC.": ";
                      $presetList1 .= $listName;
                      $presetList1 .= ">";
                    }
                    else {
                      $presetList2 .= "<P".$presetListC.": ";
                      $presetList2 .= $listName;
                      $presetList2 .= ">";
                    }
                    if ( $preset ne "" )
                    {
                    $preset .= ',';
                    }
                    $preset .= $listName;
                  }
                  $preset = encode_utf8($preset);
                  if ( !defined( $hash->{helper}->{presetAll} )) {
                    $hash->{helper}->{presetAll} = "0";
                  }
                  if ( !defined( $hash->{helper}->{preset1_5} )) {
                    $hash->{helper}->{preset1_5} = "0";
                  }
                  if ( !defined( $hash->{helper}->{preset6_0} )) {
                    $hash->{helper}->{preset6_0} = "0";
                  }
                  if ($hash->{helper}->{presetAll} ne $preset) {
                    $hash->{helper}->{presetAll} = $preset;
                  }
                  if ($hash->{helper}->{preset1_5} ne $presetList1) {
                    $hash->{helper}->{preset1_5} = $presetList1;
                  }
                  if ($hash->{helper}->{preset6_0} ne $presetList2) {
                    $hash->{helper}->{preset6_0} = $presetList2;
                  }
                  $presetListC = '0';
                }
              }
            }
          }
        }
        else
        {
          Log 1, "SIRD Command PresetList wrong Parameter: " . $params;
          return 0;
        }
        $FC++;
        $hash->{helper}->{FunctionCounter} = $FC;
        return undef;
      }
    }
###############################
    sub SIRD_SearchTerm($$);
    sub SIRD_SearchTerm($$)
    {
      my ( $hash, $params ) = @_;
      my $response = "";
      my $responseHelper = "false";
      my $ref;
      my $helper = ' ';

      if ( $params ne '-1' )
      {
        eval { SIRD_Com( $hash, "netRemote.nav.searchTerm", 2, $params, 0 ); };
        if ($@)
        {
          ### catch block
          Log 1, "SIRD SearchTerm error: $@";
          return 0;
        }
        SIRD_SearchTerm( $hash, -1 );
      }
      else
      {
        $response = SIRD_Com( $hash, "netRemote.nav.searchTerm", 1, 0, 0 );
#        if ($response eq "exit") {
#          exit 1;
#        }
        $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
          my $refXML = eval {
            XMLin( $response, KeyAttr => {}, ForceArray => [] );
          };
          if($@) {
            $responseHelper = "false";
#Log 1, "SearchTerm: XML-Error: ".$@;
          }
        if ( $responseHelper eq "true" )
        {
          $responseHelper = "false";
#          else {
            $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 = encode_utf8( $ref->{value}->{c8_array} );
            }
            if ( $hash->{READINGS}{"searchTerm"}{VAL} ne $helper )
            {
              readingsSingleUpdate( $hash, "searchTerm", $helper, 1 );
            }
          }
        }
      }
      return undef;
    }
##############################
    sub SIRD_DABScan($$);
    sub SIRD_DABScan($$)
    {

      #notifying
      my ( $hash, $params ) = @_;
      my $response = "";
      my $responseHelper = "false";
      my $ref;
      my $helper = ' ';

      if ( $params eq "idle" || $params eq "scan" )
      {
        if ( $params eq "scan" )
        {
          $helper = '1';
        }
        elsif ( $params eq "idle" )
        {
          $helper = '0';
        }
        eval
        {
          SIRD_Com( $hash, "netRemote.nav.action.dabScan", 2, $helper, 0 );
        };
        if ($@)
        {
          ### catch block
          Log 1, "SIRD DABScan error: $@";
          return 0;
        }
        SIRD_DABScan( $hash, -1 );
      }
      elsif ( $params eq '-1' )
      {
        $response = SIRD_Com( $hash, "netRemote.nav.action.dabScan", 1, 0, 0 );
#        if ($response eq "exit") {
#          exit 1;
#        }
        $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
          my $refXML = eval {
            XMLin( $response, KeyAttr => {}, ForceArray => [] );
          };
          if($@) {
            $responseHelper = "false";
#Log 1, "DABScan: XML-Error: ".$@;
          }
        if ( $responseHelper eq "true" )
        {
          $responseHelper = "false";
#          else {
            $ref = XMLin( $response, KeyAttr => {}, ForceArray => [] );
#          }
          ## Überprüfen ob Abfrage in Ordnung war
          if ( $ref->{status} eq 'FS_OK' )
          {
            if ( $ref->{value}->{u8} == 0 )
            {
              $helper = encode_utf8("idle");
            }
            else
            {
              $helper = encode_utf8("scan");
            }
            if ( $hash->{READINGS}{"dABScan"}{VAL} ne $helper )
            {
              readingsSingleUpdate( $hash, "dABScan", $helper, 1 );
            }
          }
        }
      }
      else
      {
        Log 1, "SIRD Command DABScan wrong Parameter: " . $params;
        return 0;
      }
      return undef;
    }
###############################
    sub SIRD_Logoff($);
    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($$$);
    sub SIRD_Define($$$)
    {
      my ( $hash, $def ) = @_;
      my @a = split( "[ \t][ \t]*", $def );
      my $u = "wrong syntax: define <name> SIRD IP Password TYP [interval]";
#      my $name = $a_[0];
      return $u if ( int(@a) < 4 );

      $hash->{IP}   = $a[2];
#      $hash->{test} = ( int(@a) );

      if ( int(@a) == 6 || int(@a) == 5 )
      {
        $hash->{PASSWORD} = $a[3];

        #    $hash->{PASSWORD} = $a[3];
      }
      else
      {
        Log $hash->{logLevel}, "TEST else to Password @" . $hash->{PASSWORD};
        $hash->{PASSWORD} = "";
      }

      $hash->{Model} = $a[4];

      $hash->{logLevel} = 3;
      my $result = SIRD_Login($hash);
      if ( $result == 1 )
      {
        $hash->{STATE} = "initialized";

      }
      if ( defined( $a[5] ) and $a[5] > 10 )
      {
        $hash->{INTERVAL} = $a[5];
      }
      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 = "";
      my $responseHelper = "false";
      my $helpC = '0';
      my $retExit = "exit";
      START:

      if ( $mode == 0 )    #nonspecific
      {
        $helper = "http://" . $hash->{IP} . ":80/fsapi/" . $Command;
        $response = GetFileFromURL( $helper, 10, "", 1, 5 );
        $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      }
      elsif ( $mode == 1 )    # GET     #/fsapi/GET/netRemote.sys.mode?pin=1337&sid=300029608
      {
        $helper =
            "http://"
          . $hash->{IP}
          . ":80/fsapi/GET/"
          . $Command . "?pin="
          . $hash->{PASSWORD} . "&sid="
          . $hash->{SESSIONID};
        $response = GetFileFromURL( $helper, 2, "", 1, 5 );
        $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      }
      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 );
        $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      }
      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 );
        $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      }
      elsif ( $mode == 4 )    # LIST_GET_NEXT VALID MODES  #/fsapi/LIST_GET_NEXT/netRemote.sys.caps.validModes/-1?pin=1337&sid=300029608&maxItems=100
      {
        $helper =
            "http://"
          . $hash->{IP}
          . ":80/fsapi/LIST_GET_NEXT/"
          . $Command
          . "?pin="
          . $hash->{PASSWORD}
          . "&sid="
          . $hash->{SESSIONID}
          . "&maxItems="
          . $value1;
        $response = GetFileFromURL( $helper, 2, "", 1, 5 );
        $responseHelper = "true" if ! $response || ( $response =~ /fsapiResponse/ );
      }
      if ( $responseHelper eq "true" )
      {
        $responseHelper = "false";
        $helpC = '0';
        return $response;
      }
      elsif ( $responseHelper eq "false" )
      {
#Log 2, "FALSE 1: ".$response." HELP Counter: ".$helpC;
#Log 2, "Hash: ".$hash." Command: ".$Command." Mode: ".$mode." Value: ".$value." Value 1: ".$value1." Name: ".$name." Helper: ".$helper;
        $helpC = $helpC + '1';
        if ($helpC >= '3') {
          Log 2, "(return undef) FALSE 2: ".$response." HELP Counter: ".$helpC;
          $helpC = '0';
          return undef;
        }
        else {
          sleep(1);
          goto START;
        }
      }
    }
###############################
    sub SIRD_GetStatus($$);
    sub SIRD_GetStatus($$)
    {

      my ( $hash, $local ) = @_;
      my $name   = $hash->{NAME};
      my $helper = 1;
#     $local = 1;
      $hash->{logLevel} = GetLogLevel($name);
#      my $name = $hash->{name};
      $attr{$name}{"presetListRequestMode"} = "0" unless(defined($attr{$name}{"presetListRequestMode"}));
#      Log 1, "Name Test: ".$name;
      my $PLR_ = $attr{$name}{"presetListRequestMode"};
      

#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_Power( $hash, '-1' );

      if ( $helper eq '' or !defined( $hash->{SESSIONID} ) )
      {
        ### catch block
        SIRD_Login($hash);
        SIRD_Power( $hash, '-1' );
      }

      if (defined $hash->{helper}->{browserRefresh} && $hash->{helper}->{browserRefresh} eq "true") {
        $hash->{helper}->{browserRefresh} = "false";
        SIRD_refresh("WEB");
      }

      if ( $hash->{STATE} eq "on" )
      {

        #SIRD_GetNotify($hash);
        SIRD_FriendlyName( $hash, '-1' );
        SIRD_Version( $hash, '-1' );
        SIRD_ID( $hash, '-1' );
        SIRD_Volume( $hash, '-1' );
        SIRD_Mute( $hash, '-1' );
        SIRD_Input( $hash, '-1' );
        SIRD_InfoName( $hash, '-1' );
        SIRD_InfoText( $hash, '-1' );
        SIRD_RemoteState( $hash, '-1' );
        SIRD_PlayMode( $hash, '-1' );
        SIRD_Shuffle( $hash, '-1' );
        SIRD_Repeat( $hash, '-1' );
        SIRD_InfoAlbum( $hash, '-1' );
        SIRD_InfoArtist( $hash, '-1' );
        SIRD_PlayRate( $hash, '-1' );
        SIRD_PlayPos( $hash, '-1' );
        SIRD_Duration( $hash, '-1' );
        SIRD_InfoGraphURI( $hash, '-1' );
        SIRD_SignalStrength( $hash, '-1' );
        SIRD_NavCaps( $hash, '-1' );
        SIRD_NavNumItems( $hash, '-1' );
        SIRD_PlayCaps( $hash, '-1' );
        SIRD_VolumeSteps( $hash, '-1' );
        SIRD_Time( $hash, '-1' );
        SIRD_Date( $hash, '-1' );
        SIRD_SearchTerm( $hash, '-1' );
        SIRD_NavStatus( $hash, '-1' );
        SIRD_DABScan( $hash, '-1' );
        SIRD_Frequency( $hash, '-1' );
#        SIRD_NavList( $hash, '-1' );

#        if ( $hash->{READINGS}{"presetListRequestMode"}{VAL} ne $PLR_ )
#        {
#          Log 1, "ON ATTR PLR Test: ".$PLR_;
#          readingsSingleUpdate( $hash, "presetListRequestMode", $PLR_, 1 );
#        }
#        if ( $hash->{READINGS}{"presetListRequestMode"}{VAL} eq "1" || $hash->{READINGS}{"presetListRequestMode"}{VAL} eq "3" )
#        {
#          Log 1, "ON PLR Test: ".$PLR_;
          SIRD_PresetList( $hash, '-1' );
#        }


#        SIRD_PresetList( $hash, '-1' );xxx
#$helper = $helper + $attr{$name}{"volumeStep"};
#          $helper = $attr{$name}{"navListItems"};

#        my $PLR_ = $attr{$name}{"PresetListRequest"};
#        if ( $PLR_ eq "1" || $PLR_ eq "3" )
#        {
#          SIRD_PresetList( $hash, '-1' );
#          Log 1, "PresetListRequest ON";
#        }







        if ( $hash->{READINGS}{"remoteState"}{VAL} ne "on" )
        {
          SIRD_RemoteState( $hash, "on" );
        }

#        my $VolHelper = $hash->{READINGS}{"volume"}{VAL};
#        if ( $hash->{READINGS}{"volume"}{VAL} ne $VolHelper )
#        {
#          readingsSingleUpdate( $hash, "volume", $helper, 1 );
#        }

        #		if ($hash->{READINGS}{"remoteState"}{VAL} eq "on")
        #		{
        #		SIRD_NavList
        #		}
      }

      else
      {
        $helper = encode_utf8(" ");

#        if ( $hash->{READINGS}{"volume"}{VAL} ne '0' )
#        {
#          readingsSingleUpdate( $hash, "volume", '0', 1 );
#        }
#        if ( $hash->{READINGS}{"volumeSteps"}{VAL} ne $helper )
#        {
#          readingsSingleUpdate( $hash, "volumeSteps", $helper, 1 );
#        }
#        if ( $hash->{READINGS}{"volumeStraight"}{VAL} ne '0' )
#        {
#          readingsSingleUpdate( $hash, "volumeStraight", '0', 1 );
#        }
        if ( $hash->{READINGS}{"mute"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "mute", $helper, 1 );
        }
        if ( $hash->{READINGS}{"shuffle"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "shuffle", $helper, 1 );
        }
        if ( $hash->{READINGS}{"repeat"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "repeat", $helper, 1 );
        }
        if ( $hash->{READINGS}{"currentTitle"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "currentTitle", $helper, 1 );
        }
        if ( $hash->{READINGS}{"infoText"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "infoText", $helper, 1 );
        }
        if ( $hash->{READINGS}{"currentAlbum"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "currentAlbum", $helper, 1 );
        }
        if ( $hash->{READINGS}{"currentArtist"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "currentArtist", $helper, 1 );
        }
        if ( $hash->{READINGS}{"graphicUri"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "graphicUri", $helper, 1 );
        }
        if ( $hash->{READINGS}{"currentPosition"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "currentPosition", $helper, 1 );
        }
        if ( $hash->{READINGS}{"currentDuration"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "currentDuration", $helper, 1 );
        }
        if ( $hash->{READINGS}{"playCaps"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "playCaps", $helper, 1 );
        }
        if ( $hash->{READINGS}{"signalStrength"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "signalStrength", $helper, 1 );
        }
#        if ( $hash->{READINGS}{"presetList_1-5"}{VAL} ne $helper )
#        {
#          readingsSingleUpdate( $hash, "presetList_1-5", $helper, 1 );
#        }
#        if ( $hash->{READINGS}{"presetList_6-0"}{VAL} ne $helper )
#        {
#          readingsSingleUpdate( $hash, "presetList_6-0", $helper, 1 );
#        }
        if ( $hash->{READINGS}{"remoteState"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "remoteState", $helper, 1 );
        }
        if ( $hash->{READINGS}{"playStatus"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "playStatus", $helper, 1 );
        }
        if ( $hash->{READINGS}{"navStatus"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "navStatus", $helper, 1 );
        }
        if ( $hash->{READINGS}{"frequency"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "frequency", $helper, 1 );
        }
        if ( $hash->{READINGS}{"input"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "input", $helper, 1 );
        }
#        if ( $hash->{READINGS}{"inputSelectable"}{VAL} ne $helper )
#        {
#          readingsSingleUpdate( $hash, "inputSelectable", $helper, 1 );
#        }
        if ( $hash->{READINGS}{"navCaps"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "navCaps", $helper, 1 );
        }
        if ( $hash->{READINGS}{"navNumItems"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "navNumItems", $helper, 1 );
        }
        if ( $hash->{READINGS}{"searchTerm"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "searchTerm", $helper, 1 );
        }
        if ( $hash->{READINGS}{"dABScan"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "dABScan", $helper, 1 );
        }
        if ( $hash->{READINGS}{"playRate"}{VAL} ne $helper )
        {
          readingsSingleUpdate( $hash, "playRate", $helper, 1 );
        }

        if ( $hash->{STATE} eq "off" )
        {
          SIRD_Time( $hash, -1 );
          SIRD_Date( $hash, -1 );
          SIRD_FriendlyName( $hash, -1 );
          SIRD_Version( $hash, -1 );
          SIRD_ID( $hash, -1 );

#          if ( $hash->{READINGS}{"presetListRequestMode"}{VAL} ne $PLR_ )
#          {
#            Log 1, "OFF ATTR PLR Test: ".$PLR_;
#            readingsSingleUpdate( $hash, "presetListRequestMode", $PLR_, 1 );
#          }
#          if ( $hash->{READINGS}{"presetListRequestMode"}{VAL} eq "2" || $hash->{READINGS}{"presetListRequestMode"}{VAL} eq "3" )
#          {
#            Log 1, "OFF PLR Test: ".$PLR_;
            SIRD_PresetList( $hash, '-1' );
#          }



#        my $PLR_ = $attr{$name}{"PresetListRequest"};
#          if ( $PLR_ eq "2" || $PLR_ eq "3" )
#          {
#            SIRD_PresetList( $hash, -1 );
#          Log 1, "PresetListRequest OFF";
#          }
#            SIRD_PresetList( $hash, -1 );
          SIRD_Volume( $hash, -1 );
        }
        else
        {
          if ( $hash->{READINGS}{"friendlyName"}{VAL} ne $helper )
          {
            readingsSingleUpdate( $hash, "friendlyName", $helper, 1 );
          }
          if ( $hash->{READINGS}{"localDate"}{VAL} ne $helper )
          {
            readingsSingleUpdate( $hash, "localDate", $helper, 1 );
          }
          if ( $hash->{READINGS}{"localTime"}{VAL} ne $helper )
          {
            readingsSingleUpdate( $hash, "localTime", $helper, 1 );
          }
          if ( $hash->{READINGS}{"radioID"}{VAL} ne $helper )
          {
            readingsSingleUpdate( $hash, "radioID", $helper, 1 );
          }
          if ( $hash->{READINGS}{"version"}{VAL} ne $helper )
          {
            readingsSingleUpdate( $hash, "version", $helper, 1 );
          }
        }
      }
      return undef;
    }
###############################
    sub SIRD_xml2txt($);
    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;
    }

###############################
    sub SIRD_space2sub ($)
    {

      # Space in Untersrich wandeln
      my ($string) = @_;
      $string =~ s/ //g;
      $string =~ s/,/./g;
      $string =~ s/(\s+$)//g;
      return $string;
    }
    
###############################
    sub SIRD_refresh($);                                                                     
    sub SIRD_refresh($)
    {
      my ($name) = @_;

#      FW_directNotify("#FHEMWEB:$name", "location.reload(true);","" );
      FW_directNotify("#FHEMWEB:$name", "location.reload();","" );
    }

##SET##########################
    sub SIRD_Set($@);
    sub SIRD_Set($@)
    {
      my ( $hash, @a ) = @_;
      my $namex   = $hash->{NAME};
#      my $name       = shift @a;
      my $preset  = "";
      my $presetList1  = "";
      my $presetList2  = "";
      my $presetListC  = '0';
      my $navList = "<<BACK<<";
      my $incer   = 0;
      my $input1 = "nix";
my $listMethode = "new";
      ##################### Presetliste ################################################
      if ( defined( $hash->{helper}->{presetAll} )) {
        $preset = $hash->{helper}->{presetAll};
        $preset = encode_utf8($preset);
      }

      if ( defined( $hash->{helper}->{preset1_5} ) && $hash->{READINGS}{"presetList_1-5"}{VAL} ne $hash->{helper}->{preset1_5} && $hash->{READINGS}{"power"}{VAL} eq "on" ) {
        my $pList = $hash->{helper}->{preset1_5};
        readingsSingleUpdate( $hash, "presetList_1-5", $pList, 1 );
        $hash->{helper}->{browserRefresh} = "true";
      }
      if ( defined( $hash->{helper}->{preset6_0} ) && $hash->{READINGS}{"presetList_6-0"}{VAL} ne $hash->{helper}->{preset6_0} && $hash->{READINGS}{"power"}{VAL} eq "on" ) {
        my $pList = $hash->{helper}->{preset6_0};
        readingsSingleUpdate( $hash, "presetList_6-0", $pList, 1 );
        $hash->{helper}->{browserRefresh} = "true";
      }
#      if ( defined( $hash->{helper}->{preset6_0} ) && $hash->{READINGS}{"presetList_6-0"}{VAL} ne $hash->{helper}->{preset6_0} && $hash->{READINGS}{"power"}{VAL} eq "on" ) {
#        my $pList = $hash->{helper}->{preset6_0};
#        $refresh = "true";
#        readingsSingleUpdate( $hash, "presetList_6-0", $pList, 1 );
#      }
#      if ( defined( $hash->{helper}->{inputRead} ) && $hash->{READINGS}{"inputSelectable"}{VAL} ne $hash->{helper}->{inputRead} && $hash->{READINGS}{"power"}{VAL} eq "on" ) {
#        my $pList = $hash->{helper}->{inputRead};
#        $refresh = "true";
#        readingsSingleUpdate( $hash, "inputSelectable", $pList, 1 );
#      }

#      if ($refresh eq "true") {
#        $refresh = "false";
#        SIRD_refresh("WEB");
#      }

#                  if ($hash->{READINGS}{"input"}{VAL} ne $helper ) {
#                    readingsSingleUpdate( $hash, "input", $helper, 1 );
#                  }
#                  if ($hash->{READINGS}{"inputSelectable"}{VAL} ne $hash->{helper}->{inputRead} ) {
#                    readingsSingleUpdate( $hash, "inputSelectable", $hash->{helper}->{inputRead}, 1 );
#                  }
########################### Presetliste  ENDE ##########################################

########################### Navliste ###################################################
      if ( defined( $hash->{helper}->{navList} )
           && ref( $hash->{helper}->{navList}->{item} ) eq "ARRAY" )
      {
        if ( ref( $hash->{helper}->{navList}->{'item'} ) eq "ARRAY" )
        {
          $incer = 0;
          for my $item ( @{ $hash->{helper}->{navList}->{'item'} } )
          {
            if ( exists $item->{'field'}[0]->{c8_array}
                 && ref( $item->{'field'}[0]->{c8_array} ) ne "HASH" )
            {

              # Im HASH: Leerzeichen entfernen und in utf umwandeln
              @{ $item->{'field'} }[0]->{c8_array} =
                SIRD_xml2txt(
                       SIRD_space2sub( @{ $item->{'field'} }[0]->{c8_array} ) );

              # $presetliste mit Kommas zusammenbauen
              if ( $navList ne "" )
              {
                $navList .= ',';
              }
              $incer = $incer + 1;
              $navList .= @{ $item->{'field'} }[0]->{c8_array};
            }
          }
          $navList .= ",>>FORWARD>>";
          $navList = encode_utf8($navList);
          $hash->{helper}->{navList}->{keyErster} =
            $hash->{helper}->{navList}->{item}[0]->{key};
          $hash->{helper}->{navList}->{keyLetzter} =
            $hash->{helper}->{navList}->{item}[ int( $incer - 1 ) ]->{key};
        }
      }
      ##################### Navliste  ENDE ##########################################  my $input1 = $hash->{helper}->{inputDropdown}

      return "no set value specified" if ( int(@a) < 2 );
      
      if ( $hash->{Model} eq "SIRD-AUTOMATIC" ) {
#        if (defined $hash->{helper}->{inputDropdown}) {
#          $input1 = $hash->{helper}->{inputDropdown};
#        }
#        if (defined $hash->{helper}->{inputAll} && $input1 ne $hash->{helper}->{inputAll}) {
        if (defined $hash->{helper}->{inputAll}) {
          $input1 = $hash->{helper}->{inputAll};
#          $hash->{helper}->{inputDropdown} = $input1;
#          $hash->{helper}->{browserRefresh} = "true";
        }
        else {
          $input1 = "InternetRadio";
        }
        my $navList1 = $navList;
        my $navList2 = $navList;
        return
        "Unknown argument $a[1], choose one of on:noArg off:noArg play:noArg pause:noArg stop:noArg channelUp:noArg channelDown:noArg "
        . "volumeStraight:slider,0,1,20 volume:slider,0,1,100 volumeUp volumeDown mute:on,off,toggle shuffle:on,off repeat:on,off input:$input1 "
        . "statusRequest:noArg remoteState:on,off clearreadings:noArg "
        . "navListRequest navActionSelItem navActionNavi navCapsRequest searchTerm navList:"
        . $navList . " "
        . "presetListRequest:noArg preset:"
        . $preset
        if ( $a[1] eq "?" );
      }

      if ( $hash->{Model} eq "sird" )
      {
        return
        "Unknown argument $a[1], choose one of on:noArg off:noArg play:noArg pause:noArg stop:noArg channelUp:noArg channelDown:noArg "
        . "volumeStraight:slider,0,1,20 volume:slider,0,1,100 volumeUp volumeDown mute:on,off,toggle shuffle:on,off repeat:on,off input:InternetRadio "
        . "statusRequest:noArg remoteState:on,off clearreadings:noArg "
        . "navListRequest navActionSelItem navActionNavi navCapsRequest searchTerm navList:"
        . $navList . " "
        . "presetListRequest:noArg preset:"
        . $preset
        if ( $a[1] eq "?" );
      }

      if ( $hash->{Model} eq "sird14" || $hash->{Model} eq "sird14a2" || $hash->{Model} eq "sird14b1" )
      {
      my $input1 = "InternetRadio,MediaPlayer,DAB-Radio,FM-Radio,AUX";
      return
        "Unknown argument $a[1], choose one of on:noArg off:noArg play:noArg pause:noArg stop:noArg channelUp:noArg channelDown:noArg "
        . "volumeStraight:slider,0,1,20 volume:slider,0,5,100 volumeUp volumeDown mute:on,off,toggle shuffle:on,off repeat:on,off input:$input1 "
        . "statusRequest:noArg remoteState:on,off clearreadings:noArg "
        . "navListRequest navActionSelItem navActionNavi navCapsRequest searchTerm navList:"
        . $navList . " "
        . "presetListRequest:noArg preset:"
        . $preset
        if ( $a[1] eq "?" );
      }

      if ( $hash->{Model} eq "sird14c2" )
      {
      my $input1 = "InternetRadio,Tidal,Deezer,Qobuz,Spotify,MediaPlayer,DAB-Radio,FM-Radio,AUX";
      return
        "Unknown argument $a[1], choose one of on:noArg off:noArg play:noArg pause:noArg stop:noArg channelUp:noArg channelDown:noArg "
        . "volumeStraight:slider,0,5,20 volume:slider,0,1,100 volumeUp volumeDown mute:on,off,toggle shuffle:on,off repeat:on,off input:$input1 "
        . "statusRequest:noArg remoteState:on,off clearreadings:noArg "
        . "navListRequest navActionSelItem navActionNavi navCapsRequest searchTerm navList:"
        . $navList . " "
        . "presetListRequest:noArg preset:"
        . $preset
        if ( $a[1] eq "?" );
      }

      if ( $hash->{Model} eq "IR110" )
      {
      return
        "Unknown argument $a[1], choose one of on:noArg off:noArg play:noArg pause:noArg stop:noArg channelUp:noArg channelDown:noArg "
        . "volume:slider,0,1,100 volumeStraight:slider,0,1,20 volumeUp volumeDown mute:on,off,toggle shuffle:on,off repeat:on,off input:InternetRadio,Spotify,MediaPlayer,DAB-Radio,FM-Radio,AUX "
        . "statusRequest:noArg remoteState:on,off clearreadings:noArg "
        . "navListRequest navActionSelItem navActionNavi navCapsRequest searchTerm navList:"
        . $navList . " "
        . "presetListRequest:noArg preset:"
        . $preset
        if ( $a[1] eq "?" );
      }

      if ( $hash->{Model} eq "MD87238" )
      {
      return
        "Unknown argument $a[1], choose one of on:noArg off:noArg play:noArg pause:noArg stop:noArg channelUp:noArg channelDown:noArg "
        . "volume:slider,0,1,100 volumeStraight:slider,0,1,20 volumeUp volumeDown mute:on,off,toggle shuffle:on,off repeat:on,off input:InternetRadio,MediaPlayer,FM-Radio,AUX "
        . "statusRequest:noArg remoteState:on,off clearreadings:noArg "
        . "navListRequest navActionSelItem navActionNavi navCapsRequest searchTerm navList:"
        . $navList . " "
        . "presetListRequest:noArg preset:"
        . $preset
        if ( $a[1] eq "?" );
      }

      if ( $hash->{Model} eq "MD87385" )
      {
      return
        "Unknown argument $a[1], choose one of on:noArg off:noArg play:noArg pause:noArg stop:noArg channelUp:noArg channelDown:noArg "
        . "volume:slider,0,1,100 volumeStraight:slider,0,1,20 volumeUp volumeDown 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 "
        . "navListRequest navActionSelItem navActionNavi navCapsRequest searchTerm navList:"
        . $navList . " "
        . "presetListRequest:noArg preset:"
        . $preset
        if ( $a[1] eq "?" );
      }

      if ( $hash->{Model} eq "TechniSatDR580" )
      {
      return
        "Unknown argument $a[1], choose one of on:noArg off:noArg play:noArg pause:noArg stop:noArg channelUp:noArg channelDown:noArg "
        . "volume:slider,0,1,100 volumeStraight:slider,0,1,20 volumeUp volumeDown mute:on,off,toggle shuffle:on,off repeat:on,off input:InternetRadio,Spotify,MediaPlayer,DAB-Radio,FM-Radio,AUX,CD,Bluetooth "
        . "statusRequest:noArg remoteState:on,off clearreadings:noArg "
        . "navListRequest navActionSelItem navActionNavi navCapsRequest searchTerm navList:"
        . $navList . " "
        . "presetListRequest:noArg preset:"
        . $preset
        if ( $a[1] eq "?" );
      }

#      if (defined $hash->{helper}->{browserRefresh} && $hash->{helper}->{browserRefresh} eq "true") {
#        $hash->{helper}->{browserRefresh} = "false";
#        SIRD_refresh("WEB");
#      }

      my $name       = shift @a;
      my $setcommand = shift @a;
      my $params     = join( ' ', @a );
      my $helper     = '0';
      my $helper1    = 0;
      my $logLevel   = GetLogLevel($name);
      Log $logLevel, "SIRD set $name $setcommand $params";
      
      $helper = SIRD_Power( $hash, -1 );

      if ( $helper eq '' || !defined( $hash->{SESSIONID} ) )
      {
        ### catch block
        SIRD_Login($hash);
      }

      if ( $setcommand eq "on" )
      {
        SIRD_Power( $hash, "on" );
        $hash->{helper}->{functionRun} = "true";
        $hash->{helper}->{FunctionCounter} = '0';
      }
      elsif ( $setcommand eq "off" )
      {
        SIRD_Power( $hash, "off" );
      }
      elsif ( $setcommand eq "input" )
      {
        SIRD_Input( $hash, $params );
        $hash->{helper}->{functionRun} = "true";
        $hash->{helper}->{FunctionCounter} = '0';
      }
      elsif ( $setcommand eq "volume" )
      {
        my $helper = int( $params / 5 );
        SIRD_Volume( $hash, $helper );
      }
      elsif ( $setcommand eq "volumeStraight" )
      {
        my $helper = int($params);
        SIRD_Volume( $hash, $helper );
      }
      elsif ( $setcommand eq "volumeUp" )
      {
        my $helper = $hash->{READINGS}{volumeStraight}{VAL};
        if ( int($helper) < 20 )
        {
          if ( $params eq '' )
          {
            if ( $attr{$name}{"volumeStep"} == '0' )
            {
              $helper = $helper + 1;
            }
            else
            {
              $helper = $helper + $attr{$name}{"volumeStep"};
            }
          }
          else
          {
            $helper = $helper + int($params);
          }
          if ( int($helper) > 20 )
          {
            $helper = 20;
          }
          elsif ( int($helper) < 0 )
          {
            $helper = 0;
          }
          SIRD_Volume( $hash, $helper );
        }
      }
      elsif ( $setcommand eq "volumeDown" )
      {
        my $helper = $hash->{READINGS}{volumeStraight}{VAL};
        if ( int($helper) > 0 )
        {
          if ( $params eq '' )
          {
            if ( $attr{$name}{"volumeStep"} == '0' )
            {
              $helper = $helper - 1;
            }
            else
            {
              $helper = $helper - $attr{$name}{"volumeStep"};
            }
          }
          else
          {
            $helper = $helper - int($params);
          }
          if ( int($helper) > 20 )
          {
            $helper = 20;
          }
          elsif ( int($helper) < 0 )
          {
            $helper = 0;
          }
          SIRD_Volume( $hash, $helper );
        }
      }
      elsif ( $setcommand eq "mute" )
      {
        if ( $params eq "on" || $params eq "off" )
        {
          SIRD_Mute( $hash, $params );
        }
        elsif ( $params eq "toggle" )
        {
          if ( ReadingsVal( $name, "mute", "0" ) eq "on" )
          {
            $helper = "off";
          }
          elsif ( ReadingsVal( $name, "mute", "0" ) eq "off" )
          {
            $helper = "on";
          }
          SIRD_Mute( $hash, $helper );
        }
        else
        {
          Log 1, "SIRD Command Mute wrong Parameter: " . $params;
          return 0;
        }
      }
      elsif ( $setcommand eq "stop" )
      {
        SIRD_PlayMode( $hash, "stop" );
      }
      elsif ( $setcommand eq "play" )
      {
        SIRD_PlayMode( $hash, "play" );
      }
      elsif ( $setcommand eq "pause" )
      {
        SIRD_PlayMode( $hash, "pause" );
      }
      elsif ( $setcommand eq "channelUp" )
      {
        SIRD_PlayMode( $hash, "next" );
      }
      elsif ( $setcommand eq "channelDown" )
      {
        SIRD_PlayMode( $hash, "previous" );
      }
      elsif ( $setcommand eq "statusRequest" )
      {
        SIRD_GetStatus( $hash, 1 );
      }
      elsif ( $setcommand eq "shuffle" )
      {
        SIRD_Shuffle( $hash, $params );
      }
      elsif ( $setcommand eq "repeat" )
      {
        SIRD_Repeat( $hash, $params );
      }
      elsif ( $setcommand eq "navActionSelItem" )
      {
        eval {
          SIRD_Com( $hash, "netRemote.nav.action.selectItem", 2, $params, 0 );
        };

        if ($@)
        {
          ### catch block
          Log 1, "SIRD navActionSelItem error: $@";
          return 0;
        }
      }
      elsif ( $setcommand eq "navActionNavi" )
      {
        eval {
          SIRD_Com( $hash, "netRemote.nav.action.navigate", 2, $params, 0 );
        };

        if ($@)
        {
          ### catch block
          Log 1, "SIRD navActionNavi error: $@";
          return 0;
        }
      }
      elsif ( $setcommand eq "remoteState" )
      {
        SIRD_RemoteState( $hash, $params );
      }
      elsif ( $setcommand eq "searchTerm" )
      {
        SIRD_SearchTerm( $hash, $params );
      }
      elsif ( $setcommand eq "friendlyNameRequest" )
      {
        SIRD_FriendlyName( $hash, -1 );
      }
      elsif ( $setcommand eq "versionRequest" )
      {
        SIRD_Version( $hash, -1 );
      }
      elsif ( $setcommand eq "infoTextRequest" )
      {
        SIRD_InfoText( $hash, -1 );
      }
      elsif ( $setcommand eq "infoNameRequest" )
      {
        SIRD_InfoName( $hash, -1 );
      }
      elsif ( $setcommand eq "frequencyRequest" )
      {
        SIRD_Frequency( $hash, -1 );
      }
      elsif ( $setcommand eq "signalStrengthRequest" )
      {
        SIRD_SignalStrength( $hash, -1 );
      }
      elsif ( $setcommand eq "navCapsRequest" )
      {
        SIRD_NavCaps( $hash, -1 );
      }
      elsif ( $setcommand eq "navListRequest" )
      {
        $helper = '20';
        $params = '0';
#my $teststr = ($attr{$name}{"navListItems"});
#Log 1,"ATTR 2: ".$teststr;
        if ( int( $attr{$name}{"navListItems"} ) != '0'
             || $attr{$name}{"navListItems"} ne '' )
        {
          $helper = $attr{$name}{"navListItems"};
        }
#Log 1,"PARAMS 2: ".$params;
#Log 1,"HELPER 2: ".$helper;
        SIRD_NavList( $hash, int($params), int($params) + int($helper) );
      }
      elsif ( $setcommand eq "navList" )
      {
        if ( $params eq "<<BACK<<" )
        {
          if ( int( $hash->{helper}->{navList}->{keyErster} ) <= 0 )
          {
            eval {
              SIRD_Com( $hash, "netRemote.nav.action.navigate", 2, "-1", 0 );
              SIRD_NavNumItems( $hash, -1 );
            };
            sleep 2;
            SIRD_NavList( $hash, -1, int($helper) );
          }
          else
          {
            SIRD_NavNumItems( $hash, -1 );
            $helper = 20;
            if ( int( $attr{$name}{"navListItems"} ) != 0
                 || $attr{$name}{"navListItems"} ne "" )
            {
              $helper = $attr{$name}{"navListItems"};

            }
            $helper1 = int( $hash->{helper}->{navList}->{keyErster} ) - $helper;
            if ( $helper1 < -1 )
            {
              $helper1 = -1;
            }
            sleep 2;
            SIRD_NavList( $hash, int($helper1), int($helper1) + int($helper) );
            if ($@)
            {
              ### catch block
              Log 1, "SIRD NavList back error: $@";
              return 0;
            }
          }
        }
        elsif ( $params eq ">>FORWARD>>" )
        {
          if (
               int( $hash->{helper}->{navList}->{keyLetzter} ) >=
               int( $hash->{READINGS}{navNumItems}{VAL} ) )
          {

            #do nothing
          }
          else
          {
            $helper = 20;
            if ( int( $attr{$name}{"navListItems"} ) != 0 )
            {
              $helper = int( $attr{$name}{"navListItems"} );
            }
            $helper1 = int( $hash->{helper}->{navList}->{keyLetzter} );
            if ( $helper1 < -1 )
            {
              $helper1 = -1;
            }
            sleep 2;
            SIRD_NavList( $hash, int($helper1), int($helper1) + int($helper) );
            if ($@)
            {
              ### catch block
              Log 1, "SIRD NavList forward error: $@";
              return 0;
            }
          }
        }
        else
        {
          if ( defined( $hash->{helper}->{navList} )
               && ref( $hash->{helper}->{navList}->{item} ) eq "ARRAY" )
          {
            if ( ref( $hash->{helper}->{navList}->{item} ) eq "ARRAY" )
            {
              for my $item ( @{ $hash->{helper}->{navList}->{'item'} } )
              {
                if ( exists $item->{'field'}[0]->{c8_array}
                     && ref( $item->{'field'}[0]->{c8_array} ) ne "HASH" )
                {
                  if ( @{ $item->{'field'} }[0]->{c8_array} eq $params )
                  {
                    if ( @{ $item->{'field'} }[1]->{u8} == 1 )
                    {
                      eval {
                        SIRD_Com( $hash, "netRemote.nav.action.selectItem",
                                  2, int( $item->{'key'} ), 0 );
                      };

                      if ($@)
                      {
                        ### catch block
                        Log 1, "SIRD navList SelItem error: $@";
                        return 0;
                      }
                    }
                    else
                    {
                      eval {
                        SIRD_Com( $hash, "netRemote.nav.action.navigate",
                                  2, int( $item->{'key'} ), 0 );
                      };

                      if ($@)
                      {
                        ### catch block
                        Log 1, "SIRD navList Navigate error: $@";
                        return 0;
                      }
                    }

                  }
                }
              }
            }
          }
          $helper = 20;
          if ( int( $attr{$name}{"navListItems"} ) != 0
               || $attr{$name}{"navListItems"} ne "" )
          {
            $helper = $attr{$name}{"navListItems"};
          }
          sleep 2;
          SIRD_NavList( $hash, -1, int($helper) );
          SIRD_NavNumItems( $hash, -1 );
        }
      }
      elsif ( $setcommand eq "dABScanRequest" )
      {
        SIRD_DABScan( $hash, -1 );
      }
      elsif ( $setcommand eq "clearreadings" )
      {
        delete $hash->{READINGS};
      }
      elsif ( $setcommand eq "presetListRequest" )
      {
        $hash->{helper}->{functionRun} = "true";
        $hash->{helper}->{FunctionCounter} = '0';
#Log 1, "functionRun: TRUE";        
        SIRD_PresetList( $hash, -1 );
      }
      elsif ( $setcommand eq "preset" && $listMethode eq "old")
      {
        if ( defined( $hash->{helper}->{preset} )
             && ref( $hash->{helper}->{preset}->{item} ) eq "ARRAY" )
        {
          if ( ref( $hash->{helper}->{preset}->{'item'} ) eq "ARRAY" )
          {
            for my $item ( @{ $hash->{helper}->{preset}->{'item'} } )
            {
              if ( exists $item->{'field'}->{c8_array}
                   && ref( $item->{'field'}->{c8_array} ) ne "HASH" )
              {
                if ( $item->{'field'}->{c8_array} eq $params )
                {
                  eval {
                    SIRD_Com( $hash, "netRemote.nav.action.selectPreset", 2, int( $item->{'key'} ), 0 );
                  };
                  if ($@)
                  {
                    ### catch block
                    Log 1, "SIRD preset error: $@";
                    return 0;
                  }
                }
              }
            }
          }
        }
      }
      elsif ( $setcommand eq "preset" && $listMethode eq "new" )
      {
        $hash->{helper}->{functionRun} = "true";
        $hash->{helper}->{FunctionCounter} = '0';
#Log 1, "functionRun: TRUE";        
        if ( defined( $hash->{helper}->{preset} )
             && ref( $hash->{helper}->{preset}->{item} ) eq "ARRAY" )
        {
          if ( ref( $hash->{helper}->{preset}->{'item'} ) eq "ARRAY" )
          {
            for my $item ( @{ $hash->{helper}->{preset}->{'item'} } )
            {
#my $presetitem = $item->{'key'};            
#Log 1, "SIRD preset item 1: ".$presetitem; #(PRESET ID)
#Log 1, "SIRD preset item 0: ".$item->{'field'}->{c8_array}; #(PRESET STATIONSNAME)
#Log 1, "SIRD preset params 0: ".$params;
              if ( exists $item->{'field'}->{c8_array}
                   && ref( $item->{'field'}->{c8_array} ) ne "HASH" )
              {
                my $item2 = $item->{'field'}->{c8_array};
                $item2 = SIRD_space2sub ($item2);
#                if ( $item->{'field'}->{c8_array} eq $params )
                if ( $item2 eq $params )
                {
#Log 1, "SIRD preset item 1: ".$item->{'field'}->{c8_array};
#Log 1, "SIRD preset item 2: ".$item->{'key'};
#Log 1, "SIRD preset params 1: ".$params;
                  eval {
                    SIRD_Com( $hash, "netRemote.nav.action.selectPreset",
                              2, int( $item->{'key'} ), 0 );
                  };
                  if ($@)
                  {
                    ### catch block
                    Log 1, "SIRD preset error: $@";
                    return 0;
                  }
                }
              }
            }
          }
        }
      }
      else
      {
        return
"unknown argument $setcommand, choose one of on off play pause stop channelUp channelDown "
          . "volume volumeStraight volumeUp VolumeDown 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;
    }
###GET#########################
    sub SIRD_Get($@);
    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" : "" );

    }

    # ###GET#########################
    # sub SIRD_Model($@)
    # {
    #     my ($hash, @a) = @_;
    #     my $what;
    # 	my $helper= "";
    #
    #     if ($hash->{Model} =="sird14"
    #     {
    #
    #     }
    #
    #   }
#        Log 1, "Hash: ".$hash;
#        Log 1, "Helper NavList: ".$helper;
#        Log 1, "Params NavList: ".$params;
#        Log 1, "Int Helper: ".int($helper);
#        Log 1, "Int Params: ".int($params);

  }
}
1;

=pod
=item summary    command radios based on Frontier Silicon chips via FSAPI
=item summary_DE Steuerung von Radios auf Basisn von Frontier Silicon Chips via FSAPI

=begin html

<a name="SIRD"></a>
<h3>SIRD</h3>
<ul>
Please see german documentation at <a href="commandref_DE.html#SIRD">SIRD</a>
</ul>

=end html

=begin html_DE

<a name="SIRD"></a>
<h3>SIRD</h3>
<ul>
  <a name="SIRDdefine"></a>
  <b>Define</b>
  <ul>
    <code>define &lt;name&gt; SIRD &lt;radio_ip_address&gt; &lt;password&gt; &lt;model&gt; [&lt;interval&gt;]</code>
    <br><br>
    Dieses Modul steuert Radios auf Basis von Frontier Silicon Chips, die über FSAPI angesprochen werden können.<br>
    Für weitere Hinweise, Beschreibungen und Updates bitte auch im Forum unter https://forum.fhem.de/index.php/topic,32030.0.html nachschauen.<br><br>
    Benötigt die Module:<br>
    <ul>
    <li><code>HttpUtils</code></li>
    <li><code>Encode</code></li>
    <li><code>XML::Simple</code></li>
    </ul>
    <br><br>
   <b>Parameter:</b><br>
   <ul>
      <li><code>&lt;radio_ip_address&gt;</code>: Die IP-Adresse des Radios.</li>
   </ul>
      <ul>
      <li><code>&lt;password&gt;</code>: Das Passwort des Internetradios, normalerweise 1234.</li>
   </ul>
   <ul>
      <li><code>&lt;mode&gt;</code>: Verschiedene Modi
      <ul>
        <li><code>sird14</code>: SILVERCREST® (Verkauf durch LIDL®) Stereo-Internetradio SIRD 14 B1 / C2 und kompatible (Alter Modus wird bald entfernt. Bitte Neuen verwenden !!!)</li>
        <li><code>sird14b1</code>: SILVERCREST® (Verkauf durch LIDL®) Stereo-Internetradio SIRD 14 B1 und kompatible</li>
        <li><code>sird14c2</code>: SILVERCREST® (Verkauf durch LIDL®) Stereo-Internetradio SIRD 14 C2 und kompatible</li>
        <li><code>IR110</code>: Hama® Stereo-Internetradio IR110 und kompatible</li>
        <li><code>MD87238</code>: Medion® (Verkauf durch ALDI®) Stereo-Internetradio MD 87238 und kompatible</li>
      </ul>
      </li>
   </ul>
   <br>
   <b>Optional</b><br>
   <ul>
      <li><code>&lt;[interval]&gt;</code>: Interval, in dem der Status des Radios abgefragt wird in Sekunden. Standard: 300 Sekunden</li> 
   </ul><br><br>
  </ul>
  <a name="SIRDset"></a>
  <b>Set</b>
  <ul>
    <li><code>channelDown</code></li>
    <li><code>channelUp</code></li>
    <li><code>channelUp</code></li>
    <li><code>clearreadings</code></li>
    <li><code>input</code></li>
    <li><code>mute</code></li>
    <li><code>navActionNavi</code></li>
    <li><code>navActionSelItem</code></li>
    <li><code>navCapsRequest</code></li>
    <li><code>navList</code></li>
    <li><code>navListRequest</code></li>
    <li><code>off</code></li>
    <li><code>on</code></li>
    <li><code>pause</code></li>
    <li><code>play</code></li>
    <li><code>preset</code></li>
    <li><code>presetListRequest</code></li>
    <li><code>remoteState</code></li>
    <li><code>repeat</code></li>
    <li><code>searchTerm</code></li>
    <li><code>shuffle</code></li>
    <li><code>statusRequest</code></li>
    <li><code>stop</code></li>
    <li><code>volume</code></li>
    <li><code>volumeDown</code></li>
    <li><code>volumeStraight</code></li>
    <li><code>volumeUp</code></li>
  </ul>
  <a name="SIRDget"></a>
  <b>Get</b>
  <ul>
    <li><code>currentAlbum</code></li>
    <li><code>currentArtist</code></li>
    <li><code>currentTitel</code></li>
    <li><code>input</code></li>
    <li><code>lastcommand</code></li>
    <li><code>mute</code></li>
    <li><code>playStatus</code></li>
    <li><code>power</code></li>
    <li><code>presence</code></li>
    <li><code>repeat</code></li>
    <li><code>shuffle</code></li>
    <li><code>state</code></li>
    <li><code>volume</code></li>
    <li><code>volumeStraight</code></li>
  </ul>
</ul>
=end html_DE
