2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-01 01:09:47 +00:00

26_tahoma.pm:2018-06-01 V 0219 new Attributes for time interval of getEvents, getStates and refreshAllStates

git-svn-id: https://svn.fhem.de/fhem/trunk@16805 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
mike3436 2018-06-01 22:08:40 +00:00
parent 72ff0c69d2
commit 95c2cb8ff1

View File

@ -51,6 +51,7 @@
# 2017-10-08 V 0216 group definition added
# 2018-05-10 V 0217 disable activated on devices
# 2018-05-25 V 0218 keepalive of http connection corrected
# 2018-06-01 V 0219 new Attributes for time interval of getEvents, getStates and refreshAllStates
package main;
@ -74,6 +75,8 @@ my $hash_;
sub tahoma_Initialize($)
{
my ($hash) = @_;
my $name = $hash->{NAME};
Log3 $name, 3, "$name: tahoma_Initialize";
$hash->{DefFn} = "tahoma_Define";
$hash->{NOTIFYDEV} = "global";
@ -87,6 +90,9 @@ sub tahoma_Initialize($)
"debug:1 ".
"disable:1 ".
"interval ".
"intervalRefresh ".
"intervalEvents ".
"intervalStates ".
"logfile ".
"url ".
"placeClasses ".
@ -120,10 +126,12 @@ my $groupId = 123001;
sub tahoma_Define($$)
{
my ($hash, $def) = @_;
my $name = $hash->{NAME};
Log3 $name, 3, "$name: tahoma_Define: def=$def";
my @a = split("[ \t][ \t]*", $def);
my $ModuleVersion = "0218";
my $ModuleVersion = "0219";
my $subtype;
my $name = $a[0];
@ -136,7 +144,7 @@ sub tahoma_Define($$)
$hash->{device} = $device;
$hash->{fid} = $fid;
$hash->{INTERVAL} = 0;
#$hash->{INTERVAL} = 0;
my $d = $modules{$hash->{TYPE}}{defptr}{"$fid"};
return "device $device already defined as $d->{NAME}" if( defined($d) && $d->{NAME} ne $name );
@ -152,13 +160,13 @@ sub tahoma_Define($$)
$hash->{oid} = $oid;
$hash->{fid} = $fid;
$hash->{INTERVAL} = 0;
#$hash->{INTERVAL} = 0;
my $d = $modules{$hash->{TYPE}}{defptr}{"$fid"};
return "place oid $oid already defined as $d->{NAME}" if( defined($d) && $d->{NAME} ne $name );
$modules{$hash->{TYPE}}{defptr}{"$fid"} = $hash;
} elsif( $a[2] eq "GROUP" && @a == 4 ) {
$subtype = "GROUP";
@ -169,7 +177,7 @@ sub tahoma_Define($$)
$hash->{oid} = $oid;
$hash->{fid} = $fid;
$hash->{INTERVAL} = 0;
#$hash->{INTERVAL} = 0;
my $d = $modules{$hash->{TYPE}}{defptr}{"$fid"};
return "group oid $oid already defined as $d->{NAME}" if( defined($d) && $d->{NAME} ne $name );
@ -185,7 +193,7 @@ sub tahoma_Define($$)
$hash->{oid} = $oid;
$hash->{fid} = $fid;
$hash->{INTERVAL} = 0;
#$hash->{INTERVAL} = 0;
my $d = $modules{$hash->{TYPE}}{defptr}{"$fid"};
return "scene oid $oid already defined as $d->{NAME}" if( defined($d) && $d->{NAME} ne $name );
@ -203,8 +211,10 @@ sub tahoma_Define($$)
$hash->{helper}{username} = $username;
$hash->{helper}{password} = $password;
$hash->{BLOCKING} = 0;
$hash->{INTERVAL} = 0;
$hash->{VERSION} = $ModuleVersion;
$hash->{getEventsInterval} = 2;
$hash->{refreshStatesInterval} = 120;
$hash->{getStatesInterval} = 0;
} else {
return "Usage: define <name> tahoma device\
@ -415,7 +425,7 @@ sub tahoma_readStatusTimer($)
RemoveInternalTimer($hash);
my ($seconds) = gettimeofday();
$hash->{refreshStateTimer} = $seconds + 10 if ( (!defined($hash->{refreshStateTimer})) || (!$hash->{logged_in}) );
$hash->{refreshStatesTimer} = $seconds + 10 if ( (!defined($hash->{refreshStatesTimer})) || (!$hash->{logged_in}) );
if( $hash->{request_active} ) {
Log3 $name, 3, "$name: request active";
@ -437,24 +447,31 @@ sub tahoma_readStatusTimer($)
$timeinfo = "tahoma_startup";
if ( $hash->{startup_done} ) {
tahoma_getStates($hash) ;
$hash->{refreshStateTimer} = $seconds + $hash->{INTERVAL};
$hash->{refreshStatesTimer} = $seconds + $hash->{refreshStatesInterval};
$timeinfo = "tahoma_getStates";
}
}
elsif( ($seconds < $hash->{refreshStateTimer}) || ($hash->{INTERVAL} <= 0) )
elsif( ($seconds >= $hash->{refreshStatesTimer}) && ($hash->{refreshStatesInterval} > 0) )
{
Log3 $name, 4, "$name: refreshing all states";
tahoma_refreshAllStates($hash);
$hash->{refreshStatesTimer} = $seconds + $hash->{refreshStatesInterval};
$timeinfo = "tahoma_refreshAllStates";
}
elsif( ($seconds >= $hash->{getStatesTimer}) && ($hash->{getStatesInterval} > 0) )
{
Log3 $name, 4, "$name: get all states";
tahoma_getStates($hash);
$hash->{getStatesTimer} = $seconds + $hash->{getStatesInterval};
$timeinfo = "tahoma_getStates";
}
elsif( ($seconds >= $hash->{getEventsTimer}) || ($hash->{getEventsInterval} <= 0) )
{
Log3 $name, 4, "$name: refreshing event";
tahoma_getEvents($hash);
$hash->{getEventsTimer} = $seconds + $hash->{getEventsInterval};
$timeinfo = "tahoma_getEvents";
}
else
{
Log3 $name, 4, "$name: refreshing state";
tahoma_refreshAllStates($hash);
tahoma_getStates($hash);
$hash->{refreshStateTimer} = $seconds + $hash->{INTERVAL};
$timeinfo = "tahoma_refreshAllStates tahoma_getStates";
}
my $timedelta = time -$timestart;
if ($timedelta > 0.5)
@ -476,7 +493,7 @@ sub tahoma_connect($)
tahoma_login($hash);
my ($seconds) = gettimeofday();
$hash->{refreshStateTimer} = $seconds + 10;
$hash->{refreshStatesTimer} = $seconds + 10;
tahoma_readStatusTimer($hash);
}
@ -1068,7 +1085,7 @@ sub tahoma_parseGetEvents($$)
{
my($hash, $json) = @_;
my $name = $hash->{NAME};
Log3 $name, 5, "$name: tahoma_parseGetEvent";
Log3 $name, 5, "$name: tahoma_parseGetEvents";
$hash->{refresh_event} = $json;
@ -1333,7 +1350,8 @@ sub tahoma_Get($$@)
if( $cmd eq "updateAll" ) {
my ($seconds) = gettimeofday();
$hash->{refreshStateTimer} = $seconds;
$hash = $hash->{IODev} if (defined ($hash->{IODev}));
$hash->{refreshStatesTimer} = $seconds;
return undef;
}
@ -1418,12 +1436,26 @@ sub tahoma_Set($$@)
}
if( $hash->{SUBTYPE} eq "ACCOUNT") {
$list = "cancel:noArg";
$list = "cancel:noArg reset:noArg refreshAllStates:noArg getStates:noArg";
if( $cmd eq "cancel" ) {
tahoma_cancelExecutions($hash);
return undef;
}
elsif( $cmd eq "reset" ) {
HttpUtils_Close($hash);
$hash->{logged_in} = undef;
$hash->{loginRetryTimer} = undef;
return undef;
}
elsif( $cmd eq "refreshAllStates" ) {
tahoma_refreshAllStates($hash);
return undef;
}
elsif( $cmd eq "getStates" ) {
tahoma_getStates($hash);
return undef;
}
}
return "Unknown argument $cmd, choose one of $list";
@ -1433,13 +1465,38 @@ sub tahoma_Attr($$$)
{
my ($cmd, $name, $attrName, $attrVal) = @_;
Log3 $name, 3, "$name: tahoma_Attr $cmd $attrName $attrVal";
my $orig = $attrVal;
if( $attrName eq "interval" ) {
my $hash = $defs{$name};
return "Attribut 'interval' only usable for type ACCOUNT" if $hash->{SUBTYPE} ne "ACCOUNT";
$attrVal = defined $attrVal ? int($attrVal) : 0;
$attrVal = int($attrVal);
$attrVal = 60*5 if ($attrVal < 60*5 && $attrVal != 0);
$hash->{INTERVAL} = $attrVal;
$attrVal = 120 if ($attrVal < 120 && $attrVal != 0);
$hash->{refreshStatesInterval} = $attrVal ? $attrVal / 2 : 120;
$hash->{getStatesInterval} = $attrVal;
} elsif( $attrName eq "intervalRefresh" ) {
my $hash = $defs{$name};
return "Attribut 'intervalRefresh' only usable for type ACCOUNT" if $hash->{SUBTYPE} ne "ACCOUNT";
$attrVal = defined $attrVal ? int($attrVal) : 120;
$attrVal = 60 if ($attrVal < 60 && $attrVal != 0);
$hash->{refreshStatesInterval} = $attrVal;
} elsif( $attrName eq "intervalStates" ) {
my $hash = $defs{$name};
return "Attribut 'intervalStates' only usable for type ACCOUNT" if $hash->{SUBTYPE} ne "ACCOUNT";
$attrVal = defined $attrVal ? int($attrVal) : 0;
$attrVal = int($attrVal);
$attrVal = 120 if ($attrVal < 120 && $attrVal != 0);
$hash->{getStatesInterval} = $attrVal;
} elsif( $attrName eq "intervalEvents" ) {
my $hash = $defs{$name};
return "Attribut 'intervalEvents' only usable for type ACCOUNT" if $hash->{SUBTYPE} ne "ACCOUNT";
$attrVal = defined $attrVal ? int($attrVal) : 2;
$attrVal = int($attrVal);
$attrVal = 2 if ($attrVal < 2 && $attrVal != 0);
$hash->{getEventsInterval} = $attrVal;
} elsif( $attrName eq "disable" ) {
my $hash = $defs{$name};
RemoveInternalTimer($hash);
@ -1449,13 +1506,19 @@ sub tahoma_Attr($$$)
}
} elsif( $attrName eq "blocking" ) {
my $hash = $defs{$name};
return "Attribut 'blocking' only usable for type ACCOUNT" if $hash->{SUBTYPE} ne "ACCOUNT";
$attrVal = defined $attrVal ? int($attrVal) : 0;
$hash->{BLOCKING} = $attrVal;
} elsif( $attrName eq "placeClasses" ) {
my $hash = $defs{$name};
$hash->{inClass} = $attrVal if $hash->{SUBTYPE} eq "PLACE";
return "Attribut 'placeClasses' only usable for type PLACE" if $hash->{SUBTYPE} ne "PLACE";
$attrVal = defined $attrVal ? $attrVal : 'RollerShutter';
$hash->{inClass} = $attrVal;
}
elsif ( $attrName eq "levelInvert" ) {
my $hash = $defs{$name};
return "Attribut 'placeClasses' only usable for type DEVICE" if $hash->{SUBTYPE} ne "DEVICE";
$attrVal = defined $attrVal ? int($attrVal) : 0;
my $device = tahoma_getDeviceDetail( $hash, $hash->{device} );
$device->{levelInvert} = $attrVal if (defined $device);
}
@ -1611,7 +1674,7 @@ sub tahoma_decrypt($)
<h3>tahoma</h3>
<ul>
The module realizes the communication with io-homecontrol&reg; Devices e.g. from Somfy&reg; or Velux&reg;<br>
A registered TaHoma&reg; Connect gateway from Overkiz&reg; sold by Somfy&reg; which is continously connected to the internet is necessary for the module.<br>
A registered TaHoma&reg; Connect gateway from Overkiz&reg; sold by Somfy&reg; which is continuously connected to the internet is necessary for the module.<br>
<br><br>
Notes:
@ -1632,9 +1695,9 @@ sub tahoma_decrypt($)
<br>
A definition is only necessary for a tahoma device:<br>
<code>define &lt;name&gt; tahoma ACCOUNT &lt;username&gt; &lt;password&gt;</code><br>
<b>If a tahoma device of the type ACCOUNT is created, all other devices acessable by the tahoma gateway are automaticaly created!</b><br>
<b>If a tahoma device of the type ACCOUNT is created, all other devices accessible by the tahoma gateway are automatically created!</b><br>
If the account is valid, the setup will be read from the server.<br>
All registrated devices are automatically created with name tahoma_12345 (device number 12345 is used from setup)<br>
All registered devices are automatically created with name tahoma_12345 (device number 12345 is used from setup)<br>
All defined rooms will be are automatically created.<br>
Also all defined scenes will be automatically created.<br>
Groups of devices can be manually added to send out one group command for all attached devices<br>
@ -1648,25 +1711,72 @@ sub tahoma_decrypt($)
<br>
<b>local Attributes for ACCOUNT:</b>
<ul>
Normally, the web commands will be send asynchron, and this can be forced to wait of the result by blocking=1<br>
<code>attr tahoma1 blocking 1</code><br>
Normally, the web commands will be send asynchronous, and this can be forced to wait of the result by blocking=1<br>
<code>attr tahoma1 blocking 1</code><br><br>
</ul>
<ul>
Normally, the login data is stored encrypted after the first start, but this functionality can be disabled by cryptLoginData=0<br>
<code>attr tahoma1 cryptLoginData 0</code><br>
<code>attr tahoma1 cryptLoginData 0</code><br><br>
</ul>
<ul>
The account can be completely disabled, so no communication to server is running:<br>
<code>attr tahoma1 disable 1</code><br><br>
</ul>
<ul>
The interval [seconds] for refreshing and fetching all states can be set:<br>
This is an old attribute, the default is 0 = off.<br>
<code>attr tahoma1 interval 300</code><br><br>
</ul>
<ul>
The interval [seconds] for refreshing states can be changed:<br>
The default is 120s, allowed minimum is 60s, 0 = off.<br>
This command actualizes the states of devices, which will be externally changed e.g. by controller.<br>
<code>attr tahoma1 intervalRefresh 120</code><br><br>
</ul>
<ul>
The interval [seconds] for fetching all states can be set:<br>
The default is 0 = off, allowed minimum is 120s.<br>
Normally this isn't necessary to set, because all states will be actualized by events.<br>
<code>attr tahoma1 intervalStates 300</code><br><br>
</ul>
<ul>
The interval [seconds] for fetching new events can be changed:<br>
The default is 2s, allowed minimum is 2s.<br>
<code>attr tahoma1 intervalEvents 300</code><br>
</ul>
<br>
<b>local Attributes for DEVICE:</b>
<ul>
If the closure value 0..100 should be 100..0, the level can be inverted:<br>
<code>attr tahoma_23234545 levelInvert 1</code><br>
<code>attr tahoma_23234545 levelInvert 1</code><br><br>
</ul>
<ul>
The device can be disabled:<br>
The device is disabled then for direct access and indirect access by GROUP and PLACE, but not by SCENE.<br>
<code>attr tahoma_23234545 disable 1</code><br>
</ul>
<br>
<b>local Attributes for PLACE:</b>
<ul>
The commands in a room will only affect the devices in the room with inClass=RollerShutter.<br>
This can be extend or changed by setting the placeClasses attribut:<br>
<code>attr tahoma_abc12345 placeClasses RollerShutter ExteriorScreen Window</code><br>
This can be extend or changed by setting the placeClasses attribute:<br>
<code>attr tahoma_abc12345 placeClasses RollerShutter ExteriorScreen Window</code><br><br>
</ul>
<ul>
The place and its sub places can be disabled:<br>
<code>attr tahoma_abc12345 disable 1</code><br>
</ul>
<br>
<b>local Attributes for SCENE:</b>
<ul>
The scene can be disabled:<br>
<code>attr tahoma_4ef30a23 disable 1</code><br>
</ul>
<br>
<b>local Attributes for GROUP:</b>
<ul>
The group can be disabled:<br>
<code>attr tahoma_group1 disable 1</code><br>
</ul>
<br>
<b>Examples:</b>