alarm handling added, check if ibutton devices are present added
git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@2478 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
@@ -39,9 +39,10 @@ OWServer_Initialize($)
|
|||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
|
|
||||||
# Provider
|
# Provider
|
||||||
$hash->{WriteFn}= "OWServer_Write";
|
$hash->{WriteFn} = "OWServer_Write";
|
||||||
$hash->{ReadFn} = "OWServer_Read";
|
$hash->{ReadFn} = "OWServer_Read";
|
||||||
$hash->{Clients}= ":OWDevice:";
|
$hash->{DirFn} = "OWServer_Dir";
|
||||||
|
$hash->{Clients} = ":OWDevice:";
|
||||||
|
|
||||||
# Consumer
|
# Consumer
|
||||||
$hash->{DefFn} = "OWServer_Define";
|
$hash->{DefFn} = "OWServer_Define";
|
||||||
@@ -165,6 +166,16 @@ OWServer_Write($@)
|
|||||||
return $hash->{fhem}{owserver}->write($path,$value);
|
return $hash->{fhem}{owserver}->write($path,$value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#####################################
|
||||||
|
sub
|
||||||
|
OWServer_Dir($@)
|
||||||
|
{
|
||||||
|
my ($hash,$path)= @_;
|
||||||
|
|
||||||
|
return undef unless(defined($hash->{fhem}{owserver}));
|
||||||
|
return $hash->{fhem}{owserver}->dir($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
sub
|
sub
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
# Todos:
|
# Todos:
|
||||||
# - stateFormat via Interface
|
# - stateFormat via Interface
|
||||||
# - warum wird jeder Wert 2x geloggt?
|
|
||||||
|
|
||||||
package main;
|
package main;
|
||||||
|
|
||||||
@@ -42,9 +41,9 @@ $owdevice{"01"} = {
|
|||||||
# DS1990A - Serial Number iButton
|
# DS1990A - Serial Number iButton
|
||||||
"read" => [],
|
"read" => [],
|
||||||
"write" => [],
|
"write" => [],
|
||||||
"poll" => [],
|
"poll" => [ qw(address) ],
|
||||||
"state" => [ qw(address) ],
|
"state" => [],
|
||||||
"interface" => "serial",
|
"interface" => "id",
|
||||||
};
|
};
|
||||||
$owdevice{"05"} = {
|
$owdevice{"05"} = {
|
||||||
# DS2405 - Addressable Switch
|
# DS2405 - Addressable Switch
|
||||||
@@ -290,6 +289,14 @@ $owdevice{"3B"} = {
|
|||||||
"alarm" => 1,
|
"alarm" => 1,
|
||||||
"interface" => "temperature",
|
"interface" => "temperature",
|
||||||
};
|
};
|
||||||
|
$owdevice{"81"} = {
|
||||||
|
# USB id - ID found in DS2490R and DS2490B USB adapters
|
||||||
|
"read" => [],
|
||||||
|
"write" => [],
|
||||||
|
"poll" => [ qw(address) ],
|
||||||
|
"state" => [],
|
||||||
|
"interface" => "id",
|
||||||
|
};
|
||||||
$owdevice{"FF"} = {
|
$owdevice{"FF"} = {
|
||||||
# LCD - LCD controller by Louis Swart
|
# LCD - LCD controller by Louis Swart
|
||||||
"read" => [ qw(counters.0 counters.1 counters.2 counters.3 counters.ALL),
|
"read" => [ qw(counters.0 counters.1 counters.2 counters.3 counters.ALL),
|
||||||
@@ -337,9 +344,10 @@ OWDevice_Initialize($)
|
|||||||
$hash->{GetFn} = "OWDevice_Get";
|
$hash->{GetFn} = "OWDevice_Get";
|
||||||
$hash->{SetFn} = "OWDevice_Set";
|
$hash->{SetFn} = "OWDevice_Set";
|
||||||
$hash->{DefFn} = "OWDevice_Define";
|
$hash->{DefFn} = "OWDevice_Define";
|
||||||
|
$hash->{UndefFn} = "OWDevice_Undef";
|
||||||
$hash->{AttrFn} = "OWDevice_Attr";
|
$hash->{AttrFn} = "OWDevice_Attr";
|
||||||
|
|
||||||
$hash->{AttrList} = "IODev trimvalues polls interfaces model loglevel:0,1,2,3,4,5 ".
|
$hash->{AttrList} = "trimvalues polls interfaces model loglevel:0,1,2,3,4,5 ".
|
||||||
$readingFnAttributes;
|
$readingFnAttributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,6 +358,7 @@ OWDevice_Initialize($)
|
|||||||
# 3rd element: array of setters/readings
|
# 3rd element: array of setters/readings
|
||||||
# 4th element: array of readings to be periodically updated
|
# 4th element: array of readings to be periodically updated
|
||||||
# 5th element: array of readings to be written to state
|
# 5th element: array of readings to be written to state
|
||||||
|
# 6th element: alerting device support
|
||||||
sub
|
sub
|
||||||
OWDevice_GetDetails($) {
|
OWDevice_GetDetails($) {
|
||||||
|
|
||||||
@@ -360,10 +369,11 @@ OWDevice_GetDetails($) {
|
|||||||
my @setters= @{$owdevice{$family}{"write"}};
|
my @setters= @{$owdevice{$family}{"write"}};
|
||||||
my @polls= @{$owdevice{$family}{"poll"}};
|
my @polls= @{$owdevice{$family}{"poll"}};
|
||||||
my @state= @{$owdevice{$family}{"state"}};
|
my @state= @{$owdevice{$family}{"state"}};
|
||||||
|
my $alerting= ($owdevice{$family}{"alarm"}) ? 1 : 0;
|
||||||
|
|
||||||
my $interface= $owdevice{$family}{"interface"};
|
my $interface= $owdevice{$family}{"interface"};
|
||||||
# http://perl-seiten.homepage.t-online.de/html/perl_array.html
|
# http://perl-seiten.homepage.t-online.de/html/perl_array.html
|
||||||
return ($interface, \@getters, \@setters, \@polls, \@state);
|
return ($interface, \@getters, \@setters, \@polls, \@state, $alerting);
|
||||||
}
|
}
|
||||||
|
|
||||||
###################################
|
###################################
|
||||||
@@ -371,9 +381,9 @@ OWDevice_GetDetails($) {
|
|||||||
# Read http://forum.fhem.de/index.php?t=tree&goto=54027&rid=10#msg_54027
|
# Read http://forum.fhem.de/index.php?t=tree&goto=54027&rid=10#msg_54027
|
||||||
# to find out why.
|
# to find out why.
|
||||||
sub
|
sub
|
||||||
OWDevice_ReadFromServer($@)
|
OWDevice_ReadFromServer($$@)
|
||||||
{
|
{
|
||||||
my ($hash, @a) = @_;
|
my ($hash,$cmd,@a) = @_;
|
||||||
|
|
||||||
my $dev = $hash->{NAME};
|
my $dev = $hash->{NAME};
|
||||||
return if(IsDummy($dev) || IsIgnored($dev));
|
return if(IsDummy($dev) || IsIgnored($dev));
|
||||||
@@ -387,7 +397,13 @@ OWDevice_ReadFromServer($@)
|
|||||||
}
|
}
|
||||||
|
|
||||||
no strict "refs";
|
no strict "refs";
|
||||||
my $ret = &{$modules{$iohash->{TYPE}}{ReadFn}}($iohash, @a);
|
my $ret;
|
||||||
|
if($cmd eq "read") {
|
||||||
|
$ret = &{$modules{$iohash->{TYPE}}{ReadFn}}($iohash, @a);
|
||||||
|
}
|
||||||
|
if($cmd eq "dir") {
|
||||||
|
$ret = &{$modules{$iohash->{TYPE}}{DirFn}}($iohash, @a);
|
||||||
|
}
|
||||||
use strict "refs";
|
use strict "refs";
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
@@ -399,13 +415,16 @@ OWDevice_ReadValue($$) {
|
|||||||
my ($hash,$reading)= @_;
|
my ($hash,$reading)= @_;
|
||||||
|
|
||||||
my $address= $hash->{fhem}{address};
|
my $address= $hash->{fhem}{address};
|
||||||
my $value= OWDevice_ReadFromServer($hash, "/$address/$reading");
|
my $interface= $hash->{fhem}{interfaces};
|
||||||
|
my $value= OWDevice_ReadFromServer($hash,"read","/$address/$reading");
|
||||||
#Debug "/$address/$reading => $value";
|
#Debug "/$address/$reading => $value";
|
||||||
|
if($interface ne "id") {
|
||||||
if(defined($value)) {
|
if(defined($value)) {
|
||||||
$value= trim($value) if(AttrVal($hash,"trimvalues",1));
|
$value= trim($value) if(AttrVal($hash,"trimvalues",1));
|
||||||
} else {
|
} else {
|
||||||
Log 3, $hash->{NAME} . ": reading $reading did not return a value";
|
Log 3, $hash->{NAME} . ": reading $reading did not return a value";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
@@ -429,7 +448,10 @@ OWDevice_UpdateValues($) {
|
|||||||
|
|
||||||
my @polls= @{$hash->{fhem}{polls}};
|
my @polls= @{$hash->{fhem}{polls}};
|
||||||
my @getters= @{$hash->{fhem}{getters}};
|
my @getters= @{$hash->{fhem}{getters}};
|
||||||
my @state= @{$hash->{fhem}{currentstate}};
|
my @state= @{$hash->{fhem}{state}};
|
||||||
|
my $alerting= $hash->{fhem}{alerting};
|
||||||
|
my $interface= $hash->{fhem}{interfaces};
|
||||||
|
my $state;
|
||||||
if($#polls>=0) {
|
if($#polls>=0) {
|
||||||
my $address= $hash->{fhem}{address};
|
my $address= $hash->{fhem}{address};
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
@@ -439,7 +461,7 @@ OWDevice_UpdateValues($) {
|
|||||||
readingsBulkUpdate($hash,$reading,$value);
|
readingsBulkUpdate($hash,$reading,$value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
my $state;
|
if(@state) {
|
||||||
foreach my $reading (@state) {
|
foreach my $reading (@state) {
|
||||||
my $value= OWDevice_ReadValue($hash,$reading);
|
my $value= OWDevice_ReadValue($hash,$reading);
|
||||||
if(defined($value)) {
|
if(defined($value)) {
|
||||||
@@ -448,6 +470,19 @@ OWDevice_UpdateValues($) {
|
|||||||
$state .= "$reading: n/a ";
|
$state .= "$reading: n/a ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if($alerting) {
|
||||||
|
my $dir= OWDevice_ReadFromServer($hash,"dir","/alarm/");
|
||||||
|
my $alarm= ($dir =~ m/$address/) ? 1 :0;
|
||||||
|
readingsBulkUpdate($hash,"alarm",$alarm);
|
||||||
|
$state .= "alarm: $alarm";
|
||||||
|
}
|
||||||
|
if($interface eq "id") {
|
||||||
|
my $dir= OWDevice_ReadFromServer($hash,"dir","/");
|
||||||
|
my $present= ($dir =~ m/$address/) ? 1 :0;
|
||||||
|
readingsBulkUpdate($hash,"present",$present);
|
||||||
|
$state .= "present: $present";
|
||||||
|
}
|
||||||
$state =~ s/\s+$//;
|
$state =~ s/\s+$//;
|
||||||
readingsBulkUpdate($hash,"state",$state);
|
readingsBulkUpdate($hash,"state",$state);
|
||||||
readingsEndUpdate($hash,1);
|
readingsEndUpdate($hash,1);
|
||||||
@@ -531,6 +566,18 @@ OWDevice_Set($@)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#############################
|
||||||
|
sub
|
||||||
|
OWDevice_Undef($$)
|
||||||
|
{
|
||||||
|
my ($hash, $name) = @_;
|
||||||
|
|
||||||
|
delete($modules{OWDevice}{defptr}{$hash->{NAME}});
|
||||||
|
RemoveInternalTimer($hash);
|
||||||
|
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
sub
|
sub
|
||||||
OWDevice_Define($$)
|
OWDevice_Define($$)
|
||||||
@@ -553,7 +600,7 @@ OWDevice_Define($$)
|
|||||||
$hash->{fhem}{interval}= $a[3];
|
$hash->{fhem}{interval}= $a[3];
|
||||||
Log 5, "$name: polling every $a[3] seconds";
|
Log 5, "$name: polling every $a[3] seconds";
|
||||||
}
|
}
|
||||||
my ($interface, $gettersref, $settersref, $pollsref, $stateref)= OWDevice_GetDetails($hash);
|
my ($interface, $gettersref, $settersref, $pollsref, $stateref, $alerting)= OWDevice_GetDetails($hash);
|
||||||
my @getters= @{$gettersref};
|
my @getters= @{$gettersref};
|
||||||
my @setters= @{$settersref};
|
my @setters= @{$settersref};
|
||||||
my @polls= @{$pollsref};
|
my @polls= @{$pollsref};
|
||||||
@@ -568,10 +615,21 @@ OWDevice_Define($$)
|
|||||||
Log 5, "$name: setters: " . join(" ", @setters);
|
Log 5, "$name: setters: " . join(" ", @setters);
|
||||||
$hash->{fhem}{polls}= $pollsref;
|
$hash->{fhem}{polls}= $pollsref;
|
||||||
Log 5, "$name: polls: " . join(" ", @polls);
|
Log 5, "$name: polls: " . join(" ", @polls);
|
||||||
$hash->{fhem}{currentstate}= $stateref;
|
$hash->{fhem}{state}= $stateref;
|
||||||
Log 5, "$name: state: " . join(" ", @state);
|
Log 5, "$name: state: " . join(" ", @state);
|
||||||
|
$hash->{fhem}{alerting}= $alerting;
|
||||||
|
Log 5, "$name: alerting: $alerting";
|
||||||
|
|
||||||
$attr{$name}{model}= OWDevice_ReadValue($hash, "type");
|
$attr{$name}{model}= OWDevice_ReadValue($hash, "type");
|
||||||
|
if($interface eq "id" && !defined($hash->{fhem}{interval})) {
|
||||||
|
my $value= OWDevice_Get($hash, "address");
|
||||||
|
my $dir= OWDevice_ReadFromServer($hash,"dir","/");
|
||||||
|
my $present= ($dir =~ m/$hash->{fhem}{address}/) ? 1 :0;
|
||||||
|
readingsBeginUpdate($hash);
|
||||||
|
readingsBulkUpdate($hash,"present",$present);
|
||||||
|
readingsBulkUpdate($hash,"state","present: $present");
|
||||||
|
readingsEndUpdate($hash,1);
|
||||||
|
}
|
||||||
OWDevice_UpdateValues($hash) if(defined($hash->{fhem}{interval}));
|
OWDevice_UpdateValues($hash) if(defined($hash->{fhem}{interval}));
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
@@ -705,14 +763,6 @@ OWDevice_Define($$)
|
|||||||
<a name="OWDeviceattr"></a>
|
<a name="OWDeviceattr"></a>
|
||||||
<b>Attributes</b>
|
<b>Attributes</b>
|
||||||
<ul>
|
<ul>
|
||||||
<a name="IODev"></a>
|
|
||||||
<li>IODev:
|
|
||||||
Set the OWServer device which should be used for sending and receiving data
|
|
||||||
for this OWDevice. Note: Upon startup fhem assigns each OWDevice
|
|
||||||
to the last previously defined OWServer. Thus it is best if you define OWServer
|
|
||||||
and OWDevices in blocks: first define the first OWServer and the OWDevices that
|
|
||||||
belong to it, then continue with the next OWServer and the attached OWDevices, and so on.
|
|
||||||
</li>
|
|
||||||
<li>trimvalues: removes leading and trailing whitespace from readings. Default is 1 (on).</li>
|
<li>trimvalues: removes leading and trailing whitespace from readings. Default is 1 (on).</li>
|
||||||
<li>polls: a comma-separated list of readings to poll. This supersedes the list of default readings to poll.</li>
|
<li>polls: a comma-separated list of readings to poll. This supersedes the list of default readings to poll.</li>
|
||||||
<li>interfaces: supersedes the interfaces exposed by that device.</li>
|
<li>interfaces: supersedes the interfaces exposed by that device.</li>
|
||||||
|
|||||||
Reference in New Issue
Block a user