From 4c3f195a153ec7935af564574e81caab02fc0961 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Thu, 27 Feb 2020 13:57:51 +0100 Subject: [PATCH] fix rename bug --- 21_HEOSMaster.pm | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/21_HEOSMaster.pm b/21_HEOSMaster.pm index 0d560de..dadd0e3 100644 --- a/21_HEOSMaster.pm +++ b/21_HEOSMaster.pm @@ -66,7 +66,7 @@ eval "use IO::Socket::Multicast;1" or $missingModul .= "IO::Socket::Multicast "; -my $version = "0.2.0"; +my $version = "1.0.0"; my %heosCmds = ( 'enableChangeEvents' => 'system/register_for_change_events?enable=', @@ -133,8 +133,9 @@ sub HEOSMaster_GetPlayers($); sub HEOSMaster_EnableChangeEvents($); sub HEOSMaster_PreProcessingReadings($$); sub HEOSMaster_ReOpen($); -sub HEOSMaster_ReadPassword($); -sub HEOSMaster_StorePassword($$); +sub HEOSMaster_ReadPassword($$); +sub HEOSMaster_StorePassword($@); +sub HEOSMaster_Rename(@); sub HEOSMaster_GetGroups($); sub HEOSMaster_ProcessRead($$); sub HEOSMaster_ParseMsg($$); @@ -279,7 +280,7 @@ sub HEOSMaster_Get($$@) { if( $cmd eq 'showAccount' ) { return "usage: $cmd" if( @args != 0 ); - return AttrVal($name,'heosUsername',0) . ":" .HEOSMaster_ReadPassword($hash); + return AttrVal($name,'heosUsername',0) . ":" .HEOSMaster_ReadPassword($hash,$name); } my $list = 'showAccount:noArg'; @@ -331,12 +332,12 @@ sub HEOSMaster_Set($@) { 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'); + $action = 'un='. AttrVal($name,'heosUsername','none') . '&pw=' . HEOSMaster_ReadPassword($hash,$name) if($args[0] eq 'In'); } elsif($cmd eq 'password') { return "usage: $cmd" if( @args != 1 ); - return HEOSMaster_StorePassword( $hash, $args[0] ); + return HEOSMaster_StorePassword( $hash, $name, $args[0] ); } elsif($cmd eq 'reboot') { return "usage: $cmd" if( @args != 0 ); @@ -362,7 +363,7 @@ sub HEOSMaster_Open($) { my $port = 1255; my $timeout = 0.1; my $user = AttrVal($name,'heosUsername',undef); - my $password = HEOSMaster_ReadPassword($hash); + my $password = HEOSMaster_ReadPassword($hash,$name); Log3 $name, 4, "HEOSMaster ($name) - Baue Socket Verbindung auf"; @@ -1267,10 +1268,10 @@ sub HEOSMaster_CheckAccount($) { Log3 $name, 4, "HEOSMaster ($name) - checkAccount"; } -sub HEOSMaster_StorePassword($$) { +sub HEOSMaster_StorePassword($@) { - my ($hash, $password) = @_; - my $index = $hash->{TYPE}."_".$hash->{NAME}."_passwd"; + my ($hash, $name, $password) = @_; + my $index = $hash->{TYPE}."_".$name."_passwd"; my $key = getUniqueId().$index; my $enc_pwd = ""; @@ -1294,11 +1295,21 @@ sub HEOSMaster_StorePassword($$) { return "password successfully saved"; } -sub HEOSMaster_ReadPassword($) { +sub HEOSMaster_Rename(@) { + + my ( $new, $old ) = @_; + my $hash = $defs{$new}; - my ($hash) = @_; - my $name = $hash->{NAME}; - my $index = $hash->{TYPE}."_".$hash->{NAME}."_passwd"; + StorePassword( $hash, $new, ReadPassword($hash,$old) ); + setKeyValue( $hash->{TYPE} . "_" . $old . "_passwd", undef ); + + return undef; +} + +sub HEOSMaster_ReadPassword($$) { + + my ($hash, $name) = @_; + my $index = $hash->{TYPE}."_".$name."_passwd"; my $key = getUniqueId().$index; my ($password, $err);