mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-03 07:35:22 +00:00
76_SMAPortal: contrib 2.10.0
git-svn-id: https://svn.fhem.de/fhem/trunk@22106 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
f689c66827
commit
f13bd6d865
@ -134,10 +134,10 @@ BEGIN {
|
||||
|
||||
# Versions History intern
|
||||
my %vNotesIntern = (
|
||||
"2.10.0" => "03.06.2020 refactoring login process ",
|
||||
"2.10.0" => "03.06.2020 refactored login process ",
|
||||
"2.9.0" => "01.06.2020 add get today statistic data ",
|
||||
"2.8.1" => "31.05.2020 attribute timeout, maxCallCycle deleted ",
|
||||
"2.8.0" => "31.05.2020 refactoring process logic, attribute cookielifetime & getDataRetries deleted, command delCookieFile deleted ".
|
||||
"2.8.0" => "31.05.2020 refactored process logic, attribute cookielifetime & getDataRetries deleted, command delCookieFile deleted ".
|
||||
"new attribute maxCallCycle ",
|
||||
"2.7.2" => "28.05.2020 delete cookie file if threshold of read retries reached ",
|
||||
"2.7.1" => "28.05.2020 change cookie default location to ./log/<name>_cookie.txt ",
|
||||
@ -882,10 +882,44 @@ sub GetSetData { ## no cri
|
||||
return "$name|0|0|$login_state|$getp|$setp|$st";
|
||||
}
|
||||
|
||||
### Verbraucher schalten
|
||||
#######################################
|
||||
if($setp ne "none") {
|
||||
my ($serial,$id);
|
||||
for my $key (keys %{$hash->{HELPER}{CONSUMER}}) {
|
||||
my $h = $hash->{HELPER}{CONSUMER}{$key}{DeviceName};
|
||||
if($h && $h eq $d) {
|
||||
$serial = $hash->{HELPER}{CONSUMER}{$key}{SerialNumber};
|
||||
$id = $hash->{HELPER}{CONSUMER}{$key}{SUSyID};
|
||||
}
|
||||
}
|
||||
my $plantOid = $hash->{HELPER}{PLANTOID};
|
||||
my $res = $ua->post('https://www.sunnyportal.com/Homan/ConsumerBalance/SetOperatingMode', {
|
||||
'mode' => $op,
|
||||
'serialNumber' => $serial,
|
||||
'SUSyID' => $id,
|
||||
'plantOid' => $plantOid
|
||||
}
|
||||
);
|
||||
|
||||
$res = $res->decoded_content();
|
||||
Log3 ($name, 3, "$name - Set \"$d $op\" result: ".$res);
|
||||
if($res eq "true") {
|
||||
$state = "ok - switched consumer $d to $op";
|
||||
BlockingInformParent("FHEM::SMAPortal::setFromBlocking", [$name, "all", "none", "NULL", "NULL", "NULL"], 0);
|
||||
} else {
|
||||
$state = "Error - couldn't switch consumer $d to $op";
|
||||
}
|
||||
}
|
||||
|
||||
### Live-Daten abrufen
|
||||
#########################
|
||||
### Daten abrufen
|
||||
#############################
|
||||
if($getp ne "none") {
|
||||
|
||||
my $dl = AttrVal($name, "detailLevel", 1); # selcted Detail Level
|
||||
|
||||
### JSON Live-Daten
|
||||
####################
|
||||
Log3 ($name, 4, "$name - Getting Live data");
|
||||
|
||||
my $livedata = $ua->get( 'https://www.sunnyportal.com/homemanager?t='.$time ); # V2.6.2
|
||||
@ -928,45 +962,8 @@ sub GetSetData { ## no cri
|
||||
return "$name|$exceed|$newcycle|$login_state|$getp|$setp";
|
||||
}
|
||||
|
||||
|
||||
|
||||
### Verbraucher schalten
|
||||
#######################################
|
||||
if($setp ne "none") {
|
||||
my ($serial,$id);
|
||||
for my $key (keys %{$hash->{HELPER}{CONSUMER}}) {
|
||||
my $h = $hash->{HELPER}{CONSUMER}{$key}{DeviceName};
|
||||
if($h && $h eq $d) {
|
||||
$serial = $hash->{HELPER}{CONSUMER}{$key}{SerialNumber};
|
||||
$id = $hash->{HELPER}{CONSUMER}{$key}{SUSyID};
|
||||
}
|
||||
}
|
||||
my $plantOid = $hash->{HELPER}{PLANTOID};
|
||||
my $res = $ua->post('https://www.sunnyportal.com/Homan/ConsumerBalance/SetOperatingMode', {
|
||||
'mode' => $op,
|
||||
'serialNumber' => $serial,
|
||||
'SUSyID' => $id,
|
||||
'plantOid' => $plantOid
|
||||
}
|
||||
);
|
||||
|
||||
$res = $res->decoded_content();
|
||||
Log3 ($name, 3, "$name - Set \"$d $op\" result: ".$res);
|
||||
if($res eq "true") {
|
||||
$state = "ok - switched consumer $d to $op";
|
||||
BlockingInformParent("FHEM::SMAPortal::setFromBlocking", [$name, "all", "none", "NULL", "NULL", "NULL"], 0);
|
||||
} else {
|
||||
$state = "Error - couldn't switch consumer $d to $op";
|
||||
}
|
||||
}
|
||||
|
||||
### Daten abrufen
|
||||
#########################
|
||||
if($getp ne "none") {
|
||||
|
||||
my $dl = AttrVal($name, "detailLevel", 1); # selcted Detail Level
|
||||
|
||||
# JSON Wetterdaten
|
||||
### JSON Wetterdaten
|
||||
#####################
|
||||
Log3 ($name, 4, "$name - Getting weather data");
|
||||
|
||||
my $weatherdata = $ua->get('https://www.sunnyportal.com/Dashboard/Weather');
|
||||
@ -978,7 +975,8 @@ sub GetSetData { ## no cri
|
||||
}
|
||||
|
||||
|
||||
# JSON Statistic Data Tag (anchorTime beachten !)
|
||||
### JSON Statistic Data Tag (anchorTime beachten !)
|
||||
####################################################
|
||||
Log3 ($name, 4, "$name - Getting statistic day data");
|
||||
|
||||
my $req = HTTP::Request->new( 'POST', 'https://www.sunnyportal.com/FixedPages/HoManEnergyRedesign.aspx/GetLegendWithValues' );
|
||||
@ -1000,7 +998,8 @@ sub GetSetData { ## no cri
|
||||
}
|
||||
|
||||
|
||||
# JSON Forecast Daten
|
||||
### JSON Forecast Daten
|
||||
########################
|
||||
if($dl > 1) {
|
||||
Log3 ($name, 4, "$name - Getting forecast data");
|
||||
|
||||
@ -1013,7 +1012,8 @@ sub GetSetData { ## no cri
|
||||
}
|
||||
}
|
||||
|
||||
# JSON Consumer Livedaten und historische Energiedaten
|
||||
### JSON Consumer Livedaten und historische Energiedaten
|
||||
#########################################################
|
||||
if($dl > 2) {
|
||||
Log3 ($name, 4, "$name - Getting consumer live data");
|
||||
|
||||
@ -1986,10 +1986,14 @@ return 1;
|
||||
# analysiere abgerufene Daten
|
||||
################################################################
|
||||
sub analyzeData { ## no critic 'complexity'
|
||||
my ($hash,$login_state,$state,$ad) = @_;
|
||||
my $hash = shift;
|
||||
my $login_state = shift;
|
||||
my $state = shift;
|
||||
my $ad = shift;
|
||||
my $name = $hash->{NAME};
|
||||
my ($reread,$retry) = (0,0);
|
||||
my $data = "";
|
||||
my @da = ();
|
||||
|
||||
my $v5d = AttrVal($name, "verbose5Data", "none");
|
||||
my $ad_content = encode("utf8", $ad->decoded_content);
|
||||
@ -1998,51 +2002,50 @@ sub analyzeData { ## no
|
||||
|
||||
$data = eval{decode_json($ad_content)} or do { $data = $ad_content };
|
||||
|
||||
if (ref $data eq "HASH") {
|
||||
for my $k (keys %$data) {
|
||||
my $new_val = "";
|
||||
if(ref $data eq "HASH") {
|
||||
for my $k (keys %{$data}) {
|
||||
my $val = $data->{$k};
|
||||
next if(!defined $val);
|
||||
|
||||
if (defined $data->{$k}) {
|
||||
if (($data->{$k} =~ m/ARRAY/ix) || ($data->{$k} =~ m/HASH/ix)) {
|
||||
if($data->{$k} =~ m/ARRAY/ix) {
|
||||
my $val = Dumper($data->{$k}[0]);
|
||||
next if(!$val);
|
||||
chomp $val;
|
||||
$val =~ s/[;']//gx;
|
||||
$val = ($val =~ /^undef$/x)? "none" : $val;
|
||||
$new_val = $val;
|
||||
if(ref $val eq "ARRAY") {
|
||||
for my $a (@{$val}) {
|
||||
push @da, $a;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$new_val = $data->{$k};
|
||||
if(ref $val eq "HASH") {
|
||||
for my $b (keys %{$val}) {
|
||||
push @da, $b;
|
||||
}
|
||||
}
|
||||
|
||||
if ($new_val && $k !~ /__type/ix) {
|
||||
if($k =~ m/WarningMessages/x && $new_val =~ /Updating of the live data was interrupted/) { ## no critic 'regular expression' # Regular expression without "/x" flag nicht anwenden !!!
|
||||
$val = join " ", @da if(@da);
|
||||
|
||||
if ($val && $k !~ /__type/ix) {
|
||||
if($k =~ m/WarningMessages/x && $val =~ /Updating of the live data was interrupted/) { ## no critic 'regular expression' # Regular expression without "/x" flag nicht anwenden !!!
|
||||
Log3 $name, 3, "$name - Updating of the live data was interrupted. $attstr";
|
||||
$retry = 1;
|
||||
return ($reread,$retry,$login_state,$state);
|
||||
}
|
||||
if($k =~ m/WarningMessages/x && $new_val =~ /The current consumption could not be determined. The current purchased electricity is unknown/) { ## no critic 'regular expression' # Regular expression without "/x" flag nicht anwenden !!!
|
||||
if($k =~ m/WarningMessages/x && $val =~ /The current consumption could not be determined. The current purchased electricity is unknown/) { ## no critic 'regular expression' # Regular expression without "/x" flag nicht anwenden !!!
|
||||
Log3 $name, 3, "$name - The current consumption could not be determined. The current purchased electricity is unknown. $attstr";
|
||||
$retry = 1;
|
||||
return ($reread,$retry,$login_state,$state);
|
||||
}
|
||||
if($k =~ m/ErrorMessages/x && $new_val =~ /Communication with the Sunny Home Manager is currently not possible/) { ## no critic 'regular expression' # Regular expression without "/x" flag nicht anwenden !!!
|
||||
if($k =~ m/ErrorMessages/x && $val =~ /Communication with the Sunny Home Manager is currently not possible/) { ## no critic 'regular expression' # Regular expression without "/x" flag nicht anwenden !!!
|
||||
# Energiedaten konnten nicht ermittelt werden, Daten neu lesen mit Zeitverzögerung
|
||||
Log3 $name, 3, "$name - Communication with the Sunny Home Manager currently impossible. $attstr";
|
||||
$retry = 1;
|
||||
return ($reread,$retry,$login_state,$state);
|
||||
}
|
||||
if($k =~ m/ErrorMessages/x && $new_val =~ /The current data cannot be retrieved from the PV system. Check the cabling and configuration of the following energy meters/) { ## no critic 'regular expression' # Regular expression without "/x" flag nicht anwenden !!!
|
||||
if($k =~ m/ErrorMessages/x && $val =~ /The current data cannot be retrieved from the PV system. Check the cabling and configuration of the following energy meters/) { ## no critic 'regular expression' # Regular expression without "/x" flag nicht anwenden !!!
|
||||
# Energiedaten konnten nicht ermittelt werden, Daten neu lesen mit Zeitverzögerung
|
||||
Log3 $name, 3, "$name - Live data can't be retrieved. $attstr";
|
||||
Log3 $name, 3, "$name - The current data cannot be retrieved from the PV system. $attstr";
|
||||
$retry = 1;
|
||||
return ($reread,$retry,$login_state,$state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
my $njdat = $ad->as_string;
|
||||
@ -2132,8 +2135,8 @@ sub PortalAsHtml {
|
||||
|
||||
# Kontext des aufrufenden SMAPortalSPG-Devices speichern für Refresh
|
||||
$hash->{HELPER}{SPGDEV} = $wlname; # Name des aufrufenden SMAPortalSPG-Devices
|
||||
$hash->{HELPER}{SPGROOM} = $FW_room?$FW_room:""; # Raum aus dem das SMAPortalSPG-Device die Funktion aufrief
|
||||
$hash->{HELPER}{SPGDETAIL} = $FW_detail?$FW_detail:""; # Name des SMAPortalSPG-Devices (wenn Detailansicht)
|
||||
$hash->{HELPER}{SPGROOM} = $FW_room ? $FW_room : ""; # Raum aus dem das SMAPortalSPG-Device die Funktion aufrief
|
||||
$hash->{HELPER}{SPGDETAIL} = $FW_detail ? $FW_detail : ""; # Name des SMAPortalSPG-Devices (wenn Detailansicht)
|
||||
|
||||
my $dl = AttrVal ($name, "detailLevel", 1);
|
||||
my $pv0 = ReadingsNum($name, "L2_ThisHour_PvMeanPower", undef);
|
||||
|
Loading…
x
Reference in New Issue
Block a user