From 38316c7504bb05de2b00dc866dcbdcaf6841783b Mon Sep 17 00:00:00 2001
From: jowiemann <>
Date: Wed, 16 Oct 2024 13:14:07 +0000
Subject: [PATCH] 72_FRITZBOX.pm: Version 08.00.02
git-svn-id: https://svn.fhem.de/fhem/trunk@29247 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/FHEM/72_FRITZBOX.pm | 147 +++++++++++++++++++++++++++++++++------
1 file changed, 126 insertions(+), 21 deletions(-)
diff --git a/fhem/FHEM/72_FRITZBOX.pm b/fhem/FHEM/72_FRITZBOX.pm
index 19477df59..edd635a07 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 = "08.00.01";
+my $ModulVersion = "08.00.02";
my $missingModul = "";
my $FRITZBOX_TR064pwd;
my $FRITZBOX_TR064user;
@@ -629,7 +629,7 @@ sub FRITZBOX_Initialize($)
."shdeviceID_model,shdeviceID_status,shdeviceID_tempOffset,shdeviceID_temperature,shdeviceID_type,"
."shdeviceID_voltage,shdeviceID_power,shdeviceID_current,shdeviceID_consumtion,shdeviceSD_ledState,shdeviceSH_state "
."enableBoxReadings:multiple-strict,"
- ."box_energyMode,box_globalFilter,box_led,box_vdsl,box_dns_Srv,box_pwr,box_guestWlan "
+ ."box_energyMode,box_globalFilter,box_led,box_vdsl,box_dns_Srv,box_pwr,box_guestWlan,box_usb "
."enableLogReadings:multiple-strict,"
."box_sys_Log,box_wlan_Log,box_fon_Log "
."disableBoxReadings:multiple-strict,"
@@ -881,12 +881,12 @@ sub FRITZBOX_Attr($@)
}
# if ($aName eq "enableReadingsFilter") {
-# my $inList = AttrVal($name, "enableReadingsFilter", "");
-# my @reading_list = split(/\,/, "box_led,box_energyMode,box_globalFilter,box_vdsl");
+# my @reading_list = qw(box_led box_energyMode box_globalFilter box_vdsl");
# if ($cmd eq "set") {
+# $aVal =~ s/\,/\|/g;
# foreach ( @reading_list ) {
-# if ( $_ !~ /$inList/ ) {
-# my $boxDel = $_;
+# my $boxDel = $_;
+# if ( $boxDel !~ /${aVal}/ ) {
# foreach (keys %{ $hash->{READINGS} }) {
# readingsDelete($hash, $_) if $_ =~ /^${boxDel}.*/ && defined $hash->{READINGS}{$_}{VAL};
# }
@@ -904,8 +904,7 @@ sub FRITZBOX_Attr($@)
# }
if ($aName eq "enableBoxReadings") {
- my $inList = AttrVal($name, "enableBoxReadings", "");
- my @reading_list = split(/\,/, "box_led,box_energyMode,box_globalFilter,box_vdsl,box_dns_Srv,box_pwr,box_guestWlan");
+ my @reading_list = qw(box_led box_energyMode box_globalFilter box_vdsl box_dns_Srv box_pwr box_guestWlan box_usb);
if ($cmd eq "set") {
if ( ("box_dns_Srv" =~ /$aVal/) && $hash->{fhem}{fwVersion} <= 731 ) {
return "box_dns_Srv not available for Fritz!OS: $hash->{fhem}{fwVersionStr}";
@@ -931,13 +930,18 @@ sub FRITZBOX_Attr($@)
if ( ("box_guestWlan" =~ /$aVal/) && $hash->{fhem}{fwVersion} < 700 ) {
return "box_guestWlan not available for Fritz!OS: $hash->{fhem}{fwVersionStr}";
}
+ if ( ("box_usb" =~ /$aVal/) && $hash->{fhem}{fwVersion} < 700 ) {
+ return "box_usb not available for Fritz!OS: $hash->{fhem}{fwVersionStr}";
+ }
+ $aVal =~ s/\,/\|/g;
foreach ( @reading_list ) {
- if ( $_ !~ /$inList/ ) {
- my $boxDel = $_;
+ my $boxDel = $_;
+ if ( $boxDel !~ /${aVal}/ ) {
foreach (keys %{ $hash->{READINGS} }) {
readingsDelete($hash, $_) if $_ =~ /^${boxDel}.*/ && defined $hash->{READINGS}{$_}{VAL};
}
+ readingsDelete($hash, "box_powerLine") if $_ =~ /box_guestWlan/ && defined $hash->{READINGS}{box_powerLine}{VAL};
}
}
}
@@ -948,16 +952,17 @@ sub FRITZBOX_Attr($@)
readingsDelete($hash, $_) if $_ =~ /^${boxDel}.*/ && defined $hash->{READINGS}{$_}{VAL};
}
}
+ readingsDelete($hash, "box_powerLine") if defined $hash->{READINGS}{box_powerLine}{VAL};
}
}
if ($aName eq "enableLogReadings") {
- my $inList = AttrVal($name, "enableLogReadings", "");
- my @reading_list = split(/\,/, "box_sys_Log,box_wlan_Log,box_fon_Log");
+ my @reading_list = qw(box_sys_Log box_wlan_Log box_fon_Log);
if ($cmd eq "set") {
+ $aVal =~ s/\,/\|/g;
foreach ( @reading_list ) {
- if ( $_ !~ /$inList/ ) {
- my $boxDel = $_;
+ my $boxDel = $_;
+ if ( $boxDel !~ /${aVal}/ ) {
foreach (keys %{ $hash->{READINGS} }) {
readingsDelete($hash, $_) if $_ =~ /^${boxDel}.*/ && defined $hash->{READINGS}{$_}{VAL};
}
@@ -965,8 +970,8 @@ sub FRITZBOX_Attr($@)
}
}
if ($cmd eq "del") {
- foreach ( @reading_list ) {
my $boxDel = $_;
+ if ( $boxDel !~ /${aVal}/ ) {
foreach (keys %{ $hash->{READINGS} }) {
readingsDelete($hash, $_) if $_ =~ /^${boxDel}.*/ && defined $hash->{READINGS}{$_}{VAL};
}
@@ -4710,7 +4715,7 @@ sub FRITZBOX_Readout_Run_Web_LuaData($$$$)
FRITZBOX_Readout_Add_Reading $hash, $roReadings, "box_guestWlan_groupAccess", $resultData->{data}->{guestAccess}->{guestGroupAccess}, "onoff";
FRITZBOX_Readout_Add_Reading $hash, $roReadings, "box_guestWlan_tmoActive", $resultData->{data}->{guestAccess}->{isTimeoutActive}, "onoff";
- FRITZBOX_Readout_Add_Reading $hash, $roReadings, "box_powerLine", $resultData->{data}->{guestAccess}->{isPowerline}, "onoff";
+ FRITZBOX_Readout_Add_Reading $hash, $roReadings, "box_powerLine", $resultData->{data}->{guestAccess}->{isPowerline} * 1, "onoff";
FRITZBOX_Log $hash, 4, "WLAN detailed info - end getting data";
} else {
@@ -4859,13 +4864,78 @@ sub FRITZBOX_Readout_Run_Web_LuaData($$$$)
# xhrId all
# xhr 1 lang de page dslOv xhrId all
+ #-------------------------------------------------------------------------------------
+ # USB Storage
+
+ # xhr 1 lang de page usbOv xhrId all
+
+ if ( ($hash->{fhem}{fwVersion} >= 700) && ($enableBoxReading =~ /box_usb/) ) {
+
+ FRITZBOX_Log $hash, 4, "USB Information - start getting data";
+
+ @webCmdArray = ();
+ push @webCmdArray, "xhr" => "1";
+ push @webCmdArray, "lang" => "de";
+ push @webCmdArray, "page" => "usbOv";
+ push @webCmdArray, "xhrId" => "all";
+
+ $resultData = FRITZBOX_read_LuaData($hash, "data", \@webCmdArray) ;
+
+ # Abbruch wenn Fehler beim Lesen der Fritzbox-Antwort
+ return FRITZBOX_Readout_Response($hash, $resultData, $roReadings) if ( defined $resultData->{Error} || defined $resultData->{AuthorizationRequired});
+
+ $$sidNew += $resultData->{sidNew} if defined $resultData->{sidNew};
+
+ $resultData->{data}->{usbOverview}->{isFTPStorageEnabled} = 0 unless $resultData->{data}->{usbOverview}->{isFTPStorageEnabled};
+ $resultData->{data}->{usbOverview}->{isFTPServerEnabled} = 0 unless $resultData->{data}->{usbOverview}->{isFTPServerEnabled};
+ $resultData->{data}->{usbOverview}->{isNASEnabled} = 0 unless $resultData->{data}->{usbOverview}->{isNASEnabled};
+ $resultData->{data}->{usbOverview}->{isSMBv1Enabled} = 0 unless $resultData->{data}->{usbOverview}->{isSMBv1Enabled};
+ $resultData->{data}->{usbOverview}->{isWebdavEnabled} = 0 unless $resultData->{data}->{usbOverview}->{isWebdavEnabled};
+ $resultData->{data}->{usbOverview}->{isAutoIndexingEnabled} = 0 unless $resultData->{data}->{usbOverview}->{isAutoIndexingEnabled};
+
+ FRITZBOX_Readout_Add_Reading $hash, $roReadings, "box_usb_FTP_activ", $resultData->{data}->{usbOverview}->{isFTPStorageEnabled} * 1, "onoff";
+ FRITZBOX_Readout_Add_Reading $hash, $roReadings, "box_usb_FTP_enabled", $resultData->{data}->{usbOverview}->{isFTPServerEnabled} * 1, "onoff";
+ FRITZBOX_Readout_Add_Reading $hash, $roReadings, "box_usb_NAS_enabled", $resultData->{data}->{usbOverview}->{isNASEnabled} * 1, "onoff";
+ FRITZBOX_Readout_Add_Reading $hash, $roReadings, "box_usb_SMB_enabled", $resultData->{data}->{usbOverview}->{isSMBv1Enabled} * 1, "onoff";
+ FRITZBOX_Readout_Add_Reading $hash, $roReadings, "box_usb_webDav", $resultData->{data}->{usbOverview}->{isWebdavEnabled} * 1, "onoff";
+ FRITZBOX_Readout_Add_Reading $hash, $roReadings, "box_usb_autoIndex", $resultData->{data}->{usbOverview}->{isAutoIndexingEnabled} * 1, "onoff";
+ FRITZBOX_Readout_Add_Reading $hash, $roReadings, "box_usb_indexStatus", $resultData->{data}->{usbOverview}->{indexingStatus};
+
+ $nbViews = 0;
+ if (defined $resultData->{data}->{usbOverview}->{devices}) {
+ $views = $resultData->{data}->{usbOverview}->{devices};
+ $nbViews = scalar @$views;
+ }
+
+ if ($nbViews > 0) {
+ my $i = 0;
+ eval {
+ for( $i = 0; $i <= $nbViews - 1; $i++) {
+
+ FRITZBOX_Readout_Add_Reading $hash, $roReadings, "box_usb_${i}_devID", $resultData->{data}->{usbOverview}->{devices}->[$i]->{id};
+ FRITZBOX_Readout_Add_Reading $hash, $roReadings, "box_usb_${i}_devType", $resultData->{data}->{usbOverview}->{devices}->[$i]->{deviceType};
+ FRITZBOX_Readout_Add_Reading $hash, $roReadings, "box_usb_${i}_devName", $resultData->{data}->{usbOverview}->{devices}->[$i]->{deviceName};
+ FRITZBOX_Readout_Add_Reading $hash, $roReadings, "box_usb_${i}_devStatus", $resultData->{data}->{usbOverview}->{devices}->[$i]->{storageStatus};
+ FRITZBOX_Readout_Add_Reading $hash, $roReadings, "box_usb_${i}_devConType", $resultData->{data}->{usbOverview}->{devices}->[$i]->{connectionType};
+ FRITZBOX_Readout_Add_Reading $hash, $roReadings, "box_usb_${i}_devEject", $resultData->{data}->{usbOverview}->{devices}->[$i]->{isEjectable} * 1, "onoff";
+ FRITZBOX_Readout_Add_Reading $hash, $roReadings, "box_usb_${i}_devStorageUsed", $resultData->{data}->{usbOverview}->{devices}->[$i]->{partitions}->[0]->{usedStorageInBytes};
+ FRITZBOX_Readout_Add_Reading $hash, $roReadings, "box_usb_${i}_devStorageTotal", $resultData->{data}->{usbOverview}->{devices}->[$i]->{partitions}->[0]->{totalStorageInBytes};
+
+ }
+ }
+
+ }
+
+ FRITZBOX_Log $hash, 4, "USB Information - end getting data";
+ } else {
+
+ FRITZBOX_Log $hash, 4, "wrong Fritz!OS for USB Information: $hash->{fhem}{fwVersionStr}" if $enableBoxReading =~ /box_usb/;
+
+ }
+
#-------------------------------------------------------------------------------------
# INET Monitor
- # xhr 1
- # lang de
- # page netMoni
- # xhrId all
# xhr 1 lang de page netMoni xhrId all
if ( ($hash->{fhem}{fwVersion} >= 731) && ($enableBoxReading =~ /box_dns_Srv/)) {
@@ -6143,7 +6213,7 @@ sub FRITZBOX_Readout_Process($$)
."shdeviceID_model,shdeviceID_status,shdeviceID_tempOffset,shdeviceID_temperature,shdeviceID_type,"
."shdeviceID_voltage,shdeviceID_power,shdeviceID_current,shdeviceID_consumtion,shdeviceID_ledState,shdeviceID_state "
."enableBoxReadings:multiple-strict,"
- ."box_energyMode,box_globalFilter,box_led,box_dns_Srv,box_pwr,box_guestWlan "
+ ."box_energyMode,box_globalFilter,box_led,box_dns_Srv,box_pwr,box_guestWlan,box_usb "
."enableLogReadings:multiple-strict,"
."box_sys_Log,box_wlan_Log,box_fon_Log "
."disableBoxReadings:multiple-strict,"
@@ -6948,6 +7018,7 @@ sub FRITZBOX_Set_check_APIs($)
$response = FRITZBOX_call_Lua_Query( $hash, $queryStr, "", "luaQuery") ;
if ( !defined $response->{sid} || defined $response->{Error} || defined $response->{AuthorizationRequired} ) {
+ FRITZBOX_Readout_Add_Reading $hash, \@roReadings, "->APICHECKED", -1;
$apiError = "luaQuery: error query string";
FRITZBOX_Log $hash, 4, "$queryStr: not Ok";
} else {
@@ -12248,6 +12319,7 @@ sub FRITZBOX_Helper_Url_Regex {
box_dns_Srv -> activates all readings box_dns_Srvn FritzOS > 7.31
box_pwr -> activates all readings box_pwr... FritzOS >= 7.00. ! not available for Cable with FritzOS 8.00
box_guestWlan -> activates all readings box_guestWlan... FritzOS >= 7.00
+ box_usb -> activates all readings box_usb... FritzOS >= 7.00