mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 08:03:40 +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
|
# Versions History intern
|
||||||
my %vNotesIntern = (
|
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.9.0" => "01.06.2020 add get today statistic data ",
|
||||||
"2.8.1" => "31.05.2020 attribute timeout, maxCallCycle deleted ",
|
"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 ",
|
"new attribute maxCallCycle ",
|
||||||
"2.7.2" => "28.05.2020 delete cookie file if threshold of read retries reached ",
|
"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 ",
|
"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";
|
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");
|
Log3 ($name, 4, "$name - Getting Live data");
|
||||||
|
|
||||||
my $livedata = $ua->get( 'https://www.sunnyportal.com/homemanager?t='.$time ); # V2.6.2
|
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";
|
return "$name|$exceed|$newcycle|$login_state|$getp|$setp";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
### JSON Wetterdaten
|
||||||
|
#####################
|
||||||
### 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
|
|
||||||
Log3 ($name, 4, "$name - Getting weather data");
|
Log3 ($name, 4, "$name - Getting weather data");
|
||||||
|
|
||||||
my $weatherdata = $ua->get('https://www.sunnyportal.com/Dashboard/Weather');
|
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");
|
Log3 ($name, 4, "$name - Getting statistic day data");
|
||||||
|
|
||||||
my $req = HTTP::Request->new( 'POST', 'https://www.sunnyportal.com/FixedPages/HoManEnergyRedesign.aspx/GetLegendWithValues' );
|
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) {
|
if($dl > 1) {
|
||||||
Log3 ($name, 4, "$name - Getting forecast data");
|
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) {
|
if($dl > 2) {
|
||||||
Log3 ($name, 4, "$name - Getting consumer live data");
|
Log3 ($name, 4, "$name - Getting consumer live data");
|
||||||
|
|
||||||
@ -1986,10 +1986,14 @@ return 1;
|
|||||||
# analysiere abgerufene Daten
|
# analysiere abgerufene Daten
|
||||||
################################################################
|
################################################################
|
||||||
sub analyzeData { ## no critic 'complexity'
|
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 $name = $hash->{NAME};
|
||||||
my ($reread,$retry) = (0,0);
|
my ($reread,$retry) = (0,0);
|
||||||
my $data = "";
|
my $data = "";
|
||||||
|
my @da = ();
|
||||||
|
|
||||||
my $v5d = AttrVal($name, "verbose5Data", "none");
|
my $v5d = AttrVal($name, "verbose5Data", "none");
|
||||||
my $ad_content = encode("utf8", $ad->decoded_content);
|
my $ad_content = encode("utf8", $ad->decoded_content);
|
||||||
@ -1999,50 +2003,49 @@ sub analyzeData { ## no
|
|||||||
$data = eval{decode_json($ad_content)} or do { $data = $ad_content };
|
$data = eval{decode_json($ad_content)} or do { $data = $ad_content };
|
||||||
|
|
||||||
if(ref $data eq "HASH") {
|
if(ref $data eq "HASH") {
|
||||||
for my $k (keys %$data) {
|
for my $k (keys %{$data}) {
|
||||||
my $new_val = "";
|
my $val = $data->{$k};
|
||||||
|
next if(!defined $val);
|
||||||
|
|
||||||
if (defined $data->{$k}) {
|
if(ref $val eq "ARRAY") {
|
||||||
if (($data->{$k} =~ m/ARRAY/ix) || ($data->{$k} =~ m/HASH/ix)) {
|
for my $a (@{$val}) {
|
||||||
if($data->{$k} =~ m/ARRAY/ix) {
|
push @da, $a;
|
||||||
my $val = Dumper($data->{$k}[0]);
|
}
|
||||||
next if(!$val);
|
|
||||||
chomp $val;
|
|
||||||
$val =~ s/[;']//gx;
|
|
||||||
$val = ($val =~ /^undef$/x)? "none" : $val;
|
|
||||||
$new_val = $val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
if(ref $val eq "HASH") {
|
||||||
$new_val = $data->{$k};
|
for my $b (keys %{$val}) {
|
||||||
|
push @da, $b;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($new_val && $k !~ /__type/ix) {
|
$val = join " ", @da if(@da);
|
||||||
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 !!!
|
|
||||||
|
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";
|
Log3 $name, 3, "$name - Updating of the live data was interrupted. $attstr";
|
||||||
$retry = 1;
|
$retry = 1;
|
||||||
return ($reread,$retry,$login_state,$state);
|
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";
|
Log3 $name, 3, "$name - The current consumption could not be determined. The current purchased electricity is unknown. $attstr";
|
||||||
$retry = 1;
|
$retry = 1;
|
||||||
return ($reread,$retry,$login_state,$state);
|
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
|
# Energiedaten konnten nicht ermittelt werden, Daten neu lesen mit Zeitverzögerung
|
||||||
Log3 $name, 3, "$name - Communication with the Sunny Home Manager currently impossible. $attstr";
|
Log3 $name, 3, "$name - Communication with the Sunny Home Manager currently impossible. $attstr";
|
||||||
$retry = 1;
|
$retry = 1;
|
||||||
return ($reread,$retry,$login_state,$state);
|
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
|
# 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;
|
$retry = 1;
|
||||||
return ($reread,$retry,$login_state,$state);
|
return ($reread,$retry,$login_state,$state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
my $njdat = $ad->as_string;
|
my $njdat = $ad->as_string;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user