2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-22 20:24:36 +00:00

76_SMAPortal: contrib 3.6.4

git-svn-id: https://svn.fhem.de/fhem/trunk@23136 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2020-11-11 16:34:09 +00:00
parent 9f27ae4243
commit d98a8fcf6f

View File

@ -1,5 +1,5 @@
######################################################################################################################### #########################################################################################################################
# $Id: 76_SMAPortal.pm 23096 2020-11-04 20:29:29Z DS_Starter $ # $Id: 76_SMAPortal.pm 23105 2020-11-05 22:24:21Z DS_Starter $
######################################################################################################################### #########################################################################################################################
# 76_SMAPortal.pm # 76_SMAPortal.pm
# #
@ -137,7 +137,8 @@ BEGIN {
# Versions History intern # Versions History intern
my %vNotesIntern = ( my %vNotesIntern = (
"3.6.3" => "05.11.2020 fix not all consumer are shown in set command drop down list ", "3.6.4" => "11.11.2020 preselect the user agent randomly, set min. interval to 180 s ",
"3.6.3" => "05.11.2020 fix only four consumer are shown in set command drop down list ",
"3.6.2" => "03.11.2020 new function _detailViewOn to Switch the detail view on SMA energy balance site, new default userAgent ", "3.6.2" => "03.11.2020 new function _detailViewOn to Switch the detail view on SMA energy balance site, new default userAgent ",
"3.6.1" => "31.10.2020 adjust anchortime in getBalanceMonthData ", "3.6.1" => "31.10.2020 adjust anchortime in getBalanceMonthData ",
"3.6.0" => "11.10.2020 new relative time arguments for attr balanceDay, balanceMonth, balanceYear, new attribute useRelativeNames ", "3.6.0" => "11.10.2020 new relative time arguments for attr balanceDay, balanceMonth, balanceYear, new attribute useRelativeNames ",
@ -238,10 +239,10 @@ my %statkeys = ( # Statistikdaten auszulesende Schlüs
AutarkyRate => 1, AutarkyRate => 1,
); );
my %hset = ( # Hash der Set-Funktion my %hset = ( # Hash der Set-Funktion
credentials => { fn => \&_setCredentials }, credentials => { fn => \&_setCredentials },
getData => { fn => \&_setGetData }, getData => { fn => \&_setGetData },
createPortalGraphic => { fn => \&_setCreatePortalGraphic }, createPortalGraphic => { fn => \&_setCreatePortalGraphic },
); );
my %mandatory; # Arbeitskopie von %stpl -> abzurufenden Datenprovider Stammdaten nach Login my %mandatory; # Arbeitskopie von %stpl -> abzurufenden Datenprovider Stammdaten nach Login
@ -263,6 +264,13 @@ my %stpl = (
balanceTotalData => { doit => 0, nohm => 0, level => 'L14', func => '_getBalanceTotalData' }, balanceTotalData => { doit => 0, nohm => 0, level => 'L14', func => '_getBalanceTotalData' },
); );
my %hua = ( # mögliche UserAgents für eine Round-Robin-Liste
1 => "Mozilla/5.0 (Windows NT 10.0; rv:81.0) Gecko/20100101 Firefox/81.0",
2 => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.195 Safari/537.36",
3 => "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36",
4 => "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36 Edg/86.0.622.38",
);
# Tags der verfügbaren Datenquellen # Tags der verfügbaren Datenquellen
my @pd = qw( plantMasterData my @pd = qw( plantMasterData
consumerMasterdata consumerMasterdata
@ -280,8 +288,6 @@ my @pd = qw( plantMasterData
plantLogbook plantLogbook
); );
my $defuseragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0";
############################################################### ###############################################################
# SMAPortal Initialize # SMAPortal Initialize
############################################################### ###############################################################
@ -747,7 +753,7 @@ sub Attr {
if ($cmd eq "set") { if ($cmd eq "set") {
if ($aName eq "interval") { if ($aName eq "interval") {
unless ($aVal =~ /^\d+$/x) {return "The value for $aName is not valid. Use only figures 0-9 !";} unless ($aVal =~ /^\d+$/x) {return "The value for $aName is not valid. Use only figures 0-9 !";}
return qq{The interval must be >= 120 seconds or 0 if you don't want use automatic updates} if($aVal > 0 && $aVal < 120); return qq{The interval must be >= 180 seconds or 0 if you don't want use automatic updates} if($aVal > 0 && $aVal < 180);
InternalTimer(gettimeofday()+1.0, "FHEM::SMAPortal::CallInfo", $hash, 0); InternalTimer(gettimeofday()+1.0, "FHEM::SMAPortal::CallInfo", $hash, 0);
} }
} }
@ -890,7 +896,6 @@ sub GetSetData { ## no critic 'complexity'
my ($string) = @_; my ($string) = @_;
my ($name,$getp,$setp) = split("\\|",$string); my ($name,$getp,$setp) = split("\\|",$string);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $useragent = AttrVal($name, "userAgent", $defuseragent);
my $cookieLocation = AttrVal($name, "cookieLocation", "./log/".$name."_cookie.txt"); my $cookieLocation = AttrVal($name, "cookieLocation", "./log/".$name."_cookie.txt");
my $v5d = AttrVal($name, "verbose5Data", "none"); my $v5d = AttrVal($name, "verbose5Data", "none");
my $verbose = AttrVal($name, "verbose", 3); my $verbose = AttrVal($name, "verbose", 3);
@ -901,6 +906,12 @@ sub GetSetData { ## no critic 'complexity'
my ($errstate,$reread,$retry,$exceed,$newcycle) = (0,0,0,0,0); my ($errstate,$reread,$retry,$exceed,$newcycle) = (0,0,0,0,0);
my @ak = keys %hua; # UserAgent zufällig vorbelegen
my $randomua = $ak[rand @ak];
my $defuseragent = $hua{$randomua};
my $useragent = AttrVal($name, "userAgent", $defuseragent);
BlockingInformParent("FHEM::SMAPortal::setFromBlocking", [$name, "usedUserAgent:$useragent", "NULL" ], 1);
my %hal = ( # Header Accept-Language sprachenabhängig my %hal = ( # Header Accept-Language sprachenabhängig
"DE" => "de,en-US;q=0.7,en;q=0.3", "DE" => "de,en-US;q=0.7,en;q=0.3",
"EN" => "en-US;q=0.7,en;q=0.3" "EN" => "en-US;q=0.7,en;q=0.3"
@ -3093,13 +3104,13 @@ sub setVersionInfo {
if($modules{$type}{META}{x_prereqs_src} && !$hash->{HELPER}{MODMETAABSENT}) { if($modules{$type}{META}{x_prereqs_src} && !$hash->{HELPER}{MODMETAABSENT}) {
# META-Daten sind vorhanden # META-Daten sind vorhanden
$modules{$type}{META}{version} = "v".$v; # Version aus META.json überschreiben, Anzeige mit {Dumper $modules{SMAPortal}{META}} $modules{$type}{META}{version} = "v".$v; # Version aus META.json überschreiben, Anzeige mit {Dumper $modules{SMAPortal}{META}}
if($modules{$type}{META}{x_version}) { # {x_version} ( nur gesetzt wenn $Id: 76_SMAPortal.pm 23096 2020-11-04 20:29:29Z DS_Starter $ im Kopf komplett! vorhanden ) if($modules{$type}{META}{x_version}) { # {x_version} ( nur gesetzt wenn $Id: 76_SMAPortal.pm 23105 2020-11-05 22:24:21Z DS_Starter $ im Kopf komplett! vorhanden )
$modules{$type}{META}{x_version} =~ s/1\.1\.1/$v/gx; $modules{$type}{META}{x_version} =~ s/1\.1\.1/$v/gx;
} }
else { else {
$modules{$type}{META}{x_version} = $v; $modules{$type}{META}{x_version} = $v;
} }
return $@ unless (FHEM::Meta::SetInternals($hash)); # FVERSION wird gesetzt ( nur gesetzt wenn $Id: 76_SMAPortal.pm 23096 2020-11-04 20:29:29Z DS_Starter $ im Kopf komplett! vorhanden ) return $@ unless (FHEM::Meta::SetInternals($hash)); # FVERSION wird gesetzt ( nur gesetzt wenn $Id: 76_SMAPortal.pm 23105 2020-11-05 22:24:21Z DS_Starter $ im Kopf komplett! vorhanden )
if(__PACKAGE__ eq "FHEM::$type" || __PACKAGE__ eq $type) { if(__PACKAGE__ eq "FHEM::$type" || __PACKAGE__ eq $type) {
# es wird mit Packages gearbeitet -> Perl übliche Modulversion setzen # es wird mit Packages gearbeitet -> Perl übliche Modulversion setzen
# mit {<Modul>->VERSION()} im FHEMWEB kann Modulversion abgefragt werden # mit {<Modul>->VERSION()} im FHEMWEB kann Modulversion abgefragt werden
@ -3124,7 +3135,7 @@ sub deleteData {
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my @allrds = keys%{$defs{$name}{READINGS}}; my @allrds = keys%{$defs{$name}{READINGS}};
my $bl = "state|lastCycleTime|Counter|loginState"; # Blacklist my $bl = "state|lastCycleTime|Counter|loginState|usedUserAgent"; # Blacklist
my $pblvl = $stpl{plantLogbook}{level}; # Logbuch Level my $pblvl = $stpl{plantLogbook}{level}; # Logbuch Level
@ -4441,7 +4452,7 @@ return;
<ul> <ul>
<b>Note:</b> <b>Note:</b>
The retrieval interval should not be less than 120 seconds. As of previous experiences SMA suffers an interval of The retrieval interval must not be less than 180 seconds. As of previous experiences SMA suffers an interval of
120 seconds although the SMA terms and conditions don't permit an automatic data fetch by computer programs. 120 seconds although the SMA terms and conditions don't permit an automatic data fetch by computer programs.
</ul> </ul>
</li><br> </li><br>
@ -4772,8 +4783,8 @@ return;
<ul> <ul>
<b>Hinweis:</b> <b>Hinweis:</b>
Das Abfrageintervall sollte nicht kleiner 120 Sekunden sein. Nach bisherigen Erfahrungen toleriert SMA ein Das Abfrageintervall darf nicht kleiner 180 Sekunden sein. Nach bisherigen Erfahrungen toleriert SMA ein
Intervall von 120 Sekunden obwohl lt. SMA AGB der automatische Datenabruf untersagt ist. Intervall von 180 Sekunden obwohl lt. SMA AGB der automatische Datenabruf untersagt ist.
</ul> </ul>
</li><br> </li><br>