2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-06 12:18:46 +00:00

added autocreate, documentation for OWNet.pm corrected

git-svn-id: https://svn.fhem.de/fhem/trunk@2499 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
mfr69bs 2013-01-13 00:18:17 +00:00
parent bb6a0028d9
commit 974a151a62

View File

@ -189,7 +189,7 @@ OWServer_DoInit($)
my $name = $hash->{NAME}; my $name = $hash->{NAME};
$hash->{STATE} = "Initialized" if(!$hash->{STATE}); $hash->{STATE} = "Initialized" if(!$hash->{STATE});
OWServer_Autodiscovery($hash) if($init_done); OWServer_Autocreate($hash) if($init_done);
return undef; return undef;
} }
@ -224,47 +224,64 @@ OWServer_Dir($@)
} }
##################################### #####################################
# TODO: codereview - es war zu spät...
sub sub
OWServer_Autodiscovery($) OWServer_Autocreate($)
{ {
my ($hash)= @_; my ($hash)= @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
return undef;
foreach my $d (keys %defs) {
next if($defs{$d}{TYPE} ne "autocreate");
return undef if(AttrVal($defs{$d}{NAME},"disable",undef));
}
my $owserver= $hash->{fhem}{owserver}; my $owserver= $hash->{fhem}{owserver};
my @dir= split(",", $owserver->dir()); my @dir= split(",", $owserver->dir());
my @devices= grep { m/^\/[0-9a-f]{2}.[0-9a-f]{12}$/i } @dir; my @devices= grep { m/^\/[0-9a-f]{2}.[0-9a-f]{12}$/i } @dir;
my @defined = ();
foreach my $d (keys %defs) {
next if($defs{$d}{TYPE} ne "OWDevice");
if(defined($defs{$d}{fhem}) && defined($defs{$d}{fhem}{address})) {
push(@defined,$defs{$d}{fhem}{address});
}
}
for my $device (@devices) { for my $device (@devices) {
my $address= substr($device,1); my $address= substr($device,1);
my $family= substr($address,0,2); my $family= substr($address,0,2);
if(!defined($owfamily{$family})) { if(!defined($owfamily{$family})) {
Log 2, "$name: Autocreate: unknown familycode '$family' found. Please report this!";
next; next;
} else { } else {
my $type= $owserver->read($device . "/type"); my $type= $owserver->read($device . "/type");
if($type !~ m/$owfamily{$family}/) { if($type !~ m/$owfamily{$family}/) {
Log 2, "$name: Autodiscovery: type '$type' unknown"; Log 2, "$name: Autocreate: type '$type' not defined in familycode '$family'. Please report this!";
next; next;
} else { } else {
foreach my $d (keys %defs) { foreach my $d (keys %defs) {
next if($defs{$d}{TYPE} eq "OWDevice" && next if($defs{$d}{TYPE} ne "OWDevice");
defined($defs{$d}{fhem}) && if(defined($defs{$d}{fhem}) &&
defined($defs{$d}{fhem}{address}) && $defs{$d}{fhem}{address} eq $address); defined($defs{$d}{fhem}{address}) && $defs{$d}{fhem}{address} eq $address) {
my $id= substr($address,3); Log 5, "$name address '$address' already defined as '$defs{$d}{NAME}'";
my $devname= $type . "_" . $id;
if(defined($defs{$devname})) {
next; next;
} else { } else {
my $interval= ($family eq "81") ? "" : " 60"; my $id= substr($address,3);
my $define= "$devname OWDevice $address" . $interval; my $devname= $type . "_" . $id;
my $cmdret; if(defined($defs{$devname}) || grep {$_ eq $address} @defined) {
$cmdret= CommandDefine(undef,$define); next;
if($cmdret) {
Log 1, "$name: An error occurred while creating device for address '$address': $cmdret";
} else { } else {
$cmdret= CommandAttr(undef,"$devname room OWDevice"); Log 5, "$name create new device '$devname' for address '$address'";
my $interval= ($family eq "81") ? "" : " 60";
my $define= "$devname OWDevice $address" . $interval;
my $cmdret;
$cmdret= CommandDefine(undef,$define);
if($cmdret) {
Log 1, "$name: Autocreate: An error occurred while creating device for address '$address': $cmdret";
} else {
$cmdret= CommandAttr(undef,"$devname room OWDevice");
}
} }
} }
} }
@ -352,11 +369,12 @@ OWServer_Set($@)
format <hostname>:<port>. For details see format <hostname>:<port>. For details see
<a href="http://owfs.org/index.php?page=owserver_protocol">owserver documentation</a>. <a href="http://owfs.org/index.php?page=owserver_protocol">owserver documentation</a>.
<br><br> <br><br>
You need <a href="http://owfs.cvs.sourceforge.net/viewvc/owfs/owfs/module/ownet/perl5/OWNet/lib/OWNet.pm">OWNet.pm from owfs.org</a>. Just drop it into your <code>FHEM</code> You need <a href="http://owfs.cvs.sourceforge.net/viewvc/owfs/owfs/module/ownet/perl5/OWNet/lib/OWNet.pm">OWNet.pm from owfs.org</a>, which is normally deployed with FHEM. As at 2012-12-23 the OWNet module
folder alongside the <code>10_OWServer.pm</code> module. As at 2012-12-23 the OWNet module
on CPAN has an issue which renders it useless for remote connections. on CPAN has an issue which renders it useless for remote connections.
<br><br> <br><br>
The actual 1-wire devices are defined as <a href="#OWDevice">OWDevice</a> devices. The actual 1-wire devices are defined as <a href="#OWDevice">OWDevice</a> devices.
If <a href="#autocreate">autocreate</a> is enabled, all the devices found are created at
start of FHEM automatically.
<br><br> <br><br>
This module is completely unrelated to the 1-wire modules with names all in uppercase. This module is completely unrelated to the 1-wire modules with names all in uppercase.
<br><br> <br><br>