88_xs1Dev: | 88_xs1Bridge: fix - No I/O device found

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@16394 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
HomeAuto_User 2018-03-12 23:09:47 +00:00
parent c18e5e9ee8
commit 899f88aea7
2 changed files with 48 additions and 39 deletions

View File

@ -4,7 +4,7 @@
# physisches Modul - Verbindung zur Hardware # physisches Modul - Verbindung zur Hardware
# #
# note / ToDo´s / Bugs: # note / ToDo´s / Bugs:
# # - Port Check
# #
# #
# #
@ -23,6 +23,7 @@ my $xs1_ConnectionTry = 1; # disable Funktion sobald 10x keine Verbindung (Schu
eval "use Encode qw(encode encode_utf8 decode_utf8);1" or $missingModul .= "Encode "; eval "use Encode qw(encode encode_utf8 decode_utf8);1" or $missingModul .= "Encode ";
eval "use JSON;1" or $missingModul .= "JSON "; eval "use JSON;1" or $missingModul .= "JSON ";
eval "use Net::Ping;1" or $missingModul .= "Net::Ping ";
#$| = 1; #Puffern abschalten, Hilfreich für PEARL WARNINGS Search #$| = 1; #Puffern abschalten, Hilfreich für PEARL WARNINGS Search
@ -61,8 +62,11 @@ sub xs1Bridge_Define($$) {
my $viewDeviceFunction = AttrVal($hash->{NAME},"view_Device_function",0); my $viewDeviceFunction = AttrVal($hash->{NAME},"view_Device_function",0);
my $update_only_difference = AttrVal($hash->{NAME},"update_only_difference",0); my $update_only_difference = AttrVal($hash->{NAME},"update_only_difference",0);
return "Usage: define <name> $name <ip>" if(@arg != 3); # 0 1 2
return "Usage: define <NAME> $name <IP>" if(@arg != 3);
#return "Usage: define <NAME> $name <IP> <PORT>" if(@arg != 4);
return "Your IP is not valid. Please Check!" if not($arg[2] =~ /[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}/s); return "Your IP is not valid. Please Check!" if not($arg[2] =~ /[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}/s);
#return "Your PORT is not valid. Please Check!" if not($arg[3] =~ /[0-9]{2,5}/s);
return "Cannot define xs1Bridge device. Perl modul ${missingModul}is missing." if ( $missingModul ); return "Cannot define xs1Bridge device. Perl modul ${missingModul}is missing." if ( $missingModul );
my $xs1check = 0; my $xs1check = 0;
@ -81,7 +85,7 @@ sub xs1Bridge_Define($$) {
$hash->{STATE} = "Initialized"; ## Der Status des Modules nach Initialisierung. $hash->{STATE} = "Initialized"; ## Der Status des Modules nach Initialisierung.
$hash->{TIME} = time(); ## Zeitstempel, derzeit vom anlegen des Moduls $hash->{TIME} = time(); ## Zeitstempel, derzeit vom anlegen des Moduls
$hash->{VERSION} = "1.15"; ## Version $hash->{VERSION} = "1.16"; ## Version
$hash->{BRIDGE} = 1; $hash->{BRIDGE} = 1;
# Attribut gesetzt # Attribut gesetzt
@ -139,17 +143,17 @@ sub xs1Bridge_Attr(@) {
readingsSingleUpdate($hash, "state", "active", 1); readingsSingleUpdate($hash, "state", "active", 1);
} }
}elsif ($attrName eq "view_Device_function") { }elsif ($attrName eq "view_Device_function") {
if ($attrValue eq "1") { ## Handling bei attribute disable 1 if ($attrValue eq "1") { ## Handling bei attribute view_Device_function 1
Log3 $name, 3, "$typ: Attribut view_Device_function $cmd to $attrValue"; Log3 $name, 3, "$typ: Attribut view_Device_function $cmd to $attrValue";
} }
elsif ($attrValue eq "0") { ## Handling bei attribute disable 0 elsif ($attrValue eq "0") { ## Handling bei attribute view_Device_function 0
Log3 $name, 3, "$typ: Attribut view_Device_function $cmd to $attrValue"; Log3 $name, 3, "$typ: Attribut view_Device_function $cmd to $attrValue";
} }
}elsif ($attrName eq "view_Device_name") { }elsif ($attrName eq "view_Device_name") {
if ($attrValue eq "1") { ## Handling bei attribute disable 1 if ($attrValue eq "1") { ## Handling bei attribute view_Device_name 1
Log3 $name, 3, "$typ: Attribut view_Device_name $cmd to $attrValue"; Log3 $name, 3, "$typ: Attribut view_Device_name $cmd to $attrValue";
} }
elsif ($attrValue eq "0") { ## Handling bei attribute disable 0 elsif ($attrValue eq "0") { ## Handling bei attribute view_Device_name 0
Log3 $name, 3, "$typ: Attribut view_Device_name $cmd to $attrValue"; Log3 $name, 3, "$typ: Attribut view_Device_name $cmd to $attrValue";
for my $i (0..64) { for my $i (0..64) {
delete $hash->{READINGS}{"Aktor_".sprintf("%02d", $i)."_name"} if($hash->{READINGS}); delete $hash->{READINGS}{"Aktor_".sprintf("%02d", $i)."_name"} if($hash->{READINGS});
@ -157,17 +161,17 @@ sub xs1Bridge_Attr(@) {
} }
} }
}elsif ($attrName eq "update_only_difference") { }elsif ($attrName eq "update_only_difference") {
if ($attrValue eq "1") { ## Handling bei attribute disable 1 if ($attrValue eq "1") { ## Handling bei attribute update_only_difference 1
Log3 $name, 3, "$typ: Attribut update_only_difference $cmd to $attrValue"; Log3 $name, 3, "$typ: Attribut update_only_difference $cmd to $attrValue";
} }
elsif ($attrValue eq "0") { ## Handling bei attribute disable 0 elsif ($attrValue eq "0") { ## Handling bei attribute update_only_difference 0
Log3 $name, 3, "$typ: Attribut update_only_difference $cmd to $attrValue"; Log3 $name, 3, "$typ: Attribut update_only_difference $cmd to $attrValue";
for my $i (0..64) { for my $i (0..64) {
delete $hash->{READINGS}{"Aktor_".sprintf("%02d", $i)."_name"} if($hash->{READINGS}); delete $hash->{READINGS}{"Aktor_".sprintf("%02d", $i)."_name"} if($hash->{READINGS});
} }
} }
}elsif ($attrName eq "xs1_control") { }elsif ($attrName eq "xs1_control") {
if ($attrValue eq "1") { ## Handling bei attribute disable 1 if ($attrValue eq "1") { ## Handling bei attribute xs1_control 1
if(! $modules{xs1Dev}) { ## Check Modul vorhanden if(! $modules{xs1Dev}) { ## Check Modul vorhanden
$attr{$name}{xs1_control} = "0"; $attr{$name}{xs1_control} = "0";
return "Module xs1Dev is non-existent or still under development. Please wait" return "Module xs1Dev is non-existent or still under development. Please wait"
@ -616,7 +620,7 @@ sub xs1Bridge_Undef($$)
<a name="xs1Bridge_define"></a> <a name="xs1Bridge_define"></a>
<b>Define</b><br> <b>Define</b><br>
<ul> <ul>
<code>define &lt;name&gt; xs1Bridge &lt;IP&gt; </code> <code>define &lt;NAME&gt; xs1Bridge &lt;IP&gt;</code>
<br><br> <br><br>
The module can not create without the IP of the xs1. If the IP can not be reached during module definition, the Define process is aborted. The module can not create without the IP of the xs1. If the IP can not be reached during module definition, the Define process is aborted.
@ -704,7 +708,7 @@ sub xs1Bridge_Undef($$)
<a name="xs1Bridge_define"></a> <a name="xs1Bridge_define"></a>
<b>Define</b><br> <b>Define</b><br>
<ul> <ul>
<code>define &lt;name&gt; xs1Bridge &lt;IP&gt; </code> <code>define &lt;NAME&gt; xs1Bridge &lt;IP&gt;</code>
<br><br> <br><br>
Ein anlegen des Modules ohne Angabe der IP vom xs1 ist nicht m&ouml;glich. Sollte die IP bei der Moduldefinierung nicht erreichbar sein, so bricht der Define Vorgang ab. Ein anlegen des Modules ohne Angabe der IP vom xs1 ist nicht m&ouml;glich. Sollte die IP bei der Moduldefinierung nicht erreichbar sein, so bricht der Define Vorgang ab.

View File

@ -8,7 +8,6 @@
# #
# #
# #
#
################################################################# #################################################################
package main; package main;
@ -44,8 +43,9 @@ sub xs1Dev_Define($$) {
my ($hash, $def) = @_; my ($hash, $def) = @_;
my @arg = split("[ \t][ \t]*", $def); my @arg = split("[ \t][ \t]*", $def);
# 0 1 2 3 # 0 1 2 3 4
return "Usage: define <NAME> xs1Dev <Typ> <ID> | wrong number of arguments" if( @arg != 4 ); return "Usage: define <NAME> xs1Dev <Typ> <ID> IODev= | wrong number of arguments" if( @arg != 5);
return "Usage: define <NAME> xs1Dev <Typ> <ID> IODev= | wrong IODev argument" if not ( $arg[4] =~ m/IODev=([^\s]*)[a-zA-Z0-9]/);
return "Usage: define <NAME> xs1Dev <Typ> <ID> | wrong ID, must be 1-64" if ( $arg[3] <1 || $arg[3] >64); return "Usage: define <NAME> xs1Dev <Typ> <ID> | wrong ID, must be 1-64" if ( $arg[3] <1 || $arg[3] >64);
return "Usage: define <NAME> xs1Dev <Typ> <ID> | wrong Typ, must be A or S" if ( $arg[2] ne "A" && $arg[2] ne "S"); return "Usage: define <NAME> xs1Dev <Typ> <ID> | wrong Typ, must be A or S" if ( $arg[2] ne "A" && $arg[2] ne "S");
@ -53,7 +53,7 @@ sub xs1Dev_Define($$) {
my $iodev; my $iodev;
my $i = 0; my $i = 0;
######## bisher unbenutzt - Schleife wo IODev= gefiltert wird aus define #### Schleife (Durchlauf der Argumente @arg) wo IODev= gefiltert wird aus define | Dispatch
foreach my $param ( @arg ) { foreach my $param ( @arg ) {
if( $param =~ m/IODev=([^\s]*)/ ) { if( $param =~ m/IODev=([^\s]*)/ ) {
$iodev = $1; $iodev = $1;
@ -62,12 +62,12 @@ sub xs1Dev_Define($$) {
} }
$i++; $i++;
} }
######################################################################## ###########################################################################################
my $name = $hash->{NAME}; ## Der Definitionsname, mit dem das Gerät angelegt wurde. my $name = $hash->{NAME}; ## Der Definitionsname, mit dem das Gerät angelegt wurde.
my $typ = $hash->{TYPE}; ## Der Modulname, mit welchem die Definition angelegt wurde. my $typ = $hash->{TYPE}; ## Der Modulname, mit welchem die Definition angelegt wurde.
#Log3 $name, 3, "$typ: Define arguments 0:$arg[0] | 1:$arg[1] | 2:$arg[2]"; #Log3 $name, 3, "$typ: Define arguments 0:$arg[0] | 1:$arg[1] | 2:$arg[2] | 3:$arg[3]";
# Parameter Define # Parameter Define
my $xs1_ID = $arg[2]; ## Zusatzparameter 1 bei Define - ggf. nur in Sub my $xs1_ID = $arg[2]; ## Zusatzparameter 1 bei Define - ggf. nur in Sub
@ -96,7 +96,7 @@ sub xs1Dev_Define($$) {
$hash->{STATE} = "Defined"; ## Der Status des Modules nach Initialisierung. $hash->{STATE} = "Defined"; ## Der Status des Modules nach Initialisierung.
$hash->{TIME} = time(); ## Zeitstempel, derzeit vom anlegen des Moduls $hash->{TIME} = time(); ## Zeitstempel, derzeit vom anlegen des Moduls
$hash->{VERSION} = "1.15"; ## Version $hash->{VERSION} = "1.16"; ## Version
$hash->{xs1_name} = "undefined"; ## Aktor | Sensor Name welcher def. im xs1 $hash->{xs1_name} = "undefined"; ## Aktor | Sensor Name welcher def. im xs1
$hash->{xs1_typ} = "undefined"; ## xs1_Typ switch | hygrometer | temperature ... $hash->{xs1_typ} = "undefined"; ## xs1_Typ switch | hygrometer | temperature ...
@ -111,11 +111,15 @@ sub xs1Dev_Define($$) {
# Attribut gesetzt # Attribut gesetzt
$attr{$name}{room} = "xs1" if( not defined( $attr{$name}{room} ) ); $attr{$name}{room} = "xs1" if( not defined( $attr{$name}{room} ) );
AssignIoPort($hash,$iodev) if( !$hash->{IODev} ); ## sucht nach einem passenden IO-Gerät (physikalische Definition) AssignIoPort($hash,$iodev) if( !$hash->{IODev} ); ## sucht nach einem passenden IO-Gerät (physikalische Definition)
# if(defined($hash->{IODev}->{NAME})) { if(defined($hash->{IODev}->{NAME})) {
#Log3 $name, 5, "xs1Dev: $name - I/O device is " . $hash->{IODev}->{NAME}; Log3 $name, 4, "xs1Dev: $name - I/O device is " . $hash->{IODev}->{NAME};
# } else { }
# GENERELL in FHEM auf LOG1 genommen von Rudi
# else {
# Log3 $name, 3, "xs1Dev: $name - no I/O device"; # Log3 $name, 3, "xs1Dev: $name - no I/O device";
# } # }
@ -291,18 +295,19 @@ sub xs1Dev_Parse($$) ## Input Data from 88_xs1Bridge
my $hash = $def; my $hash = $def;
$hash->{xs1_typ} = $xs1_typ2; $hash->{xs1_typ} = $xs1_typ2;
$hash->{xs1_name} = $xs1_name; $hash->{xs1_name} = $xs1_name;
my $IODev = $io_hash->{NAME};
my $name = $hash->{NAME}; ## xs1Dev_Aktor_01 my $name = $hash->{NAME}; ## xs1Dev_Aktor_01
my $typ = $hash->{TYPE}; ## xs1Dev my $typ = $hash->{TYPE}; ## xs1Dev
$typ = "xs1Dev" if (!$def); ## Erstanlegung $typ = "xs1Dev" if (!$def); ## Erstanlegung
###### Define and values update ###### ###### Define and values update ######
#Log3 $typ, 3, "$io_hash: Parse | Data: $xs1Dev | $xs1_readingsname | $xs1_ID | $xs1_typ2 | $xs1_value | $xs1_typ1" if (!$def); #Log3 $typ, 3, "$typ: Parse | Data: $xs1Dev | $xs1_readingsname | $xs1_ID | $xs1_typ2 | $xs1_value | $xs1_typ1 | $IODev" if (!$def);
if(!$def) { if(!$def) {
# "UNDEFINED xs1Dev_Aktor_12 xs1Dev A 12" # "UNDEFINED xs1Dev_Aktor_12 xs1Dev A 12"
Log3 $name, 3, "$typ: Unknown device ".$xs1Dev."_".$xs1_readingsname."_"."$xs1_ID $xs1_ID $xs1_typ1, please define it"; Log3 $name, 3, "$typ: Unknown device ".$xs1Dev."_".$xs1_readingsname."_"."$xs1_ID $xs1_ID $xs1_typ1 IODev=$IODev, please define it";
return "UNDEFINED xs1Dev"."_".$xs1_readingsname."_"."$xs1_ID xs1Dev $xs1_typ1 $xs1_ID"; return "UNDEFINED xs1Dev"."_".$xs1_readingsname."_"."$xs1_ID xs1Dev $xs1_typ1 $xs1_ID IODev=$IODev";
} else { } else {
#Log3 $name, 3, "$typ: device $xs1_readingsname"."_"."$xs1_ID xs1_value:$xs1_value xs1_typ2:$xs1_typ2"; #Log3 $name, 3, "$typ: device $xs1_readingsname"."_"."$xs1_ID xs1_value:$xs1_value xs1_typ2:$xs1_typ2";
@ -415,7 +420,7 @@ sub xs1Dev_Undef($$)
<a name="xs1Dev_define"></a> <a name="xs1Dev_define"></a>
<b>Define</b><br> <b>Define</b><br>
<ul> <ul>
<code>define &lt;name&gt; xs1Dev &lt;Typ&gt; &lt;ID&gt;</code> <code>define &lt;name&gt; xs1Dev &lt;Typ&gt; &lt;ID&gt; IODev=&lt;NAME&gt;</code>
<br><br> <br><br>
It is not possible to create the module without specifying type and ID of xs1. It is not possible to create the module without specifying type and ID of xs1.
@ -427,7 +432,7 @@ sub xs1Dev_Undef($$)
</ul><br> </ul><br>
example: example:
<ul> <ul>
define xs1Dev_Aktor_02 xs1Dev A 02 define xs1Dev_Aktor_02 xs1Dev A 02 IODev=ezControl
</ul> </ul>
</ul><br> </ul><br>
<b>Set</b> <b>Set</b>
@ -484,7 +489,7 @@ sub xs1Dev_Undef($$)
<a name="xs1Dev_define"></a> <a name="xs1Dev_define"></a>
<b>Define</b><br> <b>Define</b><br>
<ul> <ul>
<code>define &lt;name&gt; xs1Dev &lt;Typ&gt; &lt;ID&gt;</code> <code>define &lt;name&gt; xs1Dev &lt;Typ&gt; &lt;ID&gt; IODev=&lt;NAME&gt;</code>
<br><br> <br><br>
Ein anlegen des Modules ohne Angabe des Typ und der ID vom xs1 ist nicht möglich. Ein anlegen des Modules ohne Angabe des Typ und der ID vom xs1 ist nicht möglich.
@ -496,7 +501,7 @@ sub xs1Dev_Undef($$)
</ul><br> </ul><br>
Beispiel: Beispiel:
<ul> <ul>
define xs1Dev_Aktor_02 xs1Dev A 02 define xs1Dev_Aktor_02 xs1Dev A 02 IODev=ezControl
</ul> </ul>
</ul><br> </ul><br>
<b>Set</b> <b>Set</b>