mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
fixed spaces in Socketnames -> thanks to eric
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@3423 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
16124d87af
commit
97c0b787c3
@ -1,5 +1,5 @@
|
|||||||
##############################################
|
##############################################
|
||||||
# $Id: EGPM2LAN.pm 2891 2013-07-11 12:47:57Z alexus $
|
# $Id: EGPM2LAN.pm 2891 2013-07-14 19:03:51Z alexus $
|
||||||
#
|
#
|
||||||
# based / modified Version 98_EGPMS2LAN from ericl
|
# based / modified Version 98_EGPMS2LAN from ericl
|
||||||
#
|
#
|
||||||
@ -13,8 +13,6 @@
|
|||||||
#
|
#
|
||||||
# The GNU General Public License can be found at
|
# The GNU General Public License can be found at
|
||||||
# http://www.gnu.org/copyleft/gpl.html.
|
# http://www.gnu.org/copyleft/gpl.html.
|
||||||
# A copy is found in the textfile GPL.txt and important notices to the license
|
|
||||||
# from the author is found in LICENSE.txt distributed with these scripts.
|
|
||||||
#
|
#
|
||||||
# This script is distributed in the hope that it will be useful,
|
# This script is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
@ -47,44 +45,30 @@ 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 off:1,2,3,4 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 statusrequest" if($a[1] eq "?");
|
||||||
|
|
||||||
|
|
||||||
my $name = shift @a;
|
my $name = shift @a;
|
||||||
my $setcommand = shift @a;
|
my $setcommand = shift @a;
|
||||||
my $params = join(" ", @a);
|
my $params = join(" ", @a);
|
||||||
my $logLevel = GetLogLevel($name,4);
|
my $logLevel = GetLogLevel($name,4);
|
||||||
my $post = "http://" . $hash->{IP} . "/ POST:";
|
|
||||||
|
|
||||||
Log $logLevel, "EGPM2LAN set $name (". $hash->{IP}. ") $setcommand $params";
|
Log $logLevel, "EGPM2LAN set $name (". $hash->{IP}. ") $setcommand $params";
|
||||||
|
|
||||||
EGPM2LAN_Login($hash, $logLevel);
|
EGPM2LAN_Login($hash, $logLevel);
|
||||||
|
|
||||||
if($setcommand eq "on")
|
if($setcommand eq "on" || $setcommand eq "off")
|
||||||
{
|
{
|
||||||
$post .= "cte1=" . ($params == "1" ? "1" : "") . "&cte2=" . ($params == "2" ? "1" : "") . "&cte3=" . ($params == "3" ? "1" : "") . "&cte4=". ($params == "4" ? "1" : "");
|
if($params eq "all")
|
||||||
Log $logLevel, "EGPM2LAN $post";
|
{ #switch all Sockets; thanks to eric!
|
||||||
eval {
|
for (my $count = 1; $count <= 4; $count++)
|
||||||
CustomGetFileFromURL($hash, $post, 0, $logLevel);
|
{
|
||||||
EGPM2LAN_Statusrequest($hash, $logLevel);
|
EGPM2LAN_Switch($hash, $setcommand, $count, $logLevel);
|
||||||
};
|
}
|
||||||
if ($@){
|
}
|
||||||
### catch block
|
else
|
||||||
Log $logLevel, "EGPM2LAN error: $@";
|
{ #switch single Socket
|
||||||
};
|
EGPM2LAN_Switch($hash, $setcommand, $params, $logLevel);
|
||||||
}
|
}
|
||||||
elsif($setcommand eq "off")
|
|
||||||
{
|
|
||||||
$post .= "cte1=" . ($params == "1" ? "0" : "") . "&cte2=" . ($params == "2" ? "0" : "") . "&cte3=" . ($params == "3" ? "0" : "") . "&cte4=". ($params == "4" ? "0" : "");
|
|
||||||
Log $logLevel, "EGPM2LAN $post";
|
|
||||||
eval {
|
|
||||||
CustomGetFileFromURL($hash, $post, 0, $logLevel);
|
|
||||||
EGPM2LAN_Statusrequest($hash, $logLevel);
|
EGPM2LAN_Statusrequest($hash, $logLevel);
|
||||||
};
|
|
||||||
if ($@){
|
|
||||||
### catch block
|
|
||||||
Log $logLevel, "EGPM2LAN error: $@";
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
elsif($setcommand eq "toggle")
|
elsif($setcommand eq "toggle")
|
||||||
{
|
{
|
||||||
@ -123,11 +107,30 @@ EGPM2LAN_Set($@)
|
|||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
################################
|
||||||
|
sub EGPM2LAN_Switch($$$$) {
|
||||||
|
my ($hash, $state, $port, $logLevel) = @_;
|
||||||
|
$state = ($state eq "on" ? "1" : "0");
|
||||||
|
|
||||||
|
my $fritz = 0; #may be important for FritzBox-users
|
||||||
|
my $data = "cte1=" . ($port == "1" ? $state : "") . "&cte2=" . ($port == "2" ? $state : "") . "&cte3=" . ($port == "3" ? $state : "") . "&cte4=". ($port == "4" ? $state : "");
|
||||||
|
Log $logLevel, "EGPM2LAN $data";
|
||||||
|
eval {
|
||||||
|
CustomGetFileFromURL($hash ,"http://".$hash->{IP}."/",10 ,$data ,$fritz ,$logLevel);
|
||||||
|
};
|
||||||
|
if ($@){
|
||||||
|
### catch block
|
||||||
|
Log $logLevel, "EGPM2LAN error: $@";
|
||||||
|
};
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
################################
|
################################
|
||||||
sub EGPM2LAN_Login($$) {
|
sub EGPM2LAN_Login($$) {
|
||||||
my ($hash, $logLevel) = @_;
|
my ($hash, $logLevel) = @_;
|
||||||
|
|
||||||
Log $logLevel,"EGPM2LAN try to Login";
|
Log $logLevel,"EGPM2LAN try to Login @".$hash->{IP};
|
||||||
|
|
||||||
eval{
|
eval{
|
||||||
CustomGetFileFromURL($hash, "http://".$hash->{IP}."/login.html", 10, "pw=" . (defined($hash->{PASSWORD}) ? $hash->{PASSWORD} : ""), 0, $logLevel);
|
CustomGetFileFromURL($hash, "http://".$hash->{IP}."/login.html", 10, "pw=" . (defined($hash->{PASSWORD}) ? $hash->{PASSWORD} : ""), 0, $logLevel);
|
||||||
@ -138,6 +141,8 @@ sub EGPM2LAN_Login($$) {
|
|||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Log $logLevel,"EGPM2LAN Login successful!";
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +159,9 @@ sub EGPM2LAN_GetDeviceInfo($$) {
|
|||||||
my @socketlist;
|
my @socketlist;
|
||||||
while ($input =~ m/<h2 class=\"ener\">(.+?)<\/h2>/gi)
|
while ($input =~ m/<h2 class=\"ener\">(.+?)<\/h2>/gi)
|
||||||
{
|
{
|
||||||
push(@socketlist,trim($1));
|
my $socketname = trim($1);
|
||||||
|
$socketname =~ s/ /_/g; #remove spaces
|
||||||
|
push(@socketlist, $socketname);
|
||||||
}
|
}
|
||||||
|
|
||||||
#check 4 dublicate Names
|
#check 4 dublicate Names
|
||||||
@ -303,7 +310,8 @@ EGPM2LAN_Define($$)
|
|||||||
<code>define <name> EGPM2LAN <IP-Address> [<Password>]</code><br>
|
<code>define <name> EGPM2LAN <IP-Address> [<Password>]</code><br>
|
||||||
<br>
|
<br>
|
||||||
Defines an <a href="http://energenie.com/item.aspx?id=7557" >Energenie EG-PM2-LAN</a> device to switch up to 4 sockets over the network.
|
Defines an <a href="http://energenie.com/item.aspx?id=7557" >Energenie EG-PM2-LAN</a> device to switch up to 4 sockets over the network.
|
||||||
You can connect and configure your device over the web-interface. Name Settings will be adopted to Fhem-Devices to identify the sockets.
|
If you have more than one device, it is helpful to connect and set names for your sockets over the web-interface.
|
||||||
|
Name Settings will be adopted to FHEM and helps you to identify the sockets later.
|
||||||
<br>
|
<br>
|
||||||
</ul>
|
</ul>
|
||||||
<a name="EGPM2LANget"></a>
|
<a name="EGPM2LANget"></a>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user