From 00d12bc7cb71560813c0becfe4819c67ea699137 Mon Sep 17 00:00:00 2001 From: tpoitzsch <> Date: Sat, 17 Jan 2015 14:52:11 +0000 Subject: [PATCH] FRITZBOX: set alarm with time and weekdays git-svn-id: https://svn.fhem.de/fhem/trunk@7598 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/72_FRITZBOX.pm | 115 ++++++++++++++++++++++++++++++++++----- 1 file changed, 100 insertions(+), 15 deletions(-) diff --git a/fhem/FHEM/72_FRITZBOX.pm b/fhem/FHEM/72_FRITZBOX.pm index bb43fe579..5534c9b55 100644 --- a/fhem/FHEM/72_FRITZBOX.pm +++ b/fhem/FHEM/72_FRITZBOX.pm @@ -267,18 +267,15 @@ sub FRITZBOX_Set($$@) . " wlan:on,off"; # . " convertMOH" # . " convertRingTone" - if ( lc $cmd eq 'alarm') - { - if ( int @val == 2 && $val[0] =~ /^(1|2|3)$/ && $val[1] =~ /^(on|off)$/ ) + +# set alarm + if ( lc $cmd eq 'alarm') { + if ( int @val > 0 && $val[0] =~ /^(1|2|3)$/ ) { Log3 $name, 3, "FRITZBOX: set $name $cmd ".join(" ", @val); - my $state = $val[1]; - $state =~ s/on/1/; - $state =~ s/off/0/; - FRITZBOX_Exec( $hash, "ctlmgr_ctl w telcfg settings/AlarmClock".( $val[0] - 1 )."/Active ".$state ); - readingsSingleUpdate($hash,"alarm".$val[0]."_state",$val[1], 1); - return undef; + return FRITZBOX_Set_Alarm ($hash, @val); } + # set call } elsif ( lc $cmd eq 'call') { if (int @val > 0) @@ -436,7 +433,81 @@ sub FRITZBOX_Get($@) return "Unknown argument $cmd, choose one of $list"; } # end FRITZBOX_Get +########################################## +sub FRITZBOX_Set_Alarm($@) +{ + my ($hash, @val) = @_; + my $name = $hash->{NAME}; + + my $alarm = $val[0]; + shift @val; + + my $para = " ".join(" ", @val); + + my $state = 1; + my $stateTxt = "on"; + if ($para =~ /off/i) + { + $state = 0; + $stateTxt = "off"; + } + + my $time; + my $timeTxt; + if ($para =~ /([0-2]?\d):([0-5]\d)/ ) + { + if ($1<10) + { + $time = 0; + $timeTxt = "0"; + } + $time .= $1.$2; + $timeTxt .= $1.":".$2; + $time = undef if $time > 2359; + } + my $day; my $dayTxt; + my %alDayValues = %alarmDays; + $alDayValues{0} = "once"; + $alDayValues{127} = "daily"; + while (my ($key, $value) = each(%alDayValues) ) + { + if ($para =~ /$value/i) + { + $day += $key ; + $dayTxt .= $value." "; + } + } + + my $result = FRITZBOX_Open_Connection( $hash ); + return "$name|Error|$result" + if $result; + + readingsBeginUpdate($hash); + + FRITZBOX_Exec( $hash, "ctlmgr_ctl w telcfg settings/AlarmClock".($alarm-1)."/Active ".$state ); + readingsBulkUpdate($hash,"alarm".$alarm."_state",$stateTxt); + + if (defined $time) + { + FRITZBOX_Exec( $hash, "ctlmgr_ctl w telcfg settings/AlarmClock".($alarm-1)."/Time ".$time ); + readingsBulkUpdate($hash,"alarm".$alarm."_time",$timeTxt); + } + + if (defined $day) + { + FRITZBOX_Exec( $hash, "ctlmgr_ctl w telcfg settings/AlarmClock".($alarm-1)."/Weekdays ".$day ); + chop $dayTxt; + readingsBulkUpdate($hash,"alarm".$alarm."_wdays",$dayTxt); + } + + readingsEndUpdate($hash, 1); + + FRITZBOX_Close_Connection( $hash ); + + return undef; +} # end FRITZBOX_Set_Alarm + ##################################### # checks and stores FritzBox password used for telnet connection sub FRITZBOX_storePassword($$) @@ -1991,6 +2062,10 @@ sub FRITZBOX_Open_Connection($) unless (defined $pwd) { + $msg = "Error: No password set. Please define it with 'set $name password YourPassword'"; + FRITZBOX_Log $hash, 2, $msg; + # return $msg; + my $pwdFile = AttrVal( $name, "pwdFile", "fb_pwd.txt"); FRITZBOX_Log $hash, 5, "Open password file '$pwdFile' to extract password"; if (open(IN, "<" . $pwdFile)) { @@ -1998,7 +2073,6 @@ sub FRITZBOX_Open_Connection($) close(IN); FRITZBOX_Log $hash, 5, "Close password file"; } else { - $msg = "Error: Cannot open password file '$pwdFile': $!"; FRITZBOX_Log $hash, 2, $msg; return $msg; } @@ -2484,9 +2558,14 @@ sub FRITZBOX_fritztris($) Set