From e2ca775f261d2d9c81e1d35fcaeb811bf33d7930 Mon Sep 17 00:00:00 2001
From: jowiemann <>
Date: Tue, 9 Apr 2024 14:31:22 +0000
Subject: [PATCH] 72_FRITZBOX.pm: Version 07.57.13
git-svn-id: https://svn.fhem.de/fhem/trunk@28778 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/FHEM/72_FRITZBOX.pm | 182 +++++++++++++++++++++++----------------
1 file changed, 108 insertions(+), 74 deletions(-)
diff --git a/fhem/FHEM/72_FRITZBOX.pm b/fhem/FHEM/72_FRITZBOX.pm
index 3933ebd42..289204536 100644
--- a/fhem/FHEM/72_FRITZBOX.pm
+++ b/fhem/FHEM/72_FRITZBOX.pm
@@ -45,7 +45,7 @@ use warnings;
use Blocking;
use HttpUtils;
-my $ModulVersion = "07.57.12c";
+my $ModulVersion = "07.57.13";
my $missingModul = "";
my $FRITZBOX_TR064pwd;
my $FRITZBOX_TR064user;
@@ -501,9 +501,6 @@ sub FRITZBOX_Initialize($)
."INTERVAL "
."reConnectInterval "
."maxSIDrenewErrCnt "
- ."m3uFileActive:0,1 "
- ."m3uFileLocal "
- ."m3uFileURL "
."userTickets "
."enablePhoneBookInfo:0,1 "
."enableKidProfiles:0,1 "
@@ -537,6 +534,7 @@ sub FRITZBOX_Initialize($)
."deviceInfo:sortable,ipv4,name,uid,connection,speed,rssi,_noDefInf_ "
."disableTableFormat:multiple-strict,border(8),cellspacing(10),cellpadding(20) "
."FhemLog3Std:0,1 "
+ ."lanDeviceReading:mac,ip "
.$readingFnAttributes;
} # end FRITZBOX_Initialize
@@ -635,6 +633,9 @@ sub FRITZBOX_Define($$)
$hash->{TR064} = -1;
$hash->{UPNP} = -1;
+ CommandDeleteAttr(undef,"$hash m3uFileLocal -silent");
+ CommandDeleteAttr(undef,"$hash m3uFileURL -silent");
+ CommandDeleteAttr(undef,"$hash m3uFileActive -silent");
FRITZBOX_Log $hash, 4, "start of Device readout parameters";
RemoveInternalTimer($hash->{helper}{TimerReadout});
@@ -828,6 +829,17 @@ sub FRITZBOX_Attr($@)
}
}
+ if ($aName eq "enablePassivLanDevices") {
+ if ($cmd eq "set") {
+ return "$aName: $aVal. Valid is 0 or 1." if $aVal !~ /[0-1]/;
+ }
+ if ($cmd eq "del" || $aVal == 0) {
+ foreach (keys %{ $hash->{READINGS} }) {
+ readingsDelete($hash, $_) if $_ =~ /^mac_pas_/ && defined $hash->{READINGS}{$_}{VAL};
+ }
+ }
+ }
+
if ($aName eq "enableKidProfiles") {
if ($cmd eq "set") {
return "$aName: $aVal. Valid is 0 or 1." if $aVal !~ /[0-1]/;
@@ -971,6 +983,19 @@ sub FRITZBOX_Attr($@)
}
}
+ if ($aName eq "lanDeviceReading") {
+ if ($cmd eq "set") {
+ return "$aName: $aVal. Valid is mac or ip." if $aVal !~ /mac|ip/;
+ foreach (keys %{ $hash->{READINGS} }) {
+ readingsDelete($hash, $_) if $_ =~ /^mac_|ip_/ && defined $hash->{READINGS}{$_}{VAL};
+ }
+ }
+ if ($cmd eq "del" || $aVal == "mac") {
+ foreach (keys %{ $hash->{READINGS} }) {
+ readingsDelete($hash, $_) if $_ =~ /^ip_/ && defined $hash->{READINGS}{$_}{VAL};
+ }
+ }
+ }
# Stop the sub if FHEM is not initialized yet
unless ($init_done) {
@@ -978,7 +1003,7 @@ sub FRITZBOX_Attr($@)
return undef;
}
- if ( ($aName =~ /m3uFileLocal|m3uFileURL|m3uFileActive/ && $hash->{APICHECKED} == 1) || $aName =~ /disable|INTERVAL|nonblockingTimeOut/ ) {
+ if ( ( $hash->{APICHECKED} == 1) || $aName =~ /disable|INTERVAL|nonblockingTimeOut/ ) {
FRITZBOX_Log $hash, 4, "Attr $cmd $aName -> Neustart internal Timer";
$hash->{APICHECKED} = 0;
$hash->{WEBCONNECT} = 0;
@@ -2777,7 +2802,11 @@ sub FRITZBOX_SetGet_Proof_Params($@) {
return "ERROR: non existing landevice: $val[0]";
}
- $val[0] = $hash->{fhem}->{landevice}->{$mac} ;
+ if ( (split(/\|/, $hash->{fhem}->{landevice}->{$val[0]}))[0] ) {
+ $val[0] = (split(/\|/, $hash->{fhem}->{landevice}->{$val[0]}))[0];
+ } else {
+ $val[0] = $hash->{fhem}->{landevice}->{$val[0]};
+ }
} else {
@@ -3436,6 +3465,7 @@ sub FRITZBOX_Readout_Run_Web($)
#-------------------------------------------------------------------------------------
# Create WLAN-List
+
my %wlanList;
#to keep compatibility with firmware <= v3.67 and >=7
if ( ref $result->{wlanList} eq 'ARRAY' ) {
@@ -3456,12 +3486,24 @@ sub FRITZBOX_Readout_Run_Web($)
#-------------------------------------------------------------------------------------
# Create LanDevice list and delete inactive devices
+
my $allowPassiv = AttrVal( $name, "enablePassivLanDevices", "0");
my %oldLanDevice;
+ my $lDevName = AttrVal( $name, "lanDeviceReading", "mac");
#collect current mac-readings (to delete the ones that are inactive or disappeared)
foreach (keys %{ $hash->{READINGS} }) {
- $oldLanDevice{$_} = $hash->{READINGS}{$_}{VAL} if $_ =~ /^mac_/ && defined $hash->{READINGS}{$_}{VAL};
+ if ($_ =~ /^${lDevName}_/ && defined $hash->{READINGS}{$_}{VAL}) {
+ my $mac_ip = $_;
+ $mac_ip =~ s/^${lDevName}_//;
+ if ($hash->{fhem}->{landevice}->{$mac_ip} && (split(/\|/, $hash->{fhem}->{landevice}->{$mac_ip}))[1]) {
+ $oldLanDevice{$_} .= (split(/\|/, $hash->{fhem}->{landevice}->{$mac_ip}))[1] . "|";
+ } else {
+ $oldLanDevice{$_} .= (split(/\|/, $hash->{fhem}->{landevice}->{$mac_ip}))[0] . "|";
+ }
+ $oldLanDevice{$_} .= $hash->{READINGS}{$_}{VAL};
+# FRITZBOX_Log $hash, 3, "deviceInfo -> $oldLanDevice{$_} -> $_";
+ }
}
%landevice = ();
@@ -3500,9 +3542,9 @@ sub FRITZBOX_Readout_Run_Web($)
FRITZBOX_Log $hash, 5, "deviceInfo -> " . $deviceInfo;
foreach ( @{ $result->{lanDevice} } ) {
- my $dIp = $_->{ip};
- my $UID = $_->{UID};
- my $dName = $_->{name};
+ my $dIp = $_->{ip}; # IP Adress
+ my $UID = $_->{UID}; # FritzBoy lan device ID
+ my $dName = $_->{name}; # name of the device
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->landevice->$dIp", $dName;
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->landevice->$UID", $dName;
@@ -3511,29 +3553,29 @@ sub FRITZBOX_Readout_Run_Web($)
my $srTmp = $deviceInfo;
- # lan IPv4 ergänzen
+ # lan IPv4 ergänzen
$srTmp =~ s/ipv4/$dIp/g;
- # lan DeviceName ergänzen
+ # lan DeviceName ergänzen
$srTmp =~ s/name/$dName/g;
- # lan DeviceID ergänzen
+ # lan DeviceID ergänzen
$srTmp =~ s/uid/$UID/g;
- # Create a reading if a landevice is connected
- # if ( ($_->{active} && $_->{ip}) || $allowPassiv) {
+ # Create a reading if a landevice is connected
if ( $_->{active} || $allowPassiv) {
my $mac = $_->{mac};
$mac =~ s/:/_/g;
+ $mac = $UID if $mac eq "";
- FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->landevice->$mac", $UID;
- $landevice{$mac}=$UID;
+ FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "fhem->landevice->$mac", $UID . "|" . $dIp;
+ $landevice{$mac} = $UID;
# if ( !$_->{ethernet} && $_->{wlan} ) { # funktioniert nicht mehr seit v7
# if ( defined $wlanList{$mac} ) {
+ # Copes with fw >= 7
if ( defined $wlanList{$mac} and !$_->{ethernet_port} and !$_->{ethernetport} ) {
- # Copes with fw>=7
$_->{guest} = $wlanList{$mac}{is_guest} if defined $wlanList{$mac}{is_guest} && $_->{guest} eq "";
$wlanCount++;
$gWlanCount++ if $_->{guest} eq "1";
@@ -3590,9 +3632,11 @@ sub FRITZBOX_Readout_Run_Web($)
$srTmp = "no match for Informations" if ($srTmp eq "");
- my $rName = "mac_";
+ $dIp = $UID if $dIp eq "";
+ $mac = $UID if $mac eq "";
+ my $rName = $lDevName . "_";
$rName .= "pas_" if $allowPassiv && $_->{active} == 0;
- $rName .= $mac;
+ $rName .= $lDevName eq "mac" ? $mac : $dIp;
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, $rName, $srTmp ;
@@ -3606,12 +3650,19 @@ sub FRITZBOX_Readout_Run_Web($)
# Remove inactive or non existing mac-readings in two steps
foreach ( keys %oldLanDevice ) {
- # set the mac readings to 'inactive' and delete at next readout
- if ( $oldLanDevice{$_} ne "inactive" ) {
- FRITZBOX_Readout_Add_Reading $hash, \@roReadings, $_, "inactive";
+ # set the lanDevice readings to 'inactive' and delete at next readout
+ if ( $oldLanDevice{$_} !~ /inactive/ ) {
+ my $ip = ": ";
+ if ($oldLanDevice{$_} =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|landevice\d+)/) {
+ $ip .= $1;
+ }
+
+ FRITZBOX_Readout_Add_Reading $hash, \@roReadings, $_, "inactive" . $ip;
+# FRITZBOX_Log $hash, 3, "deviceInfo -> $oldLanDevice{$_} -> inactive" . $ip;
}
else {
FRITZBOX_Readout_Add_Reading $hash, \@roReadings, $_, "";
+# FRITZBOX_Log $hash, 3, "deviceInfo -> $oldLanDevice{$_} -> deleted";
}
}
@@ -5318,9 +5369,6 @@ sub FRITZBOX_Readout_Process($$)
."INTERVAL "
."reConnectInterval "
."maxSIDrenewErrCnt "
- ."m3uFileLocal "
- ."m3uFileURL "
- ."m3uFileActive:0,1 "
."userTickets "
."enablePassivLanDevices:0,1 "
."enableKidProfiles:0,1 "
@@ -5355,6 +5403,7 @@ sub FRITZBOX_Readout_Process($$)
."box_docsis30_Us_powerLevels,box_docsis30_Us_frequencys,box_docsis30_Us_modulations,"
."box_docsis31_Us_powerLevels,box_docsis31_Us_frequencys,box_docsis31_Us_modulations "
."deviceInfo:sortable,ipv4,name,uid,connection,speed,rssi,_noDefInf_ "
+ ."lanDeviceReading:mac,ip "
.$readingFnAttributes;
setDevAttrList($hash->{NAME}, $cable);
@@ -9840,8 +9889,8 @@ sub FRITZBOX_Helper_process_JSON($$$@) {
# 2018.03.19 18:43:28 3: FRITZBOX: get Fritzbox luaQuery settings/sip
if ( ref ($jsonResult) ne "HASH" ) {
chop $jsonText;
- FRITZBOX_Log $hash, 4, "no json string returned\n (" . $jsonText . ")";
- my %retHash = ("Error" => "no json string returned (" . $jsonText . ")", "ResetSID" => "1");
+ FRITZBOX_Log $hash, 4, "no HASH from JSON returned\n (" . $jsonText . ")";
+ my %retHash = ("Error" => "no HASH from JSON returned", "ResetSID" => "1");
return \%retHash;
}
@@ -10917,28 +10966,11 @@ sub FRITZBOX_Helper_Url_Regex {
Defines a new prefix for the reading name of the wlan neighborhood devices that is build from the mac address. Default prefix is nbh_.
-
m3uFileActive <0 | 1>
m3uFileLocal </path/fileName>
m3uFileURL <URL>
lanDeviceReading <mac|ip>
m3uFileActive <0 | 1>
m3uFileLocal </path/fileName>
m3uFileURL <URL>
lanDeviceReading <mac|ip>