Events added for EGPM, bugfixes4HttpUtils, german doku added

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@4345 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
alexus2033 2013-12-08 14:16:44 +00:00
parent c3133ebec9
commit bd494b6240
2 changed files with 203 additions and 26 deletions

View File

@ -1,5 +1,5 @@
############################################## ##############################################
# $Id: EGPM2LAN.pm 2891 2013-07-15 19:12:50Z alexus $ # $Id: EGPM2LAN.pm 2013-12-08 10:11:20Z alexus $
# #
# based / modified Version 98_EGPMS2LAN from ericl # based / modified Version 98_EGPMS2LAN from ericl
# #
@ -33,11 +33,40 @@ EGPM2LAN_Initialize($)
{ {
my ($hash) = @_; my ($hash) = @_;
$hash->{Clients} = ":EGPM:"; $hash->{Clients} = ":EGPM:";
$hash->{GetFn} = "EGPM2LAN_Get";
$hash->{SetFn} = "EGPM2LAN_Set"; $hash->{SetFn} = "EGPM2LAN_Set";
$hash->{DefFn} = "EGPM2LAN_Define"; $hash->{DefFn} = "EGPM2LAN_Define";
$hash->{AttrList} = "loglevel:0,1,2,3,4,5,6 stateDisplay:sockNumber,sockName autocreate:on,off"; $hash->{AttrList} = "loglevel:0,1,2,3,4,5,6 stateDisplay:sockNumber,sockName autocreate:on,off";
} }
###################################
sub
EGPM2LAN_Get($@)
{
my ($hash, @a) = @_;
my $what;
return "argument is missing" if(int(@a) != 2);
$what = $a[1];
if($what =~ /^(state|lastcommand)$/)
{
if(defined($hash->{READINGS}{$what}))
{
return $hash->{READINGS}{$what}{VAL};
}
else
{
return "reading not found: $what";
}
}
else
{
return "Unknown argument $what, choose one of state:noArg lastcommand:noArg".(exists($hash->{READINGS}{output})?" output:noArg":"");
}
}
################################### ###################################
sub sub
EGPM2LAN_Set($@) EGPM2LAN_Set($@)
@ -45,7 +74,7 @@ EGPM2LAN_Set($@)
my ($hash, @a) = @_; my ($hash, @a) = @_;
return "no set value specified" if(int(@a) < 2); return "no set value specified" if(int(@a) < 2);
return "Unknown argument $a[1], choose one of on:1,2,3,4,all off:1,2,3,4,all toggle:1,2,3,4 clearreadings statusrequest" if($a[1] eq "?"); return "Unknown argument $a[1], choose one of on:1,2,3,4,all off:1,2,3,4,all toggle:1,2,3,4 clearreadings:noArg statusrequest:noArg" if($a[1] eq "?");
my $name = shift @a; my $name = shift @a;
my $setcommand = shift @a; my $setcommand = shift @a;
@ -184,7 +213,7 @@ sub EGPM2LAN_Statusrequest($$) {
my ($hash, $logLevel) = @_; my ($hash, $logLevel) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $response = CustomGetFileFromURL($hash, "http://".$hash->{IP}."/", 10, undef, 0, $logLevel); my $response = CustomGetFileFromURL($hash, "http://".$hash->{IP}."/", 10, "", 0, $logLevel);
#Log 1,$response; #Log 1,$response;
if(defined($response) && $response =~ /.,.,.,./) if(defined($response) && $response =~ /.,.,.,./)
{ {
@ -198,6 +227,7 @@ sub EGPM2LAN_Statusrequest($$) {
my $newstatestring; my $newstatestring;
my @socketlist = EGPM2LAN_GetDeviceInfo($hash,$response); my @socketlist = EGPM2LAN_GetDeviceInfo($hash,$response);
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
foreach my $powerstate (@powerstates) foreach my $powerstate (@powerstates)
{ {
$index++; $index++;
@ -231,8 +261,11 @@ sub EGPM2LAN_Statusrequest($$) {
#Write state 2 related Socket-Object #Write state 2 related Socket-Object
if (defined($defptr)) if (defined($defptr))
{ {
Log $logLevel, "Update State of ".$defptr->{NAME}; if (ReadingsVal($defptr->{NAME},"state","") ne ($powerstates[$index-1] ? "on" : "off"))
readingsSingleUpdate($defptr, "state", ($powerstates[$index-1] ? "on" : "off") ,0); { #check for chages and update -> trigger event
Log $logLevel, "Update State of ".$defptr->{NAME};
readingsSingleUpdate($defptr, "state", ($powerstates[$index-1] ? "on" : "off") ,1);
}
$defptr->{DEVICENAME} = $hash->{DEVICENAME}; $defptr->{DEVICENAME} = $hash->{DEVICENAME};
$defptr->{SOCKETNAME} = $socketlist[$index-1]; $defptr->{SOCKETNAME} = $socketlist[$index-1];
} }
@ -262,7 +295,8 @@ sub EGPM2LAN_Statusrequest($$) {
sub EGPM2LAN_Logoff($$) { sub EGPM2LAN_Logoff($$) {
my ($hash, $logLevel) = @_; my ($hash, $logLevel) = @_;
CustomGetFileFromURL($hash, "http://".$hash->{IP}."/login.html", 10, undef, 0, $logLevel); #$quiet, $url, $timeout, $data, $noshutdown, $loglevel
CustomGetFileFromURL($hash, "http://".$hash->{IP}."/login.html", 10, "", 0, $logLevel);
return 1; return 1;
} }
@ -312,7 +346,8 @@ EGPM2LAN_Define($$)
<br> <br>
Creates a Gembird &reg; <a href="http://energenie.com/item.aspx?id=7557" >Energenie EG-PM2-LAN</a> device to switch up to 4 sockets over the network. Creates a Gembird &reg; <a href="http://energenie.com/item.aspx?id=7557" >Energenie EG-PM2-LAN</a> device to switch up to 4 sockets over the network.
If you have more than one device, it is helpful to connect and set names for your sockets over the web-interface first. If you have more than one device, it is helpful to connect and set names for your sockets over the web-interface first.
The name settings will be adopted to FHEM and helps you to identify the sockets. Please make sure that you&acute;re logged off from the Energenie web-interface otherwise you can&acute;t control it with FHEM at the same time. The name settings will be adopted to FHEM and helps you to identify the sockets. Please make sure that you&acute;re logged off from the Energenie web-interface otherwise you can&acute;t control it with FHEM at the same time.<b>
EG-PMS2-LAN with surge protector feature was not tested until now.
</ul><br> </ul><br>
<a name="EGPM2LANset"></a> <a name="EGPM2LANset"></a>
<b>Set</b> <b>Set</b>
@ -347,6 +382,7 @@ EGPM2LAN_Define($$)
</ul> </ul>
<br> <br>
<br> <br>
<br>
Example: Example:
<ul> <ul>
@ -356,4 +392,62 @@ EGPM2LAN_Define($$)
</ul> </ul>
=end html =end html
=cut =begin html_DE
<a name="EGPM2LAN"></a>
<h3>EGPM2LAN</h3>
<ul>
<br>
<a name="EGPM2LANdefine"></a>
<b>Define</b>
<ul>
<code>define &lt;name&gt; EGPM2LAN &lt;IP-Address&gt; [&lt;Password&gt;]</code><br>
<br>
Das Modul erstellt eine Verbindung zu einer Gembird &reg; <a href="http://energenie.com/item.aspx?id=7557" >Energenie EG-PM2-LAN</a> Steckdosenleiste.
Falls mehrere Steckdosenleisten über das Netzwerk gesteuert werden, ist es ratsam, diese zuerst über die Web-Oberfläche zu konfigurieren und die einzelnen Steckdosen zu benennen. Die Namen werden dann automatisch in die
Oberfläche von FHEM übernommen. Bitte darauf achten, die Weboberfläche mit <i>Logoff</i> wieder zu verlassen, da der Zugriff sonst blockiert wird.<b>
</ul><br>
<a name="EGPM2LANset"></a>
<b>Set</b>
<ul>
<code>set &lt;name&gt; &lt;[on|off|toggle]&gt &lt;socketnr.&gt;</code><br>
Schaltet die gewählte Steckdose ein oder aus.<br>
<br>
<code>set &lt;name&gt; &lt;[on|off]&gt &lt;all&gt;</code><br>
Schaltet alle Steckdosen gleichzeitig ein oder aus.<br>
<br>
<code>set &lt;name&gt; &lt;staterequest&gt;</code><br>
Aktualisiert die Statusinformation der Steckdosenleiste.<br>
Wenn das globale Attribut <a href="#autocreate">autocreate</a> aktiviert ist, wird für jede Steckdose ein <a href="#EGPM">EGPM</a>-Eintrag erstellt.<br>
<br>
<code>set &lt;name&gt; &lt;clearreadings&gt;</code><br>
Löscht alle ungültigen Einträge im Abschnitt &lt;readings&gt;.
</ul>
<br>
<a name="EGPM2LANget"></a>
<b>Get</b> <ul>N/A</ul><br>
<a name="EGPM2LANattr"></a>
<b>Attribute</b>
<ul>
<li>stateDisplay</li>
Default: <b>socketNumer</b> wechselt zwischen <b>socketNumer</b> and <b>socketName</b> für jeden Statuseintrag. Verwende <b>set statusrequest</b>, um die Anzeige zu aktualisieren.
<li>autocreate</li>
Default: <b>on</b> <a href="#EGPM">EGPM</a>-Einträge werden automatisch mit dem <b>set</b>-command erstellt.
<li><a href="#loglevel">loglevel</a></li>
<li><a href="#readingFnAttributes">readingFnAttributes</a></li>
</ul>
<br>
<br>
<br>
Beispiel:
<ul>
<code>define sleiste EGPM2LAN 10.192.192.20 SecretGarden</code><br>
<code>set sleiste on 1</code><br>
</ul>
</ul>
=end html_DE
=cut

View File

@ -1,5 +1,5 @@
############################################## ##############################################
# $Id: EGPM.pm 2892 2013-07-11 12:47:57Z alexus $ # $Id: EGPM2LAN.pm 2013-12-08 10:11:20Z alexus $
# #
# (c) 2013 Copyright: Alex Storny (moselking at arcor dot de) # (c) 2013 Copyright: Alex Storny (moselking at arcor dot de)
# All rights reserved # All rights reserved
@ -33,6 +33,7 @@ EGPM_Initialize($)
my ($hash) = @_; my ($hash) = @_;
$hash->{SetFn} = "EGPM_Set"; $hash->{SetFn} = "EGPM_Set";
$hash->{GetFn} = "EGPM_Get";
$hash->{DefFn} = "EGPM_Define"; $hash->{DefFn} = "EGPM_Define";
$hash->{AttrList} = "loglevel:0,1,2,3,4,5,6". $readingFnAttributes; $hash->{AttrList} = "loglevel:0,1,2,3,4,5,6". $readingFnAttributes;
$hash->{UndefFn} = "EGPM_Undef"; $hash->{UndefFn} = "EGPM_Undef";
@ -48,11 +49,11 @@ EGPM_Set($@)
my $loglevel = GetLogLevel($name,4); my $loglevel = GetLogLevel($name,4);
return "no set value specified" if(int(@a) < 1); return "no set value specified" if(int(@a) < 1);
return "Unknown argument ?, choose one of off on toggle" if($a[0] eq "?"); return "Unknown argument ?, choose one of off:noArg on:noArg toggle:noArg" if($a[0] eq "?");
if(not Value($parent)) if(not Value($parent))
{ {
my $u = "$parent not found. Please define EGPM2LAN device."; my $u = "$parent device not found. Please define EGPM2LAN device.";
Log $loglevel, $u; Log $loglevel, $u;
return $u; return $u;
} }
@ -60,10 +61,37 @@ EGPM_Set($@)
my $v = join(" ", @a); my $v = join(" ", @a);
Log $loglevel, "EGPM set $name $v"; Log $loglevel, "EGPM set $name $v";
CommandSet(undef,$hash->{IODEV}." $v ".$hash->{SOCKETNR}); CommandSet(undef,$hash->{IODEV}." $v ".$hash->{SOCKETNR});
return undef; return undef;
} }
###################################
sub
EGPM_Get($@)
{
my ($hash, @a) = @_;
my $what;
return "argument is missing" if(int(@a) != 2);
$what = $a[1];
if($what =~ /^(state)$/)
{
if(defined($hash->{READINGS}{$what}))
{
return $hash->{READINGS}{$what}{VAL};
}
else
{
return "reading not found: $what";
}
}
else
{
return "Unknown argument $what, choose one of state:noArg".(exists($hash->{READINGS}{output})?" output:noArg":"");
}
}
##################################### #####################################
sub sub
EGPM_Define($$) EGPM_Define($$)
@ -117,30 +145,29 @@ EGPM_Undef($$)
<h3>EGPM Socket</h3> <h3>EGPM Socket</h3>
<ul> <ul>
Define a Socket from EGPM2LAN Module. If the global Module AUTOCREATE is enabled, Defines a Socket from EGPM2LAN Module. If the global Module AUTOCREATE is enabled,
this device will be created automatically. For manual Setup, pls. see the description of EGPM2LAN. this device will be created automatically. For manual Setup, pls. see the description of <a href="#EGPM2LAN">EGPM2LAN</a>.
<br><br> <br><br>
<a name="EGPMdefine"></a> <a name="EGPMdefine"></a>
<b>Define</b> <b>Define</b>
<ul> <ul>
<code>define &lt;name&gt; EGPM &lt;device&gt; &lt;socket-nr&gt;</code> <code>define &lt;name&gt; EGPM &lt;device&gt; &lt;socket-nr&gt;</code>
<br><br> <br>
Example:
<ul>
<code>define socket_lamp EGPM mainswitch 1</code><br>
<code>set socket_lamp on</code><br>
</ul>
</ul> </ul>
<br> <br>
<a name="EGPMset"></a> <a name="EGPMset"></a>
<b>Set</b> <b>Set</b>
<ul> <code>
<code>set &lt;name&gt; &lt;value&gt</code><br> <ul>set &lt;name&gt; &lt;[on|off|toggle]&gt;</code><br>
Set any value. Switches the socket on or of.
</ul> </ul><br>
Example:
<ul>
<code>define lamp1 EGPM mainswitch 1</code><br>
<code>set lamp1 on</code><br>
</ul>
<br> <br>
<a name="EGPMget"></a> <a name="EGPMget"></a>
@ -153,8 +180,64 @@ EGPM_Undef($$)
<li><a href="#readingFnAttributes">readingFnAttributes</a></li> <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
</ul> </ul>
<br> <br>
<a name="EGPM2LANevents"></a>
<b>Generated events</b>
<ul>
<li>EGPM &lt;name&gt; &lt;[on|off]&gt</li>
</ul>
</ul> </ul>
=end html =end html
=cut =begin html_DE
<a name="EGPM"></a>
<h3>EGPM Steckdose</h3>
<ul>
Definiert eine einzelne Netzwerk-Steckdose vom EGPM2LAN. Diese Definition wird beim Einrichten eines EGPM2LAN automatisch erstellt,
wenn das globale FHEM-Attribut AUTOCREATE aktiviert wurde. Für weitere Informationen, siehe Beschreibung von <a href="#EGPM2LAN">EGPM2LAN</a>.
<br><br>
<a name="EGPMdefine"></a>
<b>Define</b>
<ul>
<code>define &lt;name&gt; EGPM &lt;device&gt; &lt;socket-nr&gt;</code>
<br>
</ul>
<br>
<a name="EGPMset"></a>
<b>Set</b>
<code>
<ul>set &lt;name&gt; &lt;[on|off|toggle]&gt;</code><br>
Schaltet die Steckdose ein oder aus.
</ul><br>
Beispiel:
<ul>
<code>define lampe1 EGPM steckdose 1</code><br>
<code>set lampe1 on</code><br>
</ul>
<br>
<a name="EGPMget"></a>
<b>Get</b> <ul>N/A</ul>
<br>
<a name="EGPMattr"></a>
<b>Attributes</b>
<ul>
<li><a href="#loglevel">loglevel</a></li>
<li><a href="#readingFnAttributes">readingFnAttributes</a></li>
</ul>
<br>
<a name="EGPM2LANevents"></a>
<b>Generated events</b>
<ul>
<li>EGPM &lt;name&gt; &lt;[on|off]&gt</li>
</ul>
</ul>
=end html_DE
=cut