mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@2686 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
8a01764589
commit
95050f45dd
132
FHEM/21_OWID.pm
132
FHEM/21_OWID.pm
@ -19,6 +19,8 @@
|
|||||||
# <ROM_ID> is a 12 character (6 byte) 1-Wire ROM ID
|
# <ROM_ID> is a 12 character (6 byte) 1-Wire ROM ID
|
||||||
# without Family ID, e.g. A2D90D000800
|
# without Family ID, e.g. A2D90D000800
|
||||||
#
|
#
|
||||||
|
# set <name> interval => set query interval for checking presence
|
||||||
|
#
|
||||||
# get <name> id => FAM_ID.ROM_ID.CRC
|
# get <name> id => FAM_ID.ROM_ID.CRC
|
||||||
# get <name> present => 1 if device present, 0 if not
|
# get <name> present => 1 if device present, 0 if not
|
||||||
#
|
#
|
||||||
@ -51,10 +53,15 @@ sub Log($$);
|
|||||||
#-- declare variables
|
#-- declare variables
|
||||||
my %gets = (
|
my %gets = (
|
||||||
"present" => "",
|
"present" => "",
|
||||||
|
"interval" => "",
|
||||||
"id" => ""
|
"id" => ""
|
||||||
);
|
);
|
||||||
my %sets = ();
|
my %sets = (
|
||||||
my %updates = ();
|
"interval" => ""
|
||||||
|
);
|
||||||
|
my %updates = (
|
||||||
|
"present" => ""
|
||||||
|
);
|
||||||
|
|
||||||
########################################################################################
|
########################################################################################
|
||||||
#
|
#
|
||||||
@ -76,8 +83,9 @@ sub OWID_Initialize ($) {
|
|||||||
$hash->{DefFn} = "OWID_Define";
|
$hash->{DefFn} = "OWID_Define";
|
||||||
$hash->{UndefFn} = "OWID_Undef";
|
$hash->{UndefFn} = "OWID_Undef";
|
||||||
$hash->{GetFn} = "OWID_Get";
|
$hash->{GetFn} = "OWID_Get";
|
||||||
$hash->{SetFn} = undef;
|
$hash->{SetFn} = "OWID_Set";
|
||||||
my $attlist = "IODev do_not_notify:0,1 showtime:0,1 model loglevel:0,1,2,3,4,5 ";
|
my $attlist = "IODev do_not_notify:0,1 showtime:0,1 model loglevel:0,1,2,3,4,5 ".
|
||||||
|
$readingFnAttributes;
|
||||||
$hash->{AttrList} = $attlist;
|
$hash->{AttrList} = $attlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,23 +103,26 @@ sub OWID_Define ($$) {
|
|||||||
#-- define <name> OWID <FAM_ID> <ROM_ID>
|
#-- define <name> OWID <FAM_ID> <ROM_ID>
|
||||||
my @a = split("[ \t][ \t]*", $def);
|
my @a = split("[ \t][ \t]*", $def);
|
||||||
|
|
||||||
my ($name,$fam,$id,$crc,$ret);
|
my ($name,$interval,$fam,$id,$crc,$ret);
|
||||||
|
|
||||||
#-- default
|
#-- default
|
||||||
$name = $a[0];
|
$name = $a[0];
|
||||||
|
$interval = 300;
|
||||||
$ret = "";
|
$ret = "";
|
||||||
|
|
||||||
#-- check syntax
|
#-- check syntax
|
||||||
return "OWID: Wrong syntax, must be define <name> OWID <fam> <id>"
|
return "OWID: Wrong syntax, must be define <name> OWID <fam> <id> [interval]"
|
||||||
if(int(@a) !=4 );
|
if(int(@a) !=4 );
|
||||||
|
|
||||||
#-- check id
|
#-- check id
|
||||||
if( ($a[2] =~ m/^[0-9|a-f|A-F]{2}$/) && ($a[3] =~ m/^[0-9|a-f|A-F]{12}$/)) {
|
if( ($a[2] =~ m/^[0-9|a-f|A-F]{2}$/) && ($a[3] =~ m/^[0-9|a-f|A-F]{12}$/)) {
|
||||||
$fam = $a[2];
|
$fam = $a[2];
|
||||||
$id = $a[3];
|
$id = $a[3];
|
||||||
|
if(int(@a)>=5) { $interval = $a[4]; }
|
||||||
} elsif( $a[2] =~ m/^0-9|a-f|A-F]{2}\.[0-9|a-f|A-F]{12}$/ ) {
|
} elsif( $a[2] =~ m/^0-9|a-f|A-F]{2}\.[0-9|a-f|A-F]{12}$/ ) {
|
||||||
$fam = substr($a[2],0,2);
|
$fam = substr($a[2],0,2);
|
||||||
$id = substr($a[2],3);
|
$id = substr($a[2],3);
|
||||||
|
if(int(@a)>=4) { $interval = $a[3]; }
|
||||||
} else {
|
} else {
|
||||||
return "OWID: $def is invalid, specify a 2 digit 12 digit or 2.12 digit value";
|
return "OWID: $def is invalid, specify a 2 digit 12 digit or 2.12 digit value";
|
||||||
}
|
}
|
||||||
@ -125,6 +136,7 @@ sub OWID_Define ($$) {
|
|||||||
$hash->{OW_ID} = $id;
|
$hash->{OW_ID} = $id;
|
||||||
$hash->{OW_FAMILY} = $fam;
|
$hash->{OW_FAMILY} = $fam;
|
||||||
$hash->{PRESENT} = 0;
|
$hash->{PRESENT} = 0;
|
||||||
|
$hash->{INTERVAL} = $interval;
|
||||||
|
|
||||||
#-- Couple to I/O device
|
#-- Couple to I/O device
|
||||||
AssignIoPort($hash);
|
AssignIoPort($hash);
|
||||||
@ -141,6 +153,10 @@ sub OWID_Define ($$) {
|
|||||||
|
|
||||||
#-- Initialization reading according to interface type
|
#-- Initialization reading according to interface type
|
||||||
my $interface= $hash->{IODev}->{TYPE};
|
my $interface= $hash->{IODev}->{TYPE};
|
||||||
|
|
||||||
|
#-- Start timer for updates
|
||||||
|
InternalTimer(time()+5+$hash->{INTERVAL}, "OWID_GetValues", $hash, 0);
|
||||||
|
|
||||||
#--
|
#--
|
||||||
readingsSingleUpdate($hash,"state","Initialized",1);
|
readingsSingleUpdate($hash,"state","Initialized",1);
|
||||||
return undef;
|
return undef;
|
||||||
@ -179,16 +195,103 @@ sub OWID_Get($@) {
|
|||||||
return "$name.id => $value";
|
return "$name.id => $value";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-- get interval
|
||||||
|
if($a[1] eq "interval") {
|
||||||
|
$value = $hash->{INTERVAL};
|
||||||
|
return "$name.interval => $value";
|
||||||
|
}
|
||||||
|
|
||||||
#-- get present
|
#-- get present
|
||||||
if($a[1] eq "present") {
|
if($a[1] eq "present") {
|
||||||
#-- hash of the busmaster
|
#-- hash of the busmaster
|
||||||
my $master = $hash->{IODev};
|
my $master = $hash->{IODev};
|
||||||
$value = OWX_Verify($master,$hash->{ROM_ID});
|
$value = OWX_Verify($master,$hash->{ROM_ID});
|
||||||
$hash->{PRESENT} = $value;
|
$hash->{PRESENT} = $value;
|
||||||
|
if( $value == 0 ){
|
||||||
|
readingsSingleUpdate($hash,"state","not present",1);
|
||||||
|
} else {
|
||||||
|
readingsSingleUpdate($hash,"state","present",1);
|
||||||
|
}
|
||||||
return "$name.present => $value";
|
return "$name.present => $value";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
########################################################################################
|
||||||
|
#
|
||||||
|
# OWID_GetValues - Updates the reading from one device
|
||||||
|
#
|
||||||
|
# Parameter hash = hash of device addressed
|
||||||
|
########################################################################################
|
||||||
|
|
||||||
|
sub OWID_GetValues($) {
|
||||||
|
my $hash = shift;
|
||||||
|
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
my $value = "";
|
||||||
|
my $ret = "";
|
||||||
|
my $offset;
|
||||||
|
my $factor;
|
||||||
|
|
||||||
|
#-- restart timer for updates
|
||||||
|
RemoveInternalTimer($hash);
|
||||||
|
InternalTimer(time()+$hash->{INTERVAL}, "OWID_GetValues", $hash, 1);
|
||||||
|
|
||||||
|
#-- hash of the busmaster
|
||||||
|
my $master = $hash->{IODev};
|
||||||
|
$value = OWX_Verify($master,$hash->{ROM_ID});
|
||||||
|
$hash->{PRESENT} = $value;
|
||||||
|
if( $value == 0 ){
|
||||||
|
readingsSingleUpdate($hash,"state","not present",1);
|
||||||
|
} else {
|
||||||
|
readingsSingleUpdate($hash,"state","present",1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#######################################################################################
|
||||||
|
#
|
||||||
|
# OWID_Set - Set one value for device
|
||||||
|
#
|
||||||
|
# Parameter hash = hash of device addressed
|
||||||
|
# a = argument array
|
||||||
|
#
|
||||||
|
########################################################################################
|
||||||
|
|
||||||
|
sub OWID_Set($@) {
|
||||||
|
my ($hash, @a) = @_;
|
||||||
|
|
||||||
|
my $key = $a[1];
|
||||||
|
my $value = $a[2];
|
||||||
|
|
||||||
|
#-- for the selector: which values are possible
|
||||||
|
if (@a == 2){
|
||||||
|
my $newkeys = join(" ", keys %sets);
|
||||||
|
return $newkeys ;
|
||||||
|
}
|
||||||
|
|
||||||
|
#-- check syntax
|
||||||
|
return "OWID: Set needs at least one parameter"
|
||||||
|
if( int(@a)<3 );
|
||||||
|
#-- check argument
|
||||||
|
if( !defined($sets{$a[1]}) ){
|
||||||
|
return "OWID: Set with unknown argument $a[1]";
|
||||||
|
}
|
||||||
|
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
#-- set new timer interval
|
||||||
|
if($key eq "interval") {
|
||||||
|
# check value
|
||||||
|
return "OWID: Set with short interval, must be > 1"
|
||||||
|
if(int($value) < 1);
|
||||||
|
# update timer
|
||||||
|
$hash->{INTERVAL} = $value;
|
||||||
|
RemoveInternalTimer($hash);
|
||||||
|
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "OWID_GetValues", $hash, 1);
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
########################################################################################
|
########################################################################################
|
||||||
#
|
#
|
||||||
# OWID_Undef - Implements UndefFn function
|
# OWID_Undef - Implements UndefFn function
|
||||||
@ -216,14 +319,14 @@ sub OWID_Undef ($) {
|
|||||||
Please define an <a href="#OWX">OWX</a> device or <a href="#OWServer">OWServer</a> device first. <br /></p>
|
Please define an <a href="#OWX">OWX</a> device or <a href="#OWServer">OWServer</a> device first. <br /></p>
|
||||||
<br /><h4>Example</h4><br />
|
<br /><h4>Example</h4><br />
|
||||||
<p>
|
<p>
|
||||||
<code>define ROM1 OWX_ID OWCOUNT 09.CE780F000000</code>
|
<code>define ROM1 OWX_ID OWCOUNT 09.CE780F000000 10</code>
|
||||||
<br />
|
<br />
|
||||||
</p><br />
|
</p><br />
|
||||||
<a name="OWIDdefine"></a>
|
<a name="OWIDdefine"></a>
|
||||||
<h4>Define</h4>
|
<h4>Define</h4>
|
||||||
<p>
|
<p>
|
||||||
<code>define <name> OWID <fam> <id> </code> or <br/>
|
<code>define <name> OWID <fam> <id> [<interval>]</code> or <br/>
|
||||||
<code>define <name> OWID <fam>.<id> </code>
|
<code>define <name> OWID <fam>.<id> [<interval>]</code>
|
||||||
<br /><br /> Define a 1-Wire device.<br /><br />
|
<br /><br /> Define a 1-Wire device.<br /><br />
|
||||||
</p>
|
</p>
|
||||||
<ul>
|
<ul>
|
||||||
@ -236,6 +339,17 @@ sub OWID_Undef ($) {
|
|||||||
<br />12-character unique ROM id of the converter device without family id and CRC
|
<br />12-character unique ROM id of the converter device without family id and CRC
|
||||||
code
|
code
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<code><interval></code>
|
||||||
|
<br />Interval in seconds for checking the presence of the device. The default is 300 seconds. </li>
|
||||||
|
</ul>
|
||||||
|
<br />
|
||||||
|
<a name="OWIDset"></a>
|
||||||
|
<h4>Set</h4>
|
||||||
|
<ul>
|
||||||
|
<li><a name="owid_interval">
|
||||||
|
<code>set <name> interval <int></code></a><br />
|
||||||
|
Interval in seconds for checking the presence of the device. The default is 300 seconds. </li>
|
||||||
</ul>
|
</ul>
|
||||||
<br />
|
<br />
|
||||||
<a name="OWIDget"></a>
|
<a name="OWIDget"></a>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user