diff --git a/fhem/FHEM/17_EGPM2LAN.pm b/fhem/FHEM/17_EGPM2LAN.pm index 2c800b369..eb3cf6140 100644 --- a/fhem/FHEM/17_EGPM2LAN.pm +++ b/fhem/FHEM/17_EGPM2LAN.pm @@ -1,9 +1,9 @@ ############################################## -# $Id: EGPM2LAN.pm 2013-12-08 10:11:20Z alexus $ +# $Id$ # # 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 # # This script free software; you can redistribute it and/or modify @@ -97,11 +97,11 @@ EGPM2LAN_Set($@) { #switch single Socket EGPM2LAN_Switch($hash, $setcommand, $params, $logLevel); } - EGPM2LAN_Statusrequest($hash, $logLevel); + EGPM2LAN_Statusrequest($hash, $logLevel, 1); } elsif($setcommand eq "toggle") { - my $currentstate = EGPM2LAN_Statusrequest($hash, $logLevel); + my $currentstate = EGPM2LAN_Statusrequest($hash, $logLevel, 1); if(defined($currentstate)) { my @powerstates = split(",", $currentstate); @@ -111,12 +111,12 @@ EGPM2LAN_Set($@) $newcommand="on"; } EGPM2LAN_Switch($hash, $newcommand, $params, $logLevel); - EGPM2LAN_Statusrequest($hash, $logLevel); + EGPM2LAN_Statusrequest($hash, $logLevel, 0); } } elsif($setcommand eq "statusrequest") { - EGPM2LAN_Statusrequest($hash, $logLevel); + EGPM2LAN_Statusrequest($hash, $logLevel, 1); } elsif($setcommand eq "clearreadings") { @@ -209,8 +209,8 @@ sub EGPM2LAN_GetDeviceInfo($$) { } ################################ -sub EGPM2LAN_Statusrequest($$) { - my ($hash, $logLevel) = @_; +sub EGPM2LAN_Statusrequest($$$) { + my ($hash, $logLevel, $autoCr) = @_; my $name = $hash->{NAME}; my $response = CustomGetFileFromURL($hash, "http://".$hash->{IP}."/", 10, "", 0, $logLevel); @@ -244,7 +244,7 @@ sub EGPM2LAN_Statusrequest($$) { #Create Socket-Object if not available 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") { @@ -295,7 +295,7 @@ sub EGPM2LAN_Statusrequest($$) { sub EGPM2LAN_Logoff($$) { 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); return 1; } @@ -321,10 +321,9 @@ EGPM2LAN_Define($$) my $result = EGPM2LAN_Login($hash, 3); if($result == 1) { - #delayed auto-create - #InternalTimer(gettimeofday()+ 3, "EGPM2LAN_Statusrequest", $hash, 4); - EGPM2LAN_Logoff($hash, 4); $hash->{STATE} = "initialized"; + EGPM2LAN_Statusrequest($hash, 4, 0); + EGPM2LAN_Logoff($hash, 4); } return undef; @@ -346,7 +345,7 @@ EGPM2LAN_Define($$)
Creates a Gembird ® Energenie EG-PM2-LAN 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. - The name settings will be adopted to FHEM and helps you to identify the sockets. Please make sure that you´re logged off from the Energenie web-interface otherwise you can´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´re logged off from the Energenie web-interface otherwise you can´t control it with FHEM at the same time.
EG-PMS2-LAN with surge protector feature was not tested until now.
@@ -403,7 +402,7 @@ EGPM2LAN_Define($$)
diff --git a/fhem/FHEM/70_EGPM.pm b/fhem/FHEM/70_EGPM.pm index 220ba56ea..77442f43c 100644 --- a/fhem/FHEM/70_EGPM.pm +++ b/fhem/FHEM/70_EGPM.pm @@ -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 # # This script free software; you can redistribute it and/or modify @@ -26,6 +26,7 @@ package main; use strict; use warnings; +use SetExtensions; sub EGPM_Initialize($) @@ -35,7 +36,7 @@ EGPM_Initialize($) $hash->{SetFn} = "EGPM_Set"; $hash->{GetFn} = "EGPM_Get"; $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"; } @@ -47,9 +48,10 @@ EGPM_Set($@) my $name = shift @a; my $parent = $hash->{IODEV}; my $loglevel = GetLogLevel($name,4); + my $cmdList = "off:noArg on:noArg toggle:noArg"; 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)) { @@ -58,12 +60,19 @@ EGPM_Set($@) return $u; } - my $v = join(" ", @a); - Log $loglevel, "EGPM set $name $v"; - CommandSet(undef,$hash->{IODEV}." $v ".$hash->{SOCKETNR}); - return undef; + if($a[0] =~ /^(on|off|toggle)$/) + { + my $v = join(" ", @a); + 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 EGPM_Get($@) @@ -110,14 +119,24 @@ EGPM_Define($$) $hash->{IODEV} = $parent; $hash->{SOCKETNR} = $socket; $hash->{NAME} = $name; - + $modules{EGPM}{defptr}{$parent.$socket} = $hash; if (defined($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; } @@ -159,9 +178,11 @@ EGPM_Undef($$) Set - -