Status-Check after Restart/Definition and SetExtensions added.

git-svn-id: https://svn.fhem.de/fhem/trunk@5344 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
alexus2033
2014-03-27 20:06:31 +00:00
parent 2a0eaa16e8
commit 9f88f0d569
2 changed files with 53 additions and 32 deletions

View File

@@ -1,9 +1,9 @@
############################################## ##############################################
# $Id: EGPM2LAN.pm 2013-12-08 10:11:20Z alexus $ # $Id$
# #
# based / modified Version 98_EGPMS2LAN from ericl # based / modified Version 98_EGPMS2LAN from ericl
# #
# (c) 2013 Copyright: Alex Storny (moselking at arcor dot de) # (c) 2013, 2014 Copyright: Alex Storny (moselking at arcor dot de)
# All rights reserved # All rights reserved
# #
# This script free software; you can redistribute it and/or modify # This script free software; you can redistribute it and/or modify
@@ -97,11 +97,11 @@ EGPM2LAN_Set($@)
{ #switch single Socket { #switch single Socket
EGPM2LAN_Switch($hash, $setcommand, $params, $logLevel); EGPM2LAN_Switch($hash, $setcommand, $params, $logLevel);
} }
EGPM2LAN_Statusrequest($hash, $logLevel); EGPM2LAN_Statusrequest($hash, $logLevel, 1);
} }
elsif($setcommand eq "toggle") elsif($setcommand eq "toggle")
{ {
my $currentstate = EGPM2LAN_Statusrequest($hash, $logLevel); my $currentstate = EGPM2LAN_Statusrequest($hash, $logLevel, 1);
if(defined($currentstate)) if(defined($currentstate))
{ {
my @powerstates = split(",", $currentstate); my @powerstates = split(",", $currentstate);
@@ -111,12 +111,12 @@ EGPM2LAN_Set($@)
$newcommand="on"; $newcommand="on";
} }
EGPM2LAN_Switch($hash, $newcommand, $params, $logLevel); EGPM2LAN_Switch($hash, $newcommand, $params, $logLevel);
EGPM2LAN_Statusrequest($hash, $logLevel); EGPM2LAN_Statusrequest($hash, $logLevel, 0);
} }
} }
elsif($setcommand eq "statusrequest") elsif($setcommand eq "statusrequest")
{ {
EGPM2LAN_Statusrequest($hash, $logLevel); EGPM2LAN_Statusrequest($hash, $logLevel, 1);
} }
elsif($setcommand eq "clearreadings") elsif($setcommand eq "clearreadings")
{ {
@@ -209,8 +209,8 @@ sub EGPM2LAN_GetDeviceInfo($$) {
} }
################################ ################################
sub EGPM2LAN_Statusrequest($$) { sub EGPM2LAN_Statusrequest($$$) {
my ($hash, $logLevel) = @_; my ($hash, $logLevel, $autoCr) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $response = CustomGetFileFromURL($hash, "http://".$hash->{IP}."/", 10, "", 0, $logLevel); my $response = CustomGetFileFromURL($hash, "http://".$hash->{IP}."/", 10, "", 0, $logLevel);
@@ -244,7 +244,7 @@ sub EGPM2LAN_Statusrequest($$) {
#Create Socket-Object if not available #Create Socket-Object if not available
my $defptr = $modules{EGPM}{defptr}{$name.$index}; my $defptr = $modules{EGPM}{defptr}{$name.$index};
if(AttrVal($name, "autocreate", "on") eq "on" && not defined($defptr)) if($autoCr && AttrVal($name, "autocreate", "on") eq "on" && not defined($defptr))
{ {
if(Value("autocreate") eq "active") if(Value("autocreate") eq "active")
{ {
@@ -295,7 +295,7 @@ sub EGPM2LAN_Statusrequest($$) {
sub EGPM2LAN_Logoff($$) { sub EGPM2LAN_Logoff($$) {
my ($hash, $logLevel) = @_; my ($hash, $logLevel) = @_;
#$quiet, $url, $timeout, $data, $noshutdown, $loglevel #$quiet, $url, $timeout, $data, $noshutdown, $loglevel
CustomGetFileFromURL($hash, "http://".$hash->{IP}."/login.html", 10, "", 0, $logLevel); CustomGetFileFromURL($hash, "http://".$hash->{IP}."/login.html", 10, "", 0, $logLevel);
return 1; return 1;
} }
@@ -321,10 +321,9 @@ EGPM2LAN_Define($$)
my $result = EGPM2LAN_Login($hash, 3); my $result = EGPM2LAN_Login($hash, 3);
if($result == 1) if($result == 1)
{ {
#delayed auto-create
#InternalTimer(gettimeofday()+ 3, "EGPM2LAN_Statusrequest", $hash, 4);
EGPM2LAN_Logoff($hash, 4);
$hash->{STATE} = "initialized"; $hash->{STATE} = "initialized";
EGPM2LAN_Statusrequest($hash, 4, 0);
EGPM2LAN_Logoff($hash, 4);
} }
return undef; return undef;
@@ -346,7 +345,7 @@ 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.<br>
<b>EG-PMS2-LAN with surge protector feature was not tested until now.</b> <b>EG-PMS2-LAN with surge protector feature was not tested until now.</b>
</ul><br> </ul><br>
<a name="EGPM2LANset"></a> <a name="EGPM2LANset"></a>
@@ -403,7 +402,7 @@ EGPM2LAN_Define($$)
<ul> <ul>
<code>define &lt;name&gt; EGPM2LAN &lt;IP-Address&gt; [&lt;Password&gt;]</code><br> <code>define &lt;name&gt; EGPM2LAN &lt;IP-Address&gt; [&lt;Password&gt;]</code><br>
<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. Das Modul erstellt eine Verbindung zu einer Gembird &reg; <a href="http://energenie.com/item.aspx?id=7557" >Energenie EG-PM2-LAN</a> Steckdosenleiste und steuert 4 angeschlossene Ger&auml;te..
Falls mehrere Steckdosenleisten &uuml;ber das Netzwerk gesteuert werden, ist es ratsam, diese zuerst &uuml;ber die Web-Oberfl&auml;che zu konfigurieren und die einzelnen Steckdosen zu benennen. Die Namen werden dann automatisch in die Falls mehrere Steckdosenleisten &uuml;ber das Netzwerk gesteuert werden, ist es ratsam, diese zuerst &uuml;ber die Web-Oberfl&auml;che zu konfigurieren und die einzelnen Steckdosen zu benennen. Die Namen werden dann automatisch in die
Oberfl&auml;che von FHEM &uuml;bernommen. Bitte darauf achten, die Weboberfl&auml;che mit <i>Logoff</i> wieder zu verlassen, da der Zugriff sonst blockiert wird. Oberfl&auml;che von FHEM &uuml;bernommen. Bitte darauf achten, die Weboberfl&auml;che mit <i>Logoff</i> wieder zu verlassen, da der Zugriff sonst blockiert wird.
</ul><br> </ul><br>

View File

@@ -1,7 +1,7 @@
############################################## ##############################################
# $Id: EGPM2LAN.pm 2013-12-08 10:11:20Z alexus $ # $Id$
# #
# (c) 2013 Copyright: Alex Storny (moselking at arcor dot de) # (c) 2013, 2014 Copyright: Alex Storny (moselking at arcor dot de)
# All rights reserved # All rights reserved
# #
# This script free software; you can redistribute it and/or modify # This script free software; you can redistribute it and/or modify
@@ -26,6 +26,7 @@ package main;
use strict; use strict;
use warnings; use warnings;
use SetExtensions;
sub sub
EGPM_Initialize($) EGPM_Initialize($)
@@ -35,7 +36,7 @@ EGPM_Initialize($)
$hash->{SetFn} = "EGPM_Set"; $hash->{SetFn} = "EGPM_Set";
$hash->{GetFn} = "EGPM_Get"; $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";
} }
@@ -47,9 +48,10 @@ EGPM_Set($@)
my $name = shift @a; my $name = shift @a;
my $parent = $hash->{IODEV}; my $parent = $hash->{IODEV};
my $loglevel = GetLogLevel($name,4); my $loglevel = GetLogLevel($name,4);
my $cmdList = "off:noArg on:noArg toggle:noArg";
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:noArg on:noArg toggle:noArg" if($a[0] eq "?"); return SetExtensions($hash,$cmdList,$name,@a) if($a[0] eq "?");
if(not Value($parent)) if(not Value($parent))
{ {
@@ -58,12 +60,19 @@ EGPM_Set($@)
return $u; return $u;
} }
my $v = join(" ", @a); if($a[0] =~ /^(on|off|toggle)$/)
Log $loglevel, "EGPM set $name $v"; {
CommandSet(undef,$hash->{IODEV}." $v ".$hash->{SOCKETNR}); my $v = join(" ", @a);
return undef; Log $loglevel, "EGPM set $name $v";
CommandSet(undef,$hash->{IODEV}." $v ".$hash->{SOCKETNR});
return undef;
} else {
Log $loglevel, "EGPM set $name $a[0]";
return SetExtensions($hash,$cmdList,$name,@a);
}
} }
################################### ###################################
sub sub
EGPM_Get($@) EGPM_Get($@)
@@ -117,7 +126,17 @@ EGPM_Define($$)
{ {
$attr{$name}{room} = $attr{$parent}{room}; $attr{$name}{room} = $attr{$parent}{room};
} }
$hash->{STATE} = "initialized";
my $currentstate = ReadingsVal($parent, "state", "?");
if ($currentstate eq "?")
{
$hash->{STATE} = "initialized";
}
else
{
my @powerstates = split(":", $currentstate);
$hash->{STATE} = trim(substr $powerstates[$socket], 1, 3);
}
return undef; return undef;
} }
@@ -159,9 +178,11 @@ EGPM_Undef($$)
<a name="EGPMset"></a> <a name="EGPMset"></a>
<b>Set</b> <b>Set</b>
<code> <ul><code>set &lt;name&gt; &lt;[on|off|toggle]&gt;</code><br>
<ul>set &lt;name&gt; &lt;[on|off|toggle]&gt;</code><br>
Switches the socket on or of. Switches the socket on or of.
</ul>
<ul><code>set &lt;name&gt; &lt;[on-for-timer|off-for-timer|on-till|off-till|blink|intervals]&gt;</code><br>
Switches the socket for a specified time+duration or n-times. For Details see <a href="#setExtensions">set extensions</a>
</ul><br> </ul><br>
Example: Example:
<ul> <ul>
@@ -194,9 +215,8 @@ EGPM_Undef($$)
<a name="EGPM"></a> <a name="EGPM"></a>
<h3>EGPM Steckdose</h3> <h3>EGPM Steckdose</h3>
<ul> <ul>
Definiert eine einzelne Netzwerk-Steckdose vom EGPM2LAN. Diese Definition wird beim Einrichten eines EGPM2LAN automatisch erstellt, 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<EFBFBD>r weitere Informationen, siehe Beschreibung von <a href="#EGPM2LAN">EGPM2LAN</a>. wenn das globale FHEM-Attribut AUTOCREATE aktiviert wurde. F&uuml;r weitere Informationen, siehe Beschreibung von <a href="#EGPM2LAN">EGPM2LAN</a>.
<br><br> <br><br>
<a name="EGPMdefine"></a> <a name="EGPMdefine"></a>
@@ -209,9 +229,11 @@ EGPM_Undef($$)
<a name="EGPMset"></a> <a name="EGPMset"></a>
<b>Set</b> <b>Set</b>
<code> <ul><code>set &lt;name&gt; &lt;[on|off|toggle]&gt;</code><br>
<ul>set &lt;name&gt; &lt;[on|off|toggle]&gt;</code><br>
Schaltet die Steckdose ein oder aus. Schaltet die Steckdose ein oder aus.
</ul>
<ul><code>set &lt;name&gt; &lt;[on-for-timer|off-for-timer|on-till|off-till|blink|intervals]&gt;</code><br>
Schaltet die Steckdose f&uuml; einen bestimmten Zeitraum oder mehrfach hintereinander. Weitere Infos hierzu unter <a href="#setExtensions">set extensions</a>.
</ul><br> </ul><br>
Beispiel: Beispiel:
<ul> <ul>