mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-01 13:29:26 +00:00
00_OW2S0SMSGUARD.pm: add set delay command
git-svn-id: https://svn.fhem.de/fhem/trunk@23674 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
73370c87f4
commit
b6fbf60fd9
@ -43,19 +43,20 @@ BEGIN
|
|||||||
DevIo_OpenDev
|
DevIo_OpenDev
|
||||||
DevIo_SimpleRead
|
DevIo_SimpleRead
|
||||||
Dispatch
|
Dispatch
|
||||||
DoTrigger
|
|
||||||
init_done
|
init_done
|
||||||
IsDisabled
|
IsDisabled
|
||||||
InternalTimer
|
InternalTimer
|
||||||
Log3
|
Log3
|
||||||
modules
|
modules
|
||||||
ReadingsVal
|
ReadingsVal
|
||||||
|
ReadingsNum
|
||||||
readingsSingleUpdate
|
readingsSingleUpdate
|
||||||
readingsBulkUpdate
|
readingsBulkUpdate
|
||||||
readingsBeginUpdate
|
readingsBeginUpdate
|
||||||
readingsEndUpdate
|
readingsEndUpdate
|
||||||
readingFnAttributes
|
readingFnAttributes
|
||||||
RemoveInternalTimer
|
RemoveInternalTimer
|
||||||
|
setDevAttrList
|
||||||
setReadingsVal
|
setReadingsVal
|
||||||
TimeNow
|
TimeNow
|
||||||
)
|
)
|
||||||
@ -87,8 +88,8 @@ sub Initialize {
|
|||||||
$hash->{SetFn} = \&SetFn;
|
$hash->{SetFn} = \&SetFn;
|
||||||
$hash->{AttrFn} = \&AttrFn;
|
$hash->{AttrFn} = \&AttrFn;
|
||||||
$hash->{ParseFn} = \&ParseFn;
|
$hash->{ParseFn} = \&ParseFn;
|
||||||
$hash->{AttrList} = 'interval disable:0,1 mapOWIDs useSubDevices:0,1 '
|
$hash->{AttrList} = 'model:master,unknown,DS2401,DS1820,DS18B20,DS1822 '.$readingFnAttributes; # Slave Device
|
||||||
.'model:master,unknown,DS2401,DS1820,DS18B20,DS1822 '.$readingFnAttributes;
|
$hash->{AutoCreate} = { '^OW.*' => {ATTR => 'event-on-change-reading:.*', FILTER => '%NAME', GPLOT => q{}} };
|
||||||
|
|
||||||
return FHEM::Meta::InitMod( __FILE__, $hash ) if ($hasmeta);
|
return FHEM::Meta::InitMod( __FILE__, $hash ) if ($hasmeta);
|
||||||
|
|
||||||
@ -99,13 +100,14 @@ sub Initialize {
|
|||||||
|
|
||||||
sub DefineFn {
|
sub DefineFn {
|
||||||
|
|
||||||
my $msg = 'wrong syntax: define <name> OW2S0SMSGUARD devicename';
|
my $msg = 'wrong syntax: define <name> OW2S0SMSGUARD IO Device or model OWID';
|
||||||
my $hash = shift;
|
my $hash = shift;
|
||||||
my $def = shift // return $msg;
|
my $def = shift // return $msg;
|
||||||
|
|
||||||
my ($name, undef, $dev, $interval) = split(m{ \s+ }xms, $def, 4);
|
my ($name, undef, $dev, $interval, $model) = split(m{ \s+ }xms, $def, 5);
|
||||||
|
|
||||||
$dev // return $msg;
|
$dev // return $msg;
|
||||||
|
$model //= 'unknown';
|
||||||
|
|
||||||
DevIo_CloseDev($hash);
|
DevIo_CloseDev($hash);
|
||||||
|
|
||||||
@ -116,19 +118,22 @@ sub DefineFn {
|
|||||||
$interval //= 30;
|
$interval //= 30;
|
||||||
$hash->{INTERVAL} = $interval;
|
$hash->{INTERVAL} = $interval;
|
||||||
$hash->{OWDEVICES} = 0;
|
$hash->{OWDEVICES} = 0;
|
||||||
|
$hash->{addr} = 'master';
|
||||||
|
setDevAttrList($name,'interval disable:0,1 mapOWIDs useSubDevices:0,1 model:master,unknown,DS2401,DS1820,DS18B20,DS1822 '.$readingFnAttributes);
|
||||||
CommandAttr(undef, "$name model master") if (!exists($attr{$name}{model}));
|
CommandAttr(undef, "$name model master") if (!exists($attr{$name}{model}));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (exists($modules{OW2S0SMSGUARD}{defptr}{$addr}) && $modules{OW2S0SMSGUARD}{defptr}{$addr}->{NAME} ne $name) {
|
if (exists($modules{OW2S0SMSGUARD}{defptr}{$addr}) && $modules{OW2S0SMSGUARD}{defptr}{$addr}->{NAME} ne $name) {
|
||||||
return "$name, a OW2S0SMSGUARD device with address $addr is already defined as ".$modules{OW2S0SMSGUARD}{defptr}{$addr}->{NAME};
|
return "$name, a OW2S0SMSGUARD device with address $addr is already defined as ".$modules{OW2S0SMSGUARD}{defptr}{$addr}->{NAME};
|
||||||
}
|
}
|
||||||
|
$hash->{addr} = $addr;
|
||||||
|
CommandAttr(undef, "$name model $model") if (!exists($attr{$name}{model}));
|
||||||
}
|
}
|
||||||
|
|
||||||
$hash->{STATE} = 'defined';
|
$hash->{STATE} = 'defined';
|
||||||
$hash->{NOTIFYDEV} = 'global';
|
$hash->{NOTIFYDEV} = 'global';
|
||||||
$hash->{addr} = $addr;
|
$hash->{DELAY} = .5;
|
||||||
$hash->{SVN} = (qw($Id:BETA $))[2];
|
$hash->{SVN} = (qw($Id$))[2];
|
||||||
|
|
||||||
|
|
||||||
$modules{OW2S0SMSGUARD}{defptr}{$addr} = $hash;
|
$modules{OW2S0SMSGUARD}{defptr}{$addr} = $hash;
|
||||||
|
|
||||||
@ -236,7 +241,7 @@ sub DoInit {
|
|||||||
if ($hash->{INTERVAL}) {
|
if ($hash->{INTERVAL}) {
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
SimpleWrite($hash, "\$L+\n\$?");
|
SimpleWrite($hash, "\$L+\n\$?");
|
||||||
InternalTimer(gettimeofday()+1, "FHEM::OW2S0SMSGUARD::GetUpdate", $hash, 0);
|
InternalTimer(gettimeofday()+1, 'FHEM::OW2S0SMSGUARD::GetUpdate', $hash, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -253,7 +258,7 @@ sub GetUpdate {
|
|||||||
|
|
||||||
return if (IsDisabled($name) || !$hash->{INTERVAL} || ($hash->{addr} ne 'master'));
|
return if (IsDisabled($name) || !$hash->{INTERVAL} || ($hash->{addr} ne 'master'));
|
||||||
|
|
||||||
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "FHEM::OW2S0SMSGUARD::GetUpdate", $hash, 0);
|
InternalTimer(gettimeofday()+$hash->{INTERVAL}, 'FHEM::OW2S0SMSGUARD::GetUpdate', $hash, 0);
|
||||||
SimpleWrite($hash, '$?');
|
SimpleWrite($hash, '$?');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -264,7 +269,7 @@ sub read_OW {
|
|||||||
my $h = shift;
|
my $h = shift;
|
||||||
my $hash = $h->{h};
|
my $hash = $h->{h};
|
||||||
my $num = $h->{n};
|
my $num = $h->{n};
|
||||||
SimpleWrite($hash, '$'.$num);
|
SimpleWrite($hash, '$'.$num); # Antwort kommt via sub ReadFn
|
||||||
Log3($hash, 5, "$hash->{NAME}, read_OW : $num");
|
Log3($hash, 5, "$hash->{NAME}, read_OW : $num");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -279,6 +284,7 @@ sub SetFn {
|
|||||||
|
|
||||||
my $name = shift;
|
my $name = shift;
|
||||||
my $cmd = shift // '?';
|
my $cmd = shift // '?';
|
||||||
|
my $val = shift // .5;
|
||||||
|
|
||||||
if ($cmd eq 'reset') {
|
if ($cmd eq 'reset') {
|
||||||
DevIo_CloseDev($hash);
|
DevIo_CloseDev($hash);
|
||||||
@ -287,7 +293,12 @@ sub SetFn {
|
|||||||
|
|
||||||
return SimpleWrite($hash, '$rez') if ($cmd eq 'S0-reset');
|
return SimpleWrite($hash, '$rez') if ($cmd eq 'S0-reset');
|
||||||
|
|
||||||
return "Unknown argument $cmd, choose one of reset:noArg S0-reset:noArg";
|
if ($cmd eq 'delay') {
|
||||||
|
$hash->{DELAY} = $val;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'Unknown argument '.$cmd.', choose one of reset:noArg S0-reset:noArg delay';
|
||||||
}
|
}
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
@ -310,7 +321,7 @@ sub GetFn {
|
|||||||
return formatOWList(@devs);
|
return formatOWList(@devs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "$name get with unknown argument $cmd, choose one of OWdevicelist:noArg";
|
return 'Unknown argument '.$cmd.', choose one of OWdevicelist:noArg';
|
||||||
}
|
}
|
||||||
|
|
||||||
sub formatOWList {
|
sub formatOWList {
|
||||||
@ -477,7 +488,7 @@ sub Parse {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
InternalTimer(gettimeofday()+1+($num*0.5), "FHEM::OW2S0SMSGUARD::read_OW", {h=>$hash, n=>$num}, 0) if ($ok && ($model > 9)); # 10 - 28
|
InternalTimer(gettimeofday()+1+($num*$hash->{DELAY}), 'FHEM::OW2S0SMSGUARD::read_OW', {h=>$hash, n=>$num}, 0) if ($ok && ($model > 9)); # 10 - 28
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -572,7 +583,7 @@ sub ParseFn {
|
|||||||
my $ac = (IsDisabled('autocreate')) ? 'disabled' : 'enabled' ;
|
my $ac = (IsDisabled('autocreate')) ? 'disabled' : 'enabled' ;
|
||||||
Log3($shash, 3, "$shash->{NAME}, got message for undefined device [$arr[1]] type $arr[2] autocreate is $ac");
|
Log3($shash, 3, "$shash->{NAME}, got message for undefined device [$arr[1]] type $arr[2] autocreate is $ac");
|
||||||
return 'disable' if ($ac eq 'disabled');
|
return 'disable' if ($ac eq 'disabled');
|
||||||
return "UNDEFINED OW_$arr[1] OW2S0SMSGUARD $arr[1]";
|
return "UNDEFINED OW_$arr[1] OW2S0SMSGUARD $arr[1] 0 $arr[2]";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $dhash = $modules{OW2S0SMSGUARD}{defptr}{$arr[1]};
|
my $dhash = $modules{OW2S0SMSGUARD}{defptr}{$arr[1]};
|
||||||
@ -580,7 +591,7 @@ sub ParseFn {
|
|||||||
|
|
||||||
Log3($dname, 4, "$dname, ParseFn $msg");
|
Log3($dname, 4, "$dname, ParseFn $msg");
|
||||||
|
|
||||||
$dhash->{model} = $model;
|
#$dhash->{model} = $model;
|
||||||
$dhash->{busid} = $arr[4] //= -1;
|
$dhash->{busid} = $arr[4] //= -1;
|
||||||
|
|
||||||
readingsBeginUpdate($dhash);
|
readingsBeginUpdate($dhash);
|
||||||
@ -590,13 +601,21 @@ sub ParseFn {
|
|||||||
readingsBulkUpdate($dhash, 'state', "T: $val °C");
|
readingsBulkUpdate($dhash, 'state', "T: $val °C");
|
||||||
}
|
}
|
||||||
elsif ($model eq 'DS2401') {
|
elsif ($model eq 'DS2401') {
|
||||||
|
my $since = int(ReadingsNum($dname, '.last' , gettimeofday()));
|
||||||
|
my $now = int(gettimeofday());
|
||||||
|
if (ReadingsVal($dname, 'presence' ,'') ne $val) {
|
||||||
|
$since = ($now-$since);
|
||||||
|
# setReadingsVal($dhash, 'since', $since, TimeNow());
|
||||||
|
}
|
||||||
|
|
||||||
|
#readingsBulkUpdate($dhash, '.last' , $now) if (ReadingsVal($dname, 'presence' ,'') ne $val);
|
||||||
readingsBulkUpdate($dhash, 'state', $val);
|
readingsBulkUpdate($dhash, 'state', $val);
|
||||||
readingsBulkUpdate($dhash, 'presence', $val);
|
readingsBulkUpdate($dhash, 'presence', $val);
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsEndUpdate($dhash,1);
|
readingsEndUpdate($dhash,1);
|
||||||
|
|
||||||
CommandAttr(undef, "$dname model $model") if (!exists($attr{$dname}{model}));
|
#CommandAttr(undef, "$dname model $model") if (!exists($attr{$dname}{model}));
|
||||||
|
|
||||||
return $dname;
|
return $dname;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user