diff --git a/fhem/FHEM/72_FRITZBOX.pm b/fhem/FHEM/72_FRITZBOX.pm index ea89738ec..4dd269dfc 100644 --- a/fhem/FHEM/72_FRITZBOX.pm +++ b/fhem/FHEM/72_FRITZBOX.pm @@ -49,6 +49,7 @@ sub FRITZBOX_Exec($$); sub FRITZBOX_SendMail($@); sub FRITZBOX_SetMOH($@); sub FRITZBOX_StartRadio($@); +sub FRITZBOX_Wlan_Run($); our $telnet; @@ -275,6 +276,7 @@ FRITZBOX_Set($$@) my $list = "alarm" . " createPwdFile" . " customerRingTone" + . " dect:on,off" . " diversity" . " guestWlan:on,off" . " moh" @@ -332,6 +334,18 @@ FRITZBOX_Set($$@) return FRITZBOX_SetCustomerRingTone $hash, @val; } + } elsif ( lc $cmd eq 'dect') { + if (int @val == 1 && $val[0] =~ /^(on|off)$/) + { + Log3 $name, 3, "FRITZBOX: set $name $cmd ".join(" ", @val); + my $state = $val[0]; + $state =~ s/on/1/; + $state =~ s/off/0/; + FRITZBOX_Exec( $hash, "ctlmgr_ctl w dect settings/enabled $state"); + readingsSingleUpdate($hash,"box_dect",$val[0], 1); + return undef; + } + } elsif ( lc $cmd eq 'diversity') { if ( int @val == 2 && defined( $hash->{READINGS}{"diversity".$val[0]} ) && $val[1] =~ /^(on|off)$/ ) { @@ -381,8 +395,7 @@ FRITZBOX_Set($$@) { Log3 $name, 3, "FRITZBOX: set $name $cmd ".join(" ", @val); push @cmdBuffer, "ring ".join(" ", @val); - FRITZBOX_Cmd_Start $hash->{helper}{TimerCmd}; - return undef; + return FRITZBOX_Cmd_Start $hash->{helper}{TimerCmd}; } } elsif ( lc $cmd eq 'sendmail') @@ -425,15 +438,8 @@ FRITZBOX_Set($$@) if (int @val == 1 && $val[0] =~ /^(on|off)$/) { Log3 $name, 3, "FRITZBOX: set $name $cmd ".join(" ", @val); - my $state = $val[0]; - $state =~ s/on/1/; - $state =~ s/off/0/; - FRITZBOX_Exec( $hash, "ctlmgr_ctl w wlan settings/wlan_enable $state"); - - $hash->{fhem}{LOCAL}=2; #2 = short update without new trigger - FRITZBOX_Readout_Start($hash->{helper}{TimerReadout}); - $hash->{fhem}{LOCAL}=0; - return undef; + push @cmdBuffer, "wlan ".join(" ", @val); + return FRITZBOX_Cmd_Start $hash->{helper}{TimerCmd}; } } @@ -497,8 +503,8 @@ FRITZBOX_Readout_Start($) } # end FRITZBOX_Readout_Start # Starts the data capturing and sets the new timer -sub ########################################## -FRITZBOX_Readout_Run($) +########################################## +sub FRITZBOX_Readout_Run($) { my ($name) = @_; my $hash = $defs{$name}; @@ -734,9 +740,11 @@ FRITZBOX_Readout_Run($) # Gäste WLAN push @readoutArray, [ "box_guestWlan", "ctlmgr_ctl r wlan settings/guest_ap_enabled", "onoff" ]; push @readoutArray, [ "box_guestWlanRemain", "ctlmgr_ctl r wlan settings/guest_time_remain", ]; -#Music on Hold +# Dect + push @readoutArray, [ "box_dect", "ctlmgr_ctl r dect settings/enabled", "onoff" ]; +# Music on Hold push @readoutArray, [ "box_moh", "ctlmgr_ctl r telcfg settings/MOHType", "mohtype" ]; -#Power Rate +# Power Rate push @readoutArray, [ "box_powerRate", "ctlmgr_ctl r power status/rate_sumact"]; # Alarm clock @@ -768,8 +776,8 @@ FRITZBOX_Readout_Run($) } # End FRITZBOX_Readout_Run -sub ########################################## -FRITZBOX_Readout_Done($) +########################################## +sub FRITZBOX_Readout_Done($) { my ($string) = @_; unless (defined $string) @@ -777,13 +785,30 @@ FRITZBOX_Readout_Done($) Log3 "FRITZBOX_Readout_Done", 1, "Fatal Error: no parameter handed over"; return; } - + + my ($name) = split("\\|", $string); + my $hash = $defs{$name}; + +# delete the marker for RUNNING_PID process + delete($hash->{helper}{READOUT_RUNNING_PID}); + + FRITZBOX_Readout_Process $string; + +} + +########################################## +sub FRITZBOX_Readout_Process($) +{ + my ($string) = @_; + unless (defined $string) + { + Log3 "FRITZBOX_Readout_Process", 1, "Fatal Error: no parameter handed over"; + return; + } + my ($name, %values) = split("\\|", $string); my $hash = $defs{$name}; - # delete the marker for RUNNING_PID process - delete($hash->{helper}{READOUT_RUNNING_PID}); - FRITZBOX_Log $hash, 5, "Processing ". keys(%values)." readouts."; readingsBeginUpdate($hash); @@ -820,12 +845,16 @@ FRITZBOX_Readout_Done($) if ($rValue ne "") { readingsBulkUpdate( $hash, $rName, $rValue ); - FRITZBOX_Log $hash, 5, "$rName = '$rValue'"; + FRITZBOX_Log $hash, 5, "SET $rName = '$rValue'"; } elsif ( exists( $hash->{READINGS}{$rName} ) ) { delete $hash->{READINGS}{$rName}; - FRITZBOX_Log $hash, 5, "Delete '$rName'."; + FRITZBOX_Log $hash, 5, "Delete reading $rName."; + } + else + { + FRITZBOX_Log $hash, 5, "Ignore reading $rName."; } } } @@ -833,22 +862,25 @@ FRITZBOX_Readout_Done($) my $msg = keys( %values )." values captured in ".$values{readoutTime}." s"; readingsBulkUpdate( $hash, "lastReadout", $msg ); FRITZBOX_Log $hash, 4, $msg; - my $newState = "WLAN: "; - if ( $values{"box_wlan_2.4GHz"} eq "on" ) { - $newState .= "on"; - } elsif ( defined $values{box_wlan_5GHz} ) { - if ( $values{box_wlan_5GHz} eq "on") { + if ( defined $values{box_wlan_5GHz} && defined $values{"box_wlan_2.4GHz"} && defined $values{box_guestWLan} ) + { + my $newState = "WLAN: "; + if ( $values{"box_wlan_2.4GHz"} eq "on" ) { $newState .= "on"; + } elsif ( defined $values{box_wlan_5GHz} ) { + if ( $values{box_wlan_5GHz} eq "on") { + $newState .= "on"; + } else { + $newState .= "off"; + } } else { $newState .= "off"; } - } else { - $newState .= "off"; + $newState .=" gWLAN: ".$values{box_guestWlan} ; + $newState .=" (Remain: ".$values{box_guestWlanRemain}." min)" + if $values{box_guestWlan} eq "on" && $values{box_guestWlanRemain} != 0; + readingsBulkUpdate( $hash, "state", $newState); } - $newState .=" gWLAN: ".$values{box_guestWlan} ; - $newState .=" (Remain: ".$values{box_guestWlanRemain}." min)" - if $values{box_guestWlan} eq "on" && $values{box_guestWlanRemain} != 0; - readingsBulkUpdate( $hash, "state", $newState); } readingsEndUpdate( $hash, 1 ); @@ -992,6 +1024,9 @@ sub FRITZBOX_Cmd_Start($) my $func = substr $timerpara, $index + 1, length($timerpara); # function extrahieren my $name = substr $timerpara, 0, $index; # name extrahieren my $hash = $defs{$name}; + my $cmdFunction; + my $timeout; + my $handover; return unless int @cmdBuffer; @@ -1017,26 +1052,89 @@ sub FRITZBOX_Cmd_Start($) my @val = split / /, $cmdBuffer[0]; +# Preparing SET RING if ($val[0] eq "ring") { shift @val; - - my $timeout = 5; + $timeout = 5; $timeout = $val[1] if $val[1] =~/^\d+$/; $timeout += 60; $cmdBufferTimeout = time() + $timeout; - - my $handover = $name . "|" . join( "|", @val ); - $hash->{helper}{CMD_RUNNING_PID} = BlockingCall("FRITZBOX_Ring_Run", $handover, - "FRITZBOX_Cmd_Done", $timeout, - "FRITZBOX_Cmd_Aborted", $hash) - unless exists $hash->{helper}{CMD_RUNNING_PID}; + $handover = $name . "|" . join( "|", @val ); + $cmdFunction = "FRITZBOX_Ring_Run"; } +# Preparing SET WLAN + elsif ($val[0] eq "wlan") + { + shift @val; + $timeout = 10; + $cmdBufferTimeout = time() + $timeout; + $handover = $name . "|" . join( "|", @val ); + $cmdFunction = "FRITZBOX_Wlan_Run"; + } +# No valid set operation + else + { + my $msg = "Unknown command '".join( " ", @val )."'"; + FRITZBOX_Log $hash, 1, $msg; + return $msg; + } + +# Starting new command + $hash->{helper}{CMD_RUNNING_PID} = BlockingCall($cmdFunction, $handover, + "FRITZBOX_Cmd_Done", $timeout, + "FRITZBOX_Cmd_Aborted", $hash); + return undef; } # end FRITZBOX_Cmd_Start -sub ########################################## -FRITZBOX_Ring_Run($) +########################################## +sub FRITZBOX_Wlan_Run($) +{ + my ($string) = @_; + my ($name, @val) = split "\\|", $string; + my $hash = $defs{$name}; + my $result; + my @readoutArray; + my @readoutReadings; + my $startTime = time(); + + my $state = $val[0]; + $state =~ s/on/1/; + $state =~ s/off/0/; + + $result = FRITZBOX_Open_Connection( $hash ); + return "$name|0|$result" + if $result; + + my $returnStr = "$name|2|"; + +# Set WLAN + push @readoutArray, [ "", "ctlmgr_ctl w wlan settings/wlan_enable $state"]; +# Read WLAN + push @readoutArray, [ "box_wlan_2.4GHz", "ctlmgr_ctl r wlan settings/ap_enabled", "onoff" ]; +# Read 2nd WLAN + push @readoutArray, [ "box_wlan_5GHz", "ctlmgr_ctl r wlan settings/ap_enabled_scnd", "onoff" ]; +# Read Gäste WLAN + push @readoutArray, [ "box_guestWlan", "ctlmgr_ctl r wlan settings/guest_ap_enabled", "onoff" ]; + push @readoutArray, [ "box_guestWlanRemain", "ctlmgr_ctl r wlan settings/guest_time_remain", ]; + +# Execute commands + FRITZBOX_Readout_Query( $hash, \@readoutArray, \@readoutReadings); + + $returnStr .= join('|', @readoutReadings ); + $returnStr .= "|readoutTime|"; + $returnStr .= sprintf "%.2f", time()-$startTime; + + FRITZBOX_Close_Connection ( $hash ); + + FRITZBOX_Log $hash, 5, "Handover: ".$returnStr; + return $returnStr + +} # end FRITZBOX_Wlan_Run + +########################################## +sub FRITZBOX_Ring_Run($) { my ($string) = @_; my ($name, @val) = split "\\|", $string; @@ -1230,20 +1328,24 @@ FRITZBOX_Cmd_Done($) my ($string) = @_; return unless defined $string; - my ($name, $success, $result) = split("\\|", $string); + my ($name, $success, $result) = split("\\|", $string,3); my $hash = $defs{$name}; shift (@cmdBuffer); delete($hash->{helper}{CMD_RUNNING_PID}); - if ($success != 1) + if ( $success !~ /1|2/ ) { FRITZBOX_Log $hash, 1, $result; } - else + elsif ( $success == 1 ) { FRITZBOX_Log $hash, 4, $result; } + elsif ($success == 2 ) + { + FRITZBOX_Readout_Process ( $name."|".$result ); + } } ########################################## @@ -1891,8 +1993,37 @@ sub FRITZBOX_fritztris($) return $returnStr; } + ##################################### + #
set <name> convertRingTone <fullFilePath>
+ # set <name> convertMusicOnHold <fullFilePath>
+ # set <name> convertRingTone <fullFilePath>
+ # set <name> convertMusicOnHold <fullFilePath>
+ # set <name> convertRingTone <fullFilePath>
- set <name> convertMusicOnHold <fullFilePath>
- set <name> createPwdFile <password>
set <name> dect <on|off>
+ set <name> diversity <number> <on|off>
set <name> ring <internalNumbers> [duration [ringTone]] [show:Text] [say:Text]
+ set <name> ring <intNumbers> [duration [ringTone]] [show:Text] [say:Text]
telnetTimeOut <seconds>
@@ -2116,6 +2238,7 @@ sub FRITZBOX_fritztris($)
set <name> convertRingTone <fullFilePath>
- set <name> convertMusicOnHold <fullFilePath>
- set <name> createPwdFile <password>
set <name> dect <on|off>
+ set <name> diversity <number> <on|off>
set <name> ring <interneNummern> [Dauer [Klingelton]] [show:Nachricht]
- Beispiel: set fritzbox ring 611,612 5 Budapest show:Es regnet
+ set <name> ring <intNummern> [Dauer [Klingelton]] [show:Text] [say:Text]
+ Beispiel:
+ set fritzbox ring 611,612 5 Budapest show:Es regnet
+ set fritzbox ring 610 say:Es regnet
set <name> sendMail [to:<Address>] [subject:<Subject>] [body:<Text>]
@@ -2368,6 +2487,7 @@ sub FRITZBOX_fritztris($)