better error handling
This commit is contained in:
parent
19ffb719ca
commit
cd719bd2db
@ -37,7 +37,7 @@ use JSON qw(decode_json);
|
||||
use Encode qw(encode_utf8);
|
||||
|
||||
|
||||
my $version = "0.1.71";
|
||||
my $version = "0.1.72";
|
||||
|
||||
|
||||
|
||||
@ -249,36 +249,37 @@ sub HEOSGroup_Set($$@) {
|
||||
return undef unless ( ReadingsVal($name, "state", "off") eq "on" );
|
||||
|
||||
if( $cmd eq 'getGroupInfo' ) {
|
||||
return "usage: getGroupInfo" if( @args != 0 );
|
||||
return "usage: $cmd" if( @args != 0 );
|
||||
|
||||
$heosCmd = $cmd;
|
||||
|
||||
} elsif( $cmd eq 'mute' ) {
|
||||
return "usage: mute on/off" if( @args != 1 );
|
||||
my $param = "on|off";
|
||||
return "usage: $cmd $param" if( @args != 1 || ! grep { $_ =~ /$args[0]/ } split(/\|/, $param) );
|
||||
|
||||
$heosCmd = 'setGroupMute';
|
||||
$action = "state=$args[0]";
|
||||
|
||||
} elsif( $cmd eq 'volume' ) {
|
||||
return "usage: volume 0-100" if( @args != 1 || $args[0] !~ /(\d+)/ || $args[0] > 100 || $args[0] < 0 );
|
||||
return "usage: $cmd 0-100" if( @args != 1 || $args[0] !~ /(\d+)/ || $args[0] > 100 || $args[0] < 0 );
|
||||
|
||||
$heosCmd = 'setGroupVolume';
|
||||
$action = "level=$args[0]";
|
||||
|
||||
} elsif( $cmd eq 'volumeUp' ) {
|
||||
return "usage: volumeUp 0-10" if( @args != 1 || $args[0] !~ /(\d+)/ || $args[0] > 10 || $args[0] < 0 );
|
||||
return "usage: $cmd 0-10" if( @args != 1 || $args[0] !~ /(\d+)/ || $args[0] > 10 || $args[0] < 1 );
|
||||
|
||||
$heosCmd = 'GroupVolumeUp';
|
||||
$action = "step=$args[0]";
|
||||
|
||||
} elsif( $cmd eq 'volumeDown' ) {
|
||||
return "usage: volumeDown 0-10" if( @args != 1 || $args[0] !~ /(\d+)/ || $args[0] > 10 || $args[0] < 0 );
|
||||
return "usage: $cmd 0-10" if( @args != 1 || $args[0] !~ /(\d+)/ || $args[0] > 10 || $args[0] < 1 );
|
||||
|
||||
$heosCmd = 'groupVolumeDown';
|
||||
$action = "step=$args[0]";
|
||||
|
||||
} elsif( $cmd eq 'clearGroup' ) {
|
||||
return "usage: clearGroup" if( @args != 0 );
|
||||
return "usage: $cmd" if( @args != 0 );
|
||||
|
||||
$heosCmd = 'createGroup';
|
||||
$string = "pid=$gid";
|
||||
|
167
21_HEOSMaster.pm
167
21_HEOSMaster.pm
@ -54,7 +54,7 @@ eval "use IO::Socket::Multicast;1" or $missingModulNet .= "IO::Socket::Multicast
|
||||
|
||||
|
||||
|
||||
my $version = "0.1.71";
|
||||
my $version = "0.1.72";
|
||||
|
||||
my %heosCmds = (
|
||||
'enableChangeEvents' => 'system/register_for_change_events?enable=',
|
||||
@ -265,6 +265,7 @@ sub HEOSMaster_Get($$@) {
|
||||
|
||||
|
||||
if( $cmd eq 'showAccount' ) {
|
||||
return "usage: $cmd" if( @args != 0 );
|
||||
|
||||
return AttrVal($name,'heosUsername',0) . ":" .HEOSMaster_ReadPassword($hash);
|
||||
}
|
||||
@ -282,49 +283,51 @@ sub HEOSMaster_Set($@) {
|
||||
|
||||
|
||||
if($cmd eq 'reopen') {
|
||||
return "usage: reopen" if( @args != 0 );
|
||||
return "usage: $cmd" if( @args != 0 );
|
||||
|
||||
HEOSMaster_ReOpen($hash);
|
||||
return undef;
|
||||
|
||||
} elsif($cmd eq 'getPlayers') {
|
||||
return "usage: getPlayers" if( @args != 0 );
|
||||
return "usage: $cmd" if( @args != 0 );
|
||||
|
||||
$heosCmd = 'getPlayers';
|
||||
$action = undef;
|
||||
|
||||
} elsif($cmd eq 'getGroups') {
|
||||
return "usage: getGroups" if( @args != 0 );
|
||||
return "usage: $cmd" if( @args != 0 );
|
||||
|
||||
$heosCmd = 'getGroups';
|
||||
$action = undef;
|
||||
|
||||
} elsif($cmd eq 'enableChangeEvents') {
|
||||
return "usage: enableChangeEvents" if( @args != 1 );
|
||||
my $param = "on|off";
|
||||
return "usage: $cmd $param" if( @args != 1 || ! grep { $_ =~ /$args[0]/ } split(/\|/, $param) );
|
||||
|
||||
$heosCmd = $cmd;
|
||||
$action = $args[0];
|
||||
|
||||
} elsif($cmd eq 'checkAccount') {
|
||||
return "usage: checkAccount" if( @args != 0 );
|
||||
return "usage: $cmd" if( @args != 0 );
|
||||
|
||||
$heosCmd = $cmd;
|
||||
$action = undef;
|
||||
|
||||
} elsif($cmd eq 'signAccount') {
|
||||
return "usage: signAccountIn" if( @args != 1 );
|
||||
my $param = "In|Out";
|
||||
return "usage: $cmd $param" if( @args != 1 || ! grep { $_ =~ /$args[0]/ } split(/\|/, $param) );
|
||||
|
||||
return "please set account informattion first" if(AttrVal($name,'heosUsername','none') eq 'none');
|
||||
$heosCmd = $cmd . $args[0];
|
||||
$action = 'un='. AttrVal($name,'heosUsername','none') . '&pw=' . HEOSMaster_ReadPassword($hash) if($args[0] eq 'In');
|
||||
|
||||
} elsif($cmd eq 'password') {
|
||||
return "usage: password" if( @args != 1 );
|
||||
return "usage: $cmd" if( @args != 1 );
|
||||
|
||||
return HEOSMaster_StorePassword( $hash, $args[0] );
|
||||
|
||||
} elsif($cmd eq 'reboot') {
|
||||
return "usage: reboot" if( @args != 0 );
|
||||
return "usage: $cmd" if( @args != 0 );
|
||||
|
||||
$heosCmd = $cmd;
|
||||
$action = undef;
|
||||
@ -1384,3 +1387,149 @@ sub HEOSMaster_MakeImage($$) {
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
||||
|
||||
|
||||
=pod
|
||||
=item device
|
||||
=item summary Modul to controls the Denon multiroom soundsystem
|
||||
=item summary_DE Modul zum steuern des Denon Multiroom-Soundsystem
|
||||
|
||||
=begin html
|
||||
|
||||
<a name="HEOSMaster"></a>
|
||||
<h3>HEOSMaster</h3>
|
||||
<ul>
|
||||
<u><b>HEOSMaster</b></u>
|
||||
<br>
|
||||
In combination with HEOSPlayer and HEOSGroup this FHEM Module controls the Denon multiroom soundsystem using a telnet socket connection and the HEOS Command Line Interface (CLI).
|
||||
<br><br>
|
||||
<b>Prerequisite</b>
|
||||
<ul>
|
||||
<li>Installation of the following packages: apt-get install libjson-perl libnet-telnet-perl libencode-perl
|
||||
</li>
|
||||
</ul>
|
||||
<br>
|
||||
<a name="HEOSMasterdefine"></a>
|
||||
<b>Define</b>
|
||||
<ul><br>
|
||||
<code>define <name> HEOSMaster <IP address></code>
|
||||
<br><br>
|
||||
Example:
|
||||
<ul><br>
|
||||
<code>define MyMasterBox HEOSMaster 192.168.178.67</code><br>
|
||||
</ul>
|
||||
<br>
|
||||
<IP address> is the IP address of Your HEOS receiver or HEOS box. The master device is created in the room HEOS, then the players of Your system are automatically recognized and created in FHEM. From now on the players can be controlled and changes in the HEOS app or at the Receiver are synchronized with the state and media readings of the players.
|
||||
<a name="HEOSMasterreadings"></a>
|
||||
<br><br>
|
||||
<b>Readings</b>
|
||||
<ul>
|
||||
<li>enableChangeEvents - state of the event reproduction at CLI master (on|off)</li>
|
||||
<li>heosAccount - signed_out | signed_in as <HEOSAccount></li>
|
||||
<li>lastCommand - last executed command</li>
|
||||
<li>lastPlayerId - player id of the device, which executed the last command</li>
|
||||
<li>lastPlayerName - player name of the device, which executed the last command</li>
|
||||
<li>lastResult - result of the last executed command</li>
|
||||
<li>state - state of the HEOSMaster</li>
|
||||
</ul>
|
||||
<br><br>
|
||||
<a name="HEOSMasterset"></a>
|
||||
<b>set</b>
|
||||
<ul>
|
||||
<li>checkAccount - checks Your HEOS account</li>
|
||||
<li>enableChangeEvents - activates the event reproduction at the CLI master</li>
|
||||
<li>getGroups - get a list of all groups and creates the devices, if not done already</li>
|
||||
<li>getPlayers - get a list of all players and creates the devices, if not yet existing</li>
|
||||
<li>password - set the password of Your HEOS account</li>
|
||||
<li>reboot - reboot of the CLI interface at HEOSMaster</li>
|
||||
<li>reopen - tries to establish a new socket connection with CLI master</li>
|
||||
<li>signAccount In|Out - sign in|out Your HEOS account (attr MyMasterBox heosUsername <username>)</li>
|
||||
</ul>
|
||||
<br><br>
|
||||
<a name="HEOSMasterget"></a>
|
||||
<b>get</b>
|
||||
<ul>
|
||||
<li>ShowAccount - shows Your HEOS account</li>
|
||||
</ul>
|
||||
<br><br>
|
||||
<a name="HEOSMasterstate"></a>
|
||||
<b>state</b>
|
||||
<ul>
|
||||
<li>connected - the HEOSmaster is connected to the CLI Master</li>
|
||||
<li>not connected - the HEOSmaster is not connected to the CLI Master</li>
|
||||
</ul>
|
||||
|
||||
=end html
|
||||
|
||||
=begin html_DE
|
||||
|
||||
<a name="HEOSMaster"></a>
|
||||
<h3>HEOSMaster</h3>
|
||||
<ul>
|
||||
<u><b>HEOSMaster</b></u>
|
||||
<br>
|
||||
In Kombination mit HEOSPlayer und HEOSGroup steuert dieses FHEM Modul das Denon Multiroom-Soundsystem mit Hilfe einer telnet Socket-Verbindung und dem HEOS Command Line Interface (CLI).
|
||||
<br><br>
|
||||
<b>Voraussetzung</b>
|
||||
<ul>
|
||||
<li>Installation der folgenden Pakete: apt-get install libjson-perl libnet-telnet-perl libencode-perl
|
||||
</li>
|
||||
</ul>
|
||||
<br>
|
||||
<a name="HEOSMasterdefine"></a>
|
||||
<b>Define</b>
|
||||
<ul><br>
|
||||
<code>define <name> HEOSMaster <IP address></code>
|
||||
<br><br>
|
||||
Example:
|
||||
<ul><br>
|
||||
<code>define MyMasterBox HEOSMaster 192.168.178.67</code><br>
|
||||
</ul>
|
||||
<br>
|
||||
<IP address> ist die IP-Adresse des HEOS Receivers oder der HEOS Box. Das Master Device wird im Raum HEOS angelegt und danach erfolgt das Einlesen und automatische Anlegen der Player.
|
||||
Von nun an können die Player gesteuert werden. Außerdem wird der Status und die Media Readings der Player entsprechend geändert, wenn man in der HEOS-App oder direkt am Receiver etwas ändert.
|
||||
|
||||
<a name="HEOSMasterreadings"></a>
|
||||
<br><br>
|
||||
<b>Readings</b>
|
||||
<ul>
|
||||
<li>enableChangeEvents - Status der Event Wiedergabe auf dem CLI Master</li>
|
||||
<li>heosAccount - signed_out | signed_in as <HEOSAccount></li>
|
||||
<li>lastCommand - zuletzt ausgeführtes Kommando</li>
|
||||
<li>lastPlayerId - Player-Id des Geräts, welches das Kommando ausgeführt hat</li>
|
||||
<li>lastPlayerName - Player-Name des Geräts, welches das Kommando ausgeführt hat</li>
|
||||
<li>lastResult - Ergebnis des zuletzt ausgeführten Kommandos</li>
|
||||
<li>state - Status des HEOSMaster</li>
|
||||
</ul>
|
||||
<br><br>
|
||||
<a name="HEOSMasterset"></a>
|
||||
<b>set</b>
|
||||
<ul>
|
||||
<li>checkAccount - prüft das HEOS Konto</li>
|
||||
<li>enableChangeEvents - aktiviert die Event Wiedergabe auf dem CLI Master</li>
|
||||
<li>getGroups - holt eine Liste aller Gruppen und legt die Devices an, sofern noch nicht geschehen</li>
|
||||
<li>getPlayers - holt eine Liste aller Player und legt die Devices an, sofern noch nicht vorhanden</li>
|
||||
<li>password - setzt das Passwort des HEOS Kontos</li>
|
||||
<li>reboot - rebootet das CLI Interface am Master</li>
|
||||
<li>reopen - versucht eine neue Socket-Verbindung zum CLI Master aufzubauen</li>
|
||||
<li>signAccount In|Out - anmelden|abmelden am HEOS Konto (attr MyMasterBox heosUsername <username>)</li>
|
||||
</ul>
|
||||
<br><br>
|
||||
<a name="HEOSMasterget"></a>
|
||||
<b>get</b>
|
||||
<ul>
|
||||
<li>ShowAccount - zeigt das HEOS Konto an</li>
|
||||
</ul>
|
||||
<br><br>
|
||||
<a name="HEOSMasterstate"></a>
|
||||
<b>state</b>
|
||||
<ul>
|
||||
<li>connected - der HEOSmaster ist mit dem CLI Master verbunden</li>
|
||||
<li>not connected - der HEOSmaster ist nicht mit dem CLI Master verbunden</li>
|
||||
</ul>
|
||||
|
||||
=end html_DE
|
||||
|
||||
=cut
|
||||
|
@ -38,7 +38,7 @@ use Encode qw(encode_utf8);
|
||||
use URI::Escape;
|
||||
use Data::Dumper;
|
||||
|
||||
my $version = "0.1.71";
|
||||
my $version = "0.1.72";
|
||||
|
||||
|
||||
|
||||
@ -396,27 +396,28 @@ sub HEOSPlayer_Set($$@) {
|
||||
return undef unless ( ReadingsVal($name, "state", "off") eq "on" );
|
||||
|
||||
if( $cmd eq 'getPlayerInfo' ) {
|
||||
return "usage: getPlayerInfo" if( @args != 0 );
|
||||
return "usage: $cmd" if( @args != 0 );
|
||||
|
||||
$heosCmd = $cmd;
|
||||
|
||||
} elsif( $cmd eq 'getPlayState' ) {
|
||||
return "usage: getPlayState" if( @args != 0 );
|
||||
return "usage: $cmd" if( @args != 0 );
|
||||
|
||||
$heosCmd = $cmd;
|
||||
|
||||
} elsif( $cmd eq 'getPlayMode' ) {
|
||||
return "usage: getPlayMode" if( @args != 0 );
|
||||
return "usage: $cmd" if( @args != 0 );
|
||||
|
||||
$heosCmd = $cmd;
|
||||
|
||||
} elsif( $cmd eq 'getNowPlayingMedia' ) {
|
||||
return "usage: getNowPlayingMedia" if( @args != 0 );
|
||||
return "usage: $cmd" if( @args != 0 );
|
||||
|
||||
$heosCmd = $cmd;
|
||||
|
||||
} elsif( $cmd eq 'repeat' ) {
|
||||
return "usage: repeat one,all,off" if( @args != 1 );
|
||||
my $param = "one|all|off";
|
||||
return "usage: $cmd $param" if( @args != 1 || ! grep { $_ =~ /$args[0]/ } split(/\|/, $param) );
|
||||
|
||||
$heosCmd = 'setPlayMode';
|
||||
$rvalue = 'on_'.$args[0];
|
||||
@ -424,7 +425,8 @@ sub HEOSPlayer_Set($$@) {
|
||||
$action = "repeat=$rvalue&shuffle=".ReadingsVal($name,'shuffle','off');
|
||||
|
||||
} elsif( $cmd eq 'shuffle' ) {
|
||||
return "usage: shuffle on,off" if( @args != 1 );
|
||||
my $param = "on|off";
|
||||
return "usage: $cmd $param" if( @args != 1 || ! grep { $_ =~ /$args[0]/ } split(/\|/, $param) );
|
||||
|
||||
$heosCmd = 'setPlayMode';
|
||||
$rvalue = 'on_'.ReadingsVal($name,'repeat','off');
|
||||
@ -432,49 +434,50 @@ sub HEOSPlayer_Set($$@) {
|
||||
$action = "repeat=$rvalue&shuffle=$args[0]";
|
||||
|
||||
} elsif( $cmd eq 'play' ) {
|
||||
return "usage: play" if( @args != 0 );
|
||||
return "usage: $cmd" if( @args != 0 );
|
||||
|
||||
$heosCmd = 'setPlayState';
|
||||
$action = "state=$cmd";
|
||||
|
||||
} elsif( $cmd eq 'stop' ) {
|
||||
return "usage: stop" if( @args != 0 );
|
||||
return "usage: $cmd" if( @args != 0 );
|
||||
|
||||
$heosCmd = 'setPlayState';
|
||||
$action = "state=$cmd";
|
||||
|
||||
} elsif( $cmd eq 'pause' ) {
|
||||
return "usage: pause" if( @args != 0 );
|
||||
return "usage: $cmd" if( @args != 0 );
|
||||
|
||||
$heosCmd = 'setPlayState';
|
||||
$action = "state=$cmd";
|
||||
|
||||
} elsif( $cmd eq 'mute' ) {
|
||||
return "usage: mute on/off" if( @args != 1 );
|
||||
my $param = "on|off";
|
||||
return "usage: $cmd $param" if( @args != 1 || ! grep { $_ =~ /$args[0]/ } split(/\|/, $param) );
|
||||
|
||||
$heosCmd = 'setMute';
|
||||
$action = "state=$args[0]";
|
||||
|
||||
} elsif( $cmd eq 'volume' ) {
|
||||
return "usage: volume 0-100" if( @args != 1 );
|
||||
return "usage: $cmd 0-100" if( @args != 1 || $args[0] !~ /(\d+)/ || $args[0] > 100 || $args[0] < 0);
|
||||
|
||||
$heosCmd = 'setVolume';
|
||||
$action = "level=$args[0]";
|
||||
|
||||
} elsif( $cmd eq 'volumeUp' ) {
|
||||
return "usage: volumeUp 0-10" if( @args != 1 );
|
||||
return "usage: $cmd 0-10" if( @args != 1 || $args[0] !~ /(\d+)/ || $args[0] > 10 || $args[0] < 1);
|
||||
|
||||
$heosCmd = $cmd;
|
||||
$action = "step=$args[0]";
|
||||
|
||||
} elsif( $cmd eq 'volumeDown' ) {
|
||||
return "usage: volumeDown 0-10" if( @args != 1 );
|
||||
return "usage: $cmd 0-10" if( @args != 1 || $args[0] !~ /(\d+)/ || $args[0] > 10 || $args[0] < 1);
|
||||
|
||||
$heosCmd = $cmd;
|
||||
$action = "step=$args[0]";
|
||||
|
||||
} elsif( $cmd eq 'groupWithMember' ) {
|
||||
return "usage: groupWithMember" if( @args != 1 );
|
||||
return "usage: $cmd" if( @args != 1 );
|
||||
|
||||
foreach ( split('\,', $args[0]) ) {
|
||||
|
||||
@ -485,17 +488,17 @@ sub HEOSPlayer_Set($$@) {
|
||||
$heosCmd = 'createGroup';
|
||||
|
||||
} elsif( $cmd eq 'groupClear' ) {
|
||||
return "usage: groupClear" if( @args != 0 );
|
||||
return "usage: $cmd" if( @args != 0 );
|
||||
|
||||
$heosCmd = 'createGroup';
|
||||
|
||||
} elsif( $cmd eq 'next' ) {
|
||||
return "usage: next" if( @args != 0 );
|
||||
return "usage: $cmd" if( @args != 0 );
|
||||
|
||||
$heosCmd = 'playNext';
|
||||
|
||||
} elsif( $cmd eq 'prev' ) {
|
||||
return "usage: prev" if( @args != 0 );
|
||||
return "usage: $cmd" if( @args != 0 );
|
||||
|
||||
$heosCmd = 'playPrev';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user