2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-21 07:56:03 +00:00

98_EDIPLUG.pm: fix wrong user at first start

git-svn-id: https://svn.fhem.de/fhem/trunk@12457 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
wzut 2016-10-28 17:57:47 +00:00
parent b30390fc7a
commit 511664a047

View File

@ -30,6 +30,7 @@
# 2015-03-07 V1.02 fix schedule # 2015-03-07 V1.02 fix schedule
# 2015-09-12 V1.03 fix errorcount and interval # 2015-09-12 V1.03 fix errorcount and interval
# 2016-01-20 V1.04 add Reading onoff for SP2101W # 2016-01-20 V1.04 add Reading onoff for SP2101W
# 2016-10-28 V1.05 fix wrong user on firststart
# #
################################################################ ################################################################
@ -41,7 +42,6 @@ use warnings;
use Time::HiRes qw(gettimeofday); use Time::HiRes qw(gettimeofday);
use HttpUtils; use HttpUtils;
use SetExtensions; use SetExtensions;
use XML::Simple qw(:strict); use XML::Simple qw(:strict);
sub EDIPLUG_Initialize($); sub EDIPLUG_Initialize($);
@ -137,13 +137,15 @@ sub EDIPLUG_Define($$) {
$hash->{httpheader} = ""; $hash->{httpheader} = "";
$hash->{conn} = ""; $hash->{conn} = "";
$hash->{data} = ""; $hash->{data} = "";
$hash->{".firststart"} = 1;
readingsSingleUpdate($hash, "state", "defined",0); readingsSingleUpdate($hash, "state", "defined",0);
for (my $i=0; $i<8; $i++) { $hash->{helper}{"list"}[$i] = ""; } # einer mehr als Tage :) for (my $i=0; $i<8; $i++) { $hash->{helper}{"list"}[$i] = ""; } # einer mehr als Tage :)
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "EDIPLUG_GetUpdate", $hash, 0); InternalTimer(gettimeofday()+5, "EDIPLUG_GetUpdate", $hash, 0);
EDIPLUG_Get($hash,$hash->{NAME},"info"); #EDIPLUG_Get($hash,$hash->{NAME},"info");
return undef; return undef;
} }
@ -161,10 +163,27 @@ sub EDIPLUG_GetUpdate($) {
my ($hash) = @_; my ($hash) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
if (!$init_done)
{
RemoveInternalTimer($hash);
InternalTimer(gettimeofday()+5,"EDIPLUG_GetUpdate", $hash, 0);
return;
}
$hash->{INTERVAL} = AttrVal($name, "interval", $hash->{INTERVAL}) if ($hash->{INTERVAL} != 3600); $hash->{INTERVAL} = AttrVal($name, "interval", $hash->{INTERVAL}) if ($hash->{INTERVAL} != 3600);
if (($hash->{".firststart"}) && !IsDisabled($name))
{
Log3 $name, 5, $name.", GetUpdate (firststart)";
$hash->{".firststart"} = 0;
EDIPLUG_Get($hash,$name,"info");
InternalTimer(gettimeofday()+$hash->{timeout}+2, "EDIPLUG_GetUpdate", $hash, 1) if ($hash->{INTERVAL});
return;
}
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "EDIPLUG_GetUpdate", $hash, 1) if ($hash->{INTERVAL}); InternalTimer(gettimeofday()+$hash->{INTERVAL}, "EDIPLUG_GetUpdate", $hash, 1) if ($hash->{INTERVAL});
Log3 $name, 5, "EDIPLUG: GetUpdate"; return if(IsDisabled($name));
Log3 $name, 5, $name.", GetUpdate";
EDIPLUG_Get($hash,$name,"status") if ($hash->{INTERVAL}); EDIPLUG_Get($hash,$name,"status") if ($hash->{INTERVAL});
return ; return ;
} }
@ -176,7 +195,7 @@ sub EDIPLUG_Read($$$)
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $state; my $state;
Log3 $name, 5, "$name , Read : $hash , $buffer\r\n"; Log3 $name, 5, $name.", Read : $hash , $buffer\r\n";
if ($err) if ($err)
{ {
@ -185,10 +204,10 @@ sub EDIPLUG_Read($$$)
$hash->{ERROR} = $err; $hash->{ERROR} = $err;
$hash->{ERRORTIME} = TimeNow(); $hash->{ERRORTIME} = TimeNow();
$hash->{ERRORCOUNT}++; $hash->{ERRORCOUNT}++;
Log3 $name, 3, "$name: return ".$error."[".$hash->{ERRORCOUNT}."] -> ".$err; Log3 $name, 3, "$name, return ".$error."[".$hash->{ERRORCOUNT}."] -> ".$err;
if ($hash->{ERRORCOUNT} > 5) if ($hash->{ERRORCOUNT} > 5)
{ {
Log3 $name, 3, "$name: too many errors, setting interval from ".$hash->{INTERVAL}." to 3600 seconds" if($hash->{INTERVAL} != 3600); Log3 $name, 3, "$name, too many errors, setting interval from ".$hash->{INTERVAL}." to 3600 seconds" if($hash->{INTERVAL} != 3600);
$hash->{INTERVAL} = 3600; $hash->{INTERVAL} = 3600;
} }
readingsSingleUpdate($hash, "state", $error, 0); readingsSingleUpdate($hash, "state", $error, 0);
@ -198,7 +217,7 @@ sub EDIPLUG_Read($$$)
if ($hash->{INTERVAL} == 3600) if ($hash->{INTERVAL} == 3600)
{ {
my $interval = AttrVal($name, "interval", 60); my $interval = AttrVal($name, "interval", 60);
Log3 $name, 3, "$name: set interval back to $interval seconds"; Log3 $name, 3, "$name, set interval back to $interval seconds";
$hash->{INTERVAL} = $interval; $hash->{INTERVAL} = $interval;
} }
@ -207,7 +226,7 @@ sub EDIPLUG_Read($$$)
{ {
# sollte eigentlich gar nicht vorkommen bzw. nur bei fehlerhaften uebergebenen XML String # sollte eigentlich gar nicht vorkommen bzw. nur bei fehlerhaften uebergebenen XML String
$hash->{ERRORCOUNT}++; $hash->{ERRORCOUNT}++;
Log3 $name, 3, "$name: empty return buffer [".$hash->{ERRORCOUNT}."]"; Log3 $name, 3, "$name, empty return buffer [".$hash->{ERRORCOUNT}."]";
$hash->{ERROR} = "empty return buffer"; $hash->{ERROR} = "empty return buffer";
$hash->{ERRORTIME} = TimeNow(); $hash->{ERRORTIME} = TimeNow();
return; return;
@ -383,8 +402,10 @@ sub EDIPLUG_Set($@) {
my ($hash, $name , @a) = @_; my ($hash, $name , @a) = @_;
my $cmd = $a[0]; my $cmd = $a[0];
return "set $name needs at least one argument" if(int(@a) < 1); return "set $name needs at least one argument" if(int(@a) < 1);
return ($cmd eq "?") ? undef : "no set commands are allowed on a read-only device !" if ($attr{$name}{'read-only'} eq "1"); return ($cmd eq "?") ? undef : "no set commands are allowed on a read-only device !" if ($attr{$name}{'read-only'} eq "1");
return ($cmd eq "?") ? undef : "no set commands are allowed on a disabled device!" if(IsDisabled($name));
my $list = "on off list addlist delete:0,1,2,3,4,5,6 dellist day clear_error"; my $list = "on off list addlist delete:0,1,2,3,4,5,6 dellist day clear_error";
@ -519,7 +540,7 @@ sub EDIPLUG_Get($@) {
my $name= $hash->{NAME}; my $name= $hash->{NAME};
return "get $name needs at least one argument" if(int(@a) < 2); return "get $name needs at least one argument" if(int(@a) < 2);
return "no get commands are allowed on a disabled device !" if(IsDisabled($name));
my $cmd = $a[1]; my $cmd = $a[1];
return "$name get power is not supported by this model !" if (($cmd eq "power") && ($hash->{MODEL} ne "SP2101W")); return "$name get power is not supported by this model !" if (($cmd eq "power") && ($hash->{MODEL} ne "SP2101W"));
@ -617,7 +638,9 @@ sub encode_list(@)
1; 1;
=pod =pod
=item device
=item summary controls EDIPLUG WLAN switches
=item summary_DE steuert EDIPLUG WLAN Schaltsteckdosen
=begin html =begin html
<a name="EDIPLUG"></a> <a name="EDIPLUG"></a>