2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-19 12:46:03 +00:00

76_SMAPortal: add check login Templates, multiple choice for attr verbose5Data

git-svn-id: https://svn.fhem.de/fhem/trunk@22167 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2020-06-12 06:54:53 +00:00
parent 75cfdba2c7
commit 0d58fce7f4
3 changed files with 60 additions and 31 deletions

View File

@ -1,5 +1,7 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it. # Do not insert empty lines here, update check depends on it.
- changed: 76_SMAPortal: add check login Templates, multiple choice for attr
verbose5Data
- bugfix: 76_SMAPortal: internal code changes, bug fixes show weather_icon - bugfix: 76_SMAPortal: internal code changes, bug fixes show weather_icon
- changed: 76_SMAPortal: internal code changes, minor bug fixes - changed: 76_SMAPortal: internal code changes, minor bug fixes
- bugfix: 70_BRAVIA: fix register procedure - bugfix: 70_BRAVIA: fix register procedure

View File

@ -135,6 +135,7 @@ BEGIN {
# Versions History intern # Versions History intern
my %vNotesIntern = ( my %vNotesIntern = (
"2.10.5" => "12.06.2020 add check login by /Templates/, deeper/mulitple choice verbose5Data ",
"2.10.4" => "11.06.2020 additional L1 Readings for Battery and more ", "2.10.4" => "11.06.2020 additional L1 Readings for Battery and more ",
"2.10.3" => "11.06.2020 internal code changes, bug fixes show weather_icon ", "2.10.3" => "11.06.2020 internal code changes, bug fixes show weather_icon ",
"2.10.2" => "10.06.2020 bug fixes get/switch consumers ", "2.10.2" => "10.06.2020 bug fixes get/switch consumers ",
@ -248,7 +249,7 @@ sub Initialize {
# "providerLevel:multiple-strict,".$v5d." ". # "providerLevel:multiple-strict,".$v5d." ".
"showPassInLog:1,0 ". "showPassInLog:1,0 ".
"userAgent ". "userAgent ".
"verbose5Data:none,loginData,".$v5d." ". "verbose5Data:multiple-strict,none,loginData,".$v5d." ".
$readingFnAttributes; $readingFnAttributes;
eval { FHEM::Meta::InitMod( __FILE__, $hash ) }; ## no critic 'eval' # für Meta.pm (https://forum.fhem.de/index.php/topic,97589.0.html) eval { FHEM::Meta::InitMod( __FILE__, $hash ) }; ## no critic 'eval' # für Meta.pm (https://forum.fhem.de/index.php/topic,97589.0.html)
@ -772,6 +773,7 @@ sub GetSetData { ## no cri
my $useragent = AttrVal($name, "userAgent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)"); my $useragent = AttrVal($name, "userAgent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)");
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 $dl = AttrVal($name, "detailLevel", 1); # selected Detail Level my $dl = AttrVal($name, "detailLevel", 1); # selected Detail Level
my $state = "ok"; my $state = "ok";
my ($st,$lc) = ("",""); my ($st,$lc) = ("","");
@ -1098,16 +1100,22 @@ sub _checkLogin {
my $hash = $defs{$name}; my $hash = $defs{$name};
my $v5d = AttrVal($name, "verbose5Data", "none"); my $v5d = AttrVal($name, "verbose5Data", "none");
my $verbose = AttrVal($name, "verbose", 3);
my $loginp = $ua->post('https://www.sunnyportal.com/Templates/Start.aspx'); my $loginp = $ua->post('https://www.sunnyportal.com/Templates/Start.aspx');
my $retcode = $loginp->code; my $retcode = $loginp->code;
my $location = $loginp->header('Location') // ""; my $location = $loginp->header('Location') // "";
if($verbose == 5 && $v5d =~ /loginData/) {
$ua->add_handler( request_send => sub { shift->dump; return } ); # for debugging
$ua->add_handler( response_done => sub { shift->dump; return } );
}
if ($loginp->is_success) { if ($loginp->is_success) {
if($v5d eq "loginData") { if($v5d =~ /loginData/) {
Log3 ($name, 5, "$name - Status Login Page: ".$loginp->status_line); Log3 ($name, 5, "$name - Status Login Page: ".$loginp->status_line);
Log3 ($name, 5, "$name - Header Location: ".$location); Log3 ($name, 5, "$name - Header Location: ".$location);
Log3 ($name, 5, "$name - Login Page content: ".encode("utf8", $loginp->decoded_content)); # Log3 ($name, 5, "$name - Login Page content: ".encode("utf8", $loginp->decoded_content));
} }
$retcode = $loginp->code; $retcode = $loginp->code;
@ -1135,13 +1143,13 @@ sub _checkLogin {
$retcode = $loginp->code; $retcode = $loginp->code;
$location = $loginp->header('Location') // ""; $location = $loginp->header('Location') // "";
if($v5d eq "loginData") { if($v5d =~ /loginData/) {
Log3 ($name, 5, "$name - Status Redirect Page : ".$retcode); Log3 ($name, 5, "$name - Status Redirect Page : ".$retcode);
Log3 ($name, 5, "$name - Header Redirect Location: ".$location); Log3 ($name, 5, "$name - Header Redirect Location: ".$location);
Log3 ($name, 5, "$name - Redirect Page content: ".encode("utf8", $loginp->decoded_content)); # Log3 ($name, 5, "$name - Redirect Page content: ".encode("utf8", $loginp->decoded_content));
} }
if($location =~ /\/FixedPages\//x && $retcode eq "302") { # Weiterleitung -> Login erfolgeich(Landing Pages können im Portal eingestellt werden!) if($location =~ /\/FixedPages\/|\/Templates\//x && $retcode eq "302") { # Weiterleitung -> Login erfolgeich(Landing Pages können im Portal eingestellt werden!)
Log3 ($name, 3, "$name - Login into SMA-Portal successfully done"); Log3 ($name, 3, "$name - Login into SMA-Portal successfully done");
handleCounter ($name, "dailyIssueCookieCounter"); # Cookie Ausstellungszähler setzen handleCounter ($name, "dailyIssueCookieCounter"); # Cookie Ausstellungszähler setzen
@ -1159,7 +1167,7 @@ sub _checkLogin {
} elsif($loginp->is_redirect) { } elsif($loginp->is_redirect) {
$retcode = $loginp->code; $retcode = $loginp->code;
$location = $loginp->header('Location') // ""; $location = $loginp->header('Location') // "";
if($v5d eq "loginData") { if($v5d =~ /loginData/) {
Log3 ($name, 5, "$name - Redirect return code: ".$retcode); Log3 ($name, 5, "$name - Redirect return code: ".$retcode);
Log3 ($name, 5, "$name - Redirect Header Location: ".$location); Log3 ($name, 5, "$name - Redirect Header Location: ".$location);
} }
@ -1171,6 +1179,9 @@ sub _checkLogin {
Log3 ($name, 1, "$name - ERROR Login Page: ".$state); Log3 ($name, 1, "$name - ERROR Login Page: ".$state);
} }
$ua->remove_handler('request_send');
$ua->remove_handler('response_done');
return ($state, $errstate); return ($state, $errstate);
} }
@ -1274,21 +1285,31 @@ sub _getData {
my $call = $paref->{call}; my $call = $paref->{call};
my $tag = $paref->{tag}; my $tag = $paref->{tag};
my $v5d = AttrVal($name, "verbose5Data", "none");
my $verbose = AttrVal($name, "verbose", 3);
my $cont; my $cont;
Log3 ($name, 4, "$name - Getting $tag"); Log3 ($name, 4, "$name - Getting $tag");
my $v5d = AttrVal($name, "verbose5Data", "none"); if($verbose == 5 && $v5d =~ /$tag/) {
$ua->add_handler( request_send => sub { shift->dump; return } ); # for debugging
$ua->add_handler( response_done => sub { shift->dump; return } );
}
my $data = $ua->get( $call ); my $data = $ua->get( $call );
my $dcont = $data->content; my $dcont = $data->content;
$cont = eval{decode_json($dcont)} or do { $cont = $dcont }; $cont = eval{decode_json($dcont)} or do { $cont = $dcont };
if($v5d eq $tag) { if($v5d =~ /$tag/) {
Log3 ($name, 5, "$name - Return Code: ".$data->code); Log3 ($name, 5, "$name - Return Code: ".$data->code);
Log3 ($name, 5, "$name - $tag received:\n".Dumper $cont); Log3 ($name, 5, "$name - $tag received:\n".Dumper $cont);
} }
$ua->remove_handler('request_send');
$ua->remove_handler('response_done');
return ($data,$dcont); return ($data,$dcont);
} }
@ -1303,23 +1324,33 @@ sub _postData {
my $fields = $paref->{fields}; my $fields = $paref->{fields};
my $content = $paref->{content}; my $content = $paref->{content};
my $tag = $paref->{tag}; my $tag = $paref->{tag};
my $v5d = AttrVal($name, "verbose5Data", "none"); my $v5d = AttrVal($name, "verbose5Data", "none");
my $verbose = AttrVal($name, "verbose", 3);
my $cont; my $cont;
Log3 ($name, 4, "$name - Getting $tag"); Log3 ($name, 4, "$name - Getting $tag");
if($verbose == 5 && $v5d =~ /$tag/) {
$ua->add_handler( request_send => sub { shift->dump; return } ); # for debugging
$ua->add_handler( response_done => sub { shift->dump; return } );
}
my $data = $ua->post( $call, %$fields, Content => $content ); my $data = $ua->post( $call, %$fields, Content => $content );
my $dcont = $data->content; my $dcont = $data->content;
$cont = eval{decode_json($dcont)} or do { $cont = $dcont }; $cont = eval{decode_json($dcont)} or do { $cont = $dcont };
if($v5d eq $tag) { if($v5d =~ /$tag/) {
Log3 ($name, 5, "$name - Return Code: ".$data->code); Log3 ($name, 5, "$name - Return Code: ".$data->code);
Log3 ($name, 5, "$name - $tag received:\n".Dumper $cont); Log3 ($name, 5, "$name - $tag received:\n".Dumper $cont);
} }
$ua->remove_handler('request_send');
$ua->remove_handler('response_done');
return ($data,$dcont); return ($data,$dcont);
} }
@ -1552,7 +1583,7 @@ return ($err);
################################################################ ################################################################
## Auswertung Live Daten ## Auswertung Live Daten
################################################################ ################################################################
sub extractLiveData { sub extractLiveData { ## no critic 'complexity'
my $hash = shift; my $hash = shift;
my $daref = shift; my $daref = shift;
my $live = shift; my $live = shift;
@ -3300,8 +3331,9 @@ return;
<a name="verbose5Data"></a> <a name="verbose5Data"></a>
<li><b>verbose5Data </b><br> <li><b>verbose5Data </b><br>
If verbose 5 is set, huge data are generated. With this attribute only the interesting verbose 5 output The attribute value verbose 5 is used to generate very large amounts of data.
can be specified. (default: none). The verbose 5 outputs of interest can be selected specifically. <br>
(default: none)
</li><br> </li><br>
</ul> </ul>
@ -3495,8 +3527,9 @@ return;
<a name="verbose5Data"></a> <a name="verbose5Data"></a>
<li><b>verbose5Data </b><br> <li><b>verbose5Data </b><br>
Mit dem Attributwert verbose 5 werden zu viele Daten generiert. Mit diesem Attribut können gezielt die interessierenden Mit dem Attributwert verbose 5 werden sehr große Datenmengen generiert.
verbose 5 Ausgaben selektiert werden. (default: none). Es können gezielt die interessierenden verbose 5 Ausgaben selektiert werden. <br>
(default: none)
</li><br> </li><br>
</ul> </ul>

View File

@ -135,7 +135,7 @@ BEGIN {
# Versions History intern # Versions History intern
my %vNotesIntern = ( my %vNotesIntern = (
"2.10.5" => "11.06.2020 add check login by /Templates/, deeper verbose5Data ", "2.10.5" => "12.06.2020 add check login by /Templates/, deeper/mulitple choice verbose5Data ",
"2.10.4" => "11.06.2020 additional L1 Readings for Battery and more ", "2.10.4" => "11.06.2020 additional L1 Readings for Battery and more ",
"2.10.3" => "11.06.2020 internal code changes, bug fixes show weather_icon ", "2.10.3" => "11.06.2020 internal code changes, bug fixes show weather_icon ",
"2.10.2" => "10.06.2020 bug fixes get/switch consumers ", "2.10.2" => "10.06.2020 bug fixes get/switch consumers ",
@ -1179,10 +1179,8 @@ sub _checkLogin {
Log3 ($name, 1, "$name - ERROR Login Page: ".$state); Log3 ($name, 1, "$name - ERROR Login Page: ".$state);
} }
my $ph_rs = "request_send"; $ua->remove_handler('request_send');
my $ph_rd = "response_done"; $ua->remove_handler('response_done');
$ua->remove_handler($ph_rs);
$ua->remove_handler($ph_rd);
return ($state, $errstate); return ($state, $errstate);
} }
@ -1309,10 +1307,8 @@ sub _getData {
Log3 ($name, 5, "$name - $tag received:\n".Dumper $cont); Log3 ($name, 5, "$name - $tag received:\n".Dumper $cont);
} }
my $ph_rs = "request_send"; $ua->remove_handler('request_send');
my $ph_rd = "response_done"; $ua->remove_handler('response_done');
$ua->remove_handler($ph_rs);
$ua->remove_handler($ph_rd);
return ($data,$dcont); return ($data,$dcont);
} }
@ -1352,10 +1348,8 @@ sub _postData {
Log3 ($name, 5, "$name - $tag received:\n".Dumper $cont); Log3 ($name, 5, "$name - $tag received:\n".Dumper $cont);
} }
my $ph_rs = "request_send"; $ua->remove_handler('request_send');
my $ph_rd = "response_done"; $ua->remove_handler('response_done');
$ua->remove_handler($ph_rs);
$ua->remove_handler($ph_rd);
return ($data,$dcont); return ($data,$dcont);
} }