2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

76_SMAPortal: contrib 3.4.0

git-svn-id: https://svn.fhem.de/fhem/trunk@22562 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2020-08-09 07:32:15 +00:00
parent fa6514a52a
commit 04ba263bbf

View File

@ -137,8 +137,8 @@ BEGIN {
# Versions History intern
my %vNotesIntern = (
"3.4.0" => "08.08.2020 attr balanceDay, balanceMonth, balanceYear for data provider balanceDayData, balanceMonthData, balanceYearData ".
"set getData command, update button in header of PortalAsHtml",
"3.4.0" => "09.08.2020 attr balanceDay, balanceMonth, balanceYear for data provider balanceDayData, balanceMonthData, balanceYearData ".
"set getData command, update button in header of PortalAsHtml, minor code changes according PBP",
"3.3.4" => "12.07.2020 fix break in header if attribute hourCount was reduced ",
"3.3.3" => "07.07.2020 change extractLiveData, minor fixes ",
"3.3.2" => "05.07.2020 change timeout calc, new reading lastSuccessTime ",
@ -231,6 +231,12 @@ my %statkeys = ( # Statistikdaten auszulesende Schlüs
AutarkyRate => 1,
);
my %hset = ( # Hash der Set-Funktion
credentials => { fn => "_setCredentials" },
getData => { fn => "_setGetData" },
createPortalGraphic => { fn => "_setCreatePortalGraphic" },
);
my %mandatory; # Arbeitskopie von %stpl -> abzurufenden Datenprovider Stammdaten nach Login
my %subs; # Arbeitskopie von %stpl -> Festlegung abzurufenden Datenprovider
my %stpl = ( # Ausgangstemplate Subfunktionen der Datenprovider
@ -366,7 +372,7 @@ sub Set { ## no critic 'complexity'
my $opt = $a[1];
my $prop = $a[2];
my $prop1 = $a[3];
my ($setlist,$success);
my $setlist;
my $ad = "";
return if(IsDisabled($name));
@ -399,19 +405,86 @@ sub Set { ## no critic 'complexity'
}
}
if ($opt eq "credentials") {
return "Credentials are incomplete, use username password" if (!$prop || !$prop1);
($success) = setcredentials($hash,$prop,$prop1);
if ($opt && $ad && $opt =~ /$ad/x) {
# Verbraucher schalten
$hash->{HELPER}{GETTER} = "none";
$hash->{HELPER}{SETTER} = "$opt:$prop";
CallInfo($hash);
} else {
my $params = {
hash => $hash,
name => $name,
opt => $opt,
prop => $prop,
prop1 => $prop1,
aref => \@a,
};
no strict "refs"; ## no critic 'NoStrict'
if($hset{$opt}) {
my $ret = "";
$ret = &{$hset{$opt}{fn}} ($params) if(defined &{$hset{$opt}{fn}});
return $ret;
}
use strict "refs";
return "$setlist";
}
return;
}
################################################################
# Setter credentials
# credentials speichern
################################################################
sub _setCredentials { ## no critic "not used"
my $paref = shift;
my $hash = $paref->{hash};
my $name = $paref->{name};
my $prop = $paref->{prop};
my $prop1 = $paref->{prop1};
return qq{Credentials are incomplete, use "set $name credentials <username> <password>"} if (!$prop || !$prop1);
my ($success) = setcredentials($hash,$prop,$prop1);
if($success) {
delcookiefile ($hash);
CallInfo($hash);
return "Username and Password saved successfully";
} else {
return "Error while saving Username / Password - see logfile for details";
}
} elsif ($opt eq "createPortalGraphic") {
return;
}
################################################################
# Setter getData
# identisch zu "get gata", Workaround um mit webCmd
# arbeiten zu können
################################################################
sub _setGetData { ## no critic "not used"
my $paref = shift;
my $name = $paref->{name};
CommandGet(undef, "$name data");
return;
}
################################################################
# Setter createPortalGraphic
# create createPortalGraphic devices
################################################################
sub _setCreatePortalGraphic { ## no critic "not used"
my $paref = shift;
my $hash = $paref->{hash};
my $name = $paref->{name};
my $prop = $paref->{prop};
if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";}
my ($htmldev,$ret,$c,$type,$color2);
@ -445,7 +518,7 @@ sub Set { ## no critic 'complexity'
CommandAttr($hash->{CL},"$htmldev alias $c"); # Alias setzen
$c = qq{This device provides a praphical output of SMA Sunny Portal values.\n}.
qq{It is important that a SMA Home Manager is installed. Otherwise no forecast data are privided by SMA!\n}.
qq{It is important that a SMA Home Manager is installed. Otherwise no forecast data are provided by SMA!\n}.
qq{The device "$name" needs to contain "forecastData" in attribute "providerLevel".\n}.
qq{The attribute "providerLevel" must also contain "consumerCurrentdata" if you want switch your consumer connectet to the SMA Home Manager.};
@ -481,21 +554,6 @@ sub Set { ## no critic 'complexity'
CommandAttr($hash->{CL},"$htmldev room $room");
return "SMA Portal Graphics device \"$htmldev\" created and assigned to room \"$room\".";
} elsif ($opt && $ad && $opt =~ /$ad/x) {
# Verbraucher schalten
$hash->{HELPER}{GETTER} = "none";
$hash->{HELPER}{SETTER} = "$opt:$prop";
CallInfo($hash);
} elsif ($opt eq "getData") { # identisch zu "get gata", Workaround um mit webCmd arbeiten zu können
CommandGet(undef, "$name data");
} else {
return "$setlist";
}
return;
}
###############################################################
@ -3205,8 +3263,13 @@ sub PortalAsHtml {
# Header Link + Status + Update Button
if($hdrDetail eq "all" || $hdrDetail eq "statusLink") {
my ($year, $month, $day, $hour, $min, $sec) = $lup =~ /(\d+)-(\d\d)-(\d\d)\s+(.*)/x;
$lup = "$3.$2.$1 $4";
my ($year, $month, $day, $time) = $lup =~ /(\d{4})-(\d{2})-(\d{2})\s+(.*)/x;
if(AttrVal("global","language","EN") eq "DE") {
$lup = "$day.$month.$year&nbsp;$time";
} else {
$lup = "$year-$month-$day&nbsp;$time";
}
my $cmdupdate = "\"FW_cmd('$FW_ME$FW_subdir?XHR=1&cmd=set $name getData')\""; # Update Button generieren