autologin when matrixPoll=1
poll changed from set to attr matrixPoll
This commit is contained in:
parent
2d020e92bd
commit
f7ba2f4755
@ -83,7 +83,7 @@ sub Initialize {
|
||||
<a id="Matrix-define"></a>
|
||||
<h4>Define</h4>
|
||||
<ul>
|
||||
<code>define <name> <server> <user></code>
|
||||
<code>define <name> <server> <user></code>
|
||||
<br><br>
|
||||
Example: <code>define matrix Matrix matrix.com fhem</code>
|
||||
<br><br>
|
||||
@ -104,31 +104,40 @@ sub Initialize {
|
||||
<ul>
|
||||
<a id="Matrix-set-password"></a>
|
||||
<li><i>password</i><br>
|
||||
Set the password to login</li>
|
||||
Set the password to login
|
||||
</li>
|
||||
<a id="Matrix-set-register"></a>
|
||||
<li><i>register</i><br>
|
||||
without function, do not use this</li>
|
||||
without function, do not use this
|
||||
</li>
|
||||
<a id="Matrix-set-login"></a>
|
||||
<li><i>login</i><br>
|
||||
Login to the Matrix-Server and sync endless if poll is set to "1"</li>
|
||||
Login to the Matrix-Server and sync endless if poll is set to "1"
|
||||
</li>
|
||||
<a id="Matrix-set-refresh"></a>
|
||||
<li><i>refresh</i><br>
|
||||
If logged in or in state "soft-logout" refresh gets a new access_token and syncs endless if poll is set to "1"</li>
|
||||
If logged in or in state "soft-logout" refresh gets a new access_token and syncs endless if poll is set to "1"
|
||||
</li>
|
||||
<a id="Matrix-set-filter"></a>
|
||||
<li><i>filter</i><br>
|
||||
A Filter must be set for syncing in long poll. This filter is in the moment experimentell and must be set manual to get the coresponding filterId</li>
|
||||
A Filter must be set for syncing in long poll. This filter is in the moment experimentell and must be set manual to get the coresponding filterId
|
||||
</li>
|
||||
<a id="Matrix-set-poll"></a>
|
||||
<li><i>poll</i><br>
|
||||
Defaults to "0": Set poll to "1" for starting the sync-loop</li>
|
||||
Defaults to "0": Set poll to "1" for starting the sync-loop
|
||||
</li>
|
||||
<a id="Matrix-set-pollFullstate"></a>
|
||||
<li><i>pollFullstate</i><br>
|
||||
Defaults to "0": Set pollFullstate to "1" for getting in the next sync a full state of all rooms</li>
|
||||
Defaults to "0": Set pollFullstate to "1" for getting in the next sync a full state of all rooms
|
||||
</li>
|
||||
<a id="Matrix-set-question"></a>
|
||||
<li><i>question</i><br>
|
||||
Start a question in the room from reading room. The first answer to the question is logged and ends the question.</li>
|
||||
Start a question in the room from reading room. The first answer to the question is logged and ends the question.
|
||||
</li>
|
||||
<a id="Matrix-set-questionEnd"></a>
|
||||
<li><i>questionEnd</i><br>
|
||||
Stop a question also it is not answered.</li>
|
||||
Stop a question also it is not answered.
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
<br>
|
||||
@ -151,32 +160,36 @@ sub Initialize {
|
||||
<br><br>
|
||||
Attributes:
|
||||
<ul>
|
||||
<a id="Matrix-attr-MatrixMessage"></a>
|
||||
<li><i>MatrixMessage</i> <room-id><br>
|
||||
<a id="Matrix-attr-matrixPoll"></a>
|
||||
<li><i>matrixPoll</i><br>
|
||||
1: Automatic login and endless sychonisation.
|
||||
</li>
|
||||
<a id="Matrix-attr-matrixMessage"></a>
|
||||
<li><i>matrixMessage</i> <room-id><br>
|
||||
Set the room-id to wich messagesare sent.
|
||||
</li>
|
||||
<a id="Matrix-attr-MatrixQuestion_"></a>
|
||||
<li><i>MatrixQuestion_[0..9]+</i> <question>:<answer 1>:<answer 2>:...<answer max. 20><br>
|
||||
Prepared questions.
|
||||
</li>
|
||||
<a id="Matrix-attr-MatrixQuestion__0-9__"></a>
|
||||
<li><i>MatrixQuestion_[0..9]+</i> <question>:<answer 1>:<answer 2>:...<answer max. 20><br>
|
||||
Prepared questions.
|
||||
</li>
|
||||
<a id="Matrix-attr-matrixAnswer_"></a>
|
||||
<li><i>matrixAnswer_[0..9]</i><br>
|
||||
<li><i>matrixAnswer_</i><br>
|
||||
Prepared commands.
|
||||
</li>
|
||||
<a id="Matrix-attr-matrixAnswer__0-9__"></a>
|
||||
<li><i>matrixAnswer_[0..9]</i><br>
|
||||
<li><i>matrixAnswer_[0-9]+</i><br>
|
||||
Prepared commands.
|
||||
</li>
|
||||
<a id="Matrix-attr-MatrixRoom"></a>
|
||||
<li><i>MatrixRoom</i> <room-id 1> <room-id 2> ...<br>
|
||||
<a id="Matrix-attr-matrixQuestion_"></a>
|
||||
<li><i>matrixQuestion_</i> <br>
|
||||
Prepared questions.
|
||||
</li>
|
||||
<a id="Matrix-attr-matrixQuestion__0-9__"></a>
|
||||
<li><i>matrixQuestion_[0..9]+</i> <question>:<answer 1>:<answer 2>:...<answer max. 20><br>
|
||||
Prepared questions.
|
||||
</li>
|
||||
<a id="Matrix-attr-matrixRoom"></a>
|
||||
<li><i>matrixRoom</i> <room-id 1> <room-id 2> ...<br>
|
||||
Set the room-id's from wich are messages received.
|
||||
</li>
|
||||
<a id="Matrix-attr-MatrixSender"></a>
|
||||
<li><i>MatrixSender</i> <code><user 1> <user 2> ...</code><br>
|
||||
<a id="Matrix-attr-matrixSender"></a>
|
||||
<li><i>matrixSender</i> <code><user 1> <user 2> ...</code><br>
|
||||
Set the user's from wich are messages received.<br><br>
|
||||
Example: <code>attr matrix MatrixSender @name:matrix.server @second.name:matrix.server</code><br>
|
||||
</li>
|
||||
@ -184,6 +197,23 @@ sub Initialize {
|
||||
</ul>
|
||||
<a id="Matrix-readings"></a>
|
||||
<h4>Readings</h4>
|
||||
<ul>
|
||||
<li><b>deviceId</b> - Geräte-ID unter der der MatrixBot registriert ist</li>
|
||||
<li><b>eventId</b> - ID der letzten Nachricht</li>
|
||||
<li><b>filterId</b> - ID des Filters, der Voraussetzung für eine Longpoll-Verbindung zum Server ist</li>
|
||||
<li><b>homeServer</b> - Rückmeldung des Servers unter welchem Namen er erreichbar ist</li>
|
||||
<li><b>httpStatus</b> - Statuscode der letzten Serverantwort</li>
|
||||
<li><b>lastLogin</b> - Statuscode und Zeit des letzten Logins</li>
|
||||
<li><b>lastRefresh</b> - Statuscode und Zeit des letzten erhaltenen Accesstokens</li>
|
||||
<li><b>logintypes</b> - unterstützte Login-Möglichkeiten des Servers. Zur Zeit ist "password" die einzige unterstützte Version</li>
|
||||
<li><b>message</b> - letzte empfangene Nachricht</li>
|
||||
<li><b>poll</b> - 0: kein Empfang, 1: Empfang eingeschaltet</li>
|
||||
<li><b>questionId</b> - ID der letzten Frage</li>
|
||||
<li><b>requestError</b> - Letzte Serveranfrage mit Fehlerantwort</li>
|
||||
<li><b>sender</b> - Sender der letzten Nachricht</li>
|
||||
<li><b>since</b> - Schlüssel vom Server bis zu welcher Nachricht der Empfang erfolgreich ist</li>
|
||||
<li><b>userId</b> - Antwort des Servers welcher Account eingeloggt ist</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
=end html
|
||||
@ -206,10 +236,10 @@ sub Initialize {
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="Matrix-set"></a>
|
||||
<a id="Matrix-set"></a>
|
||||
<h4>Set</h4>
|
||||
<ul>
|
||||
<code>set <name> <option> <wert></code>
|
||||
<code>set <name> <option> <value></code>
|
||||
<br><br>
|
||||
You can <i>set</i> any value to any of the following options.
|
||||
<br><br>
|
||||
@ -217,33 +247,42 @@ sub Initialize {
|
||||
<ul>
|
||||
<a id="Matrix-set-password"></a>
|
||||
<li><i>password</i><br>
|
||||
Setzt das Passwort zum Login</li>
|
||||
Setzt das Passwort zum Login
|
||||
</li>
|
||||
<a id="Matrix-set-register"></a>
|
||||
<li><i>register</i><br>
|
||||
noch ohne Funktion!</li>
|
||||
noch ohne Funktion!
|
||||
</li>
|
||||
<a id="Matrix-set-login"></a>
|
||||
<li><i>login</i><br>
|
||||
Login beim Matrix-Server und horche andauernd auf Nachrichten wenn poll auf "1" gesetzt ist</li>
|
||||
Login beim Matrix-Server und horche andauernd auf Nachrichten wenn poll auf "1" gesetzt ist
|
||||
</li>
|
||||
<a id="Matrix-set-refresh"></a>
|
||||
<li><i>refresh</i><br>
|
||||
Wenn eingeloggt oder im Zustand "soft-logout" erhält man mit refresh einen neuen access_token. Wenn poll auf "1" gesetzt ist läuft dann wieder der Empfang andauernd.</li>
|
||||
Wenn eingeloggt oder im Zustand "soft-logout" erhält man mit refresh einen neuen access_token. Wenn poll auf "1" gesetzt ist läuft dann wieder der Empfang andauernd.
|
||||
</li>
|
||||
<a id="Matrix-set-filter"></a>
|
||||
<li><i>filter</i><br>
|
||||
Ein Filter muss gesetzt sein um "Longpoll"-Anfragen an den Server schicken zu können. Der Filter muss hier einmalg gesetzt werden um vom Server eine Filter-ID zu erhalten.</li>
|
||||
Ein Filter muss gesetzt sein um "Longpoll"-Anfragen an den Server schicken zu können. Der Filter muss hier einmalg gesetzt werden um vom Server eine Filter-ID zu erhalten.
|
||||
</li>
|
||||
<a id="Matrix-set-poll"></a>
|
||||
<li><i>poll</i><br>
|
||||
Zunächst "0": Auf "1" startet die Empfangsschleife.</li>
|
||||
Zunächst "0": Auf "1" startet die Empfangsschleife.
|
||||
</li>
|
||||
<a id="Matrix-set-pollFullstate"></a>
|
||||
<li><i>pollFullstate</i><br>
|
||||
Standard ist "0": Wenn pollFullstate auf "1" gesetzt wird, werden beider nächsten Synchronisation alle Raumeigenschaften neu eingelesen.</li>
|
||||
Standard ist "0": Wenn pollFullstate auf "1" gesetzt wird, werden beider nächsten Synchronisation alle Raumeigenschaften neu eingelesen.
|
||||
</li>
|
||||
<a id="Matrix-set-question"></a>
|
||||
<li><i>question.start</i><br>
|
||||
<li><i>question</i><br>
|
||||
Frage in dem Raum des Attributs "MatrixMessage" stellen. Die erste Antwort steht im Reading "answer" und beendet die Frage.<br>
|
||||
Als Wert wird entweder die Nummer einer vorbereiteten Frage übergeben oder eine komplette Frage in der Form<br>
|
||||
<code>Frage:Antwort 1:Antwort 2:....:Antwort n</code></li>
|
||||
<code>Frage:Antwort 1:Antwort 2:....:Antwort n</code>
|
||||
</li>
|
||||
<a id="Matrix-set-questionEnd"></a>
|
||||
<li><i>questionEnd</i><br>
|
||||
Die gestartete Frage ohne Antwort beenden. Entweder wird ohne Parameter die aktuelle Frage beendet oder mit einer Nachrichten-ID eine "verwaiste" Frage.</li>
|
||||
Die gestartete Frage ohne Antwort beenden. Entweder wird ohne Parameter die aktuelle Frage beendet oder mit einer Nachrichten-ID eine "verwaiste" Frage.
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
<br>
|
||||
@ -266,8 +305,12 @@ sub Initialize {
|
||||
<br><br>
|
||||
Attributes:
|
||||
<ul>
|
||||
<a id="Matrix-attr-MatrixMessage"></a>
|
||||
<li><i>MatrixMessage</i> <room-id><br>
|
||||
<a id="Matrix-attr-matrixPoll"></a>
|
||||
<li><i>matrixPoll</i><br>
|
||||
1: Automatisches Login und dauerhafte Synchronisation. Ohne Attribut oder 0 stoppt die Synchronisation.
|
||||
</li>
|
||||
<a id="Matrix-attr-matrixMessage"></a>
|
||||
<li><i>matrixMessage</i> <room-id><br>
|
||||
Setzt die Raum-ID in die alle Nachrichten gesendet werden. Zur Zeit ist nur ein Raum möglich.
|
||||
</li>
|
||||
<a id="Matrix-attr-matrixAnswer_"></a>
|
||||
@ -278,24 +321,24 @@ sub Initialize {
|
||||
<li><i>matrixAnswer_[0-9]+</i><br>
|
||||
Antworten = Befehle ausführen ist noch nicht freigegeben
|
||||
</li>
|
||||
<a id="Matrix-attr-MatrixQuestion_"></a>
|
||||
<li><i>MatrixQuestion_</i> <br>
|
||||
<a id="Matrix-attr-matrixQuestion_"></a>
|
||||
<li><i>matrixQuestion_</i> <br>
|
||||
Vorbereitete Fragen, die mit set mt question.start 0..9 gestartet werden können. Es sind maximal 20 Antworten möglich.<br>
|
||||
Format der Fragen: <code>Frage:Antwort 1:Antwort 2:....:Antwort n</code>
|
||||
Eingabe in der Attribut-Liste: <code>[0-9]+ Frage:Antwort 1:Antwort 2:....:Antwort n</code>
|
||||
</li>
|
||||
<a id="Matrix-attr-MatrixQuestion__0-9__"></a>
|
||||
<li><i>MatrixQuestion_[0-9]+</i><br>
|
||||
<a id="Matrix-attr-matrixQuestion__0-9__"></a>
|
||||
<li><i>matrixQuestion_[0-9]+</i><br>
|
||||
Vorbereitete Fragen, die mit set mt question.start 0..9 gestartet werden können. Es sind maximal 20 Antworten möglich.<br>
|
||||
Format der Fragen: <code>Frage:Antwort 1:Antwort 2:....:Antwort n</code>
|
||||
Eingabe in der Attribut-Liste: <code>[0-9]+ Frage:Antwort 1:Antwort 2:....:Antwort n</code>
|
||||
</li>
|
||||
<a id="Matrix-attr-MatrixRoom"></a>
|
||||
<li><i>MatrixRoom</i> <room-id 1> <room-id 2> ...<br>
|
||||
<a id="Matrix-attr-matrixRoom"></a>
|
||||
<li><i>matrixRoom</i> <room-id 1> <room-id 2> ...<br>
|
||||
Alle Raum-ID's aus denen Nachrichten empfangen werden.
|
||||
</li>
|
||||
<a id="Matrix-attr-MatrixSender"></a>
|
||||
<li><i>MatrixSender</i> <code><user 1> <user 2> ...</code><br>
|
||||
<a id="Matrix-attr-matrixSender"></a>
|
||||
<li><i>matrixSender</i> <code><user 1> <user 2> ...</code><br>
|
||||
Alle Personen von denen Nachrichten empfangen werden.<br>
|
||||
Beispiel: <code>attr matrix MatrixSender @name:matrix.server @second.name:matrix.server</code><br>
|
||||
</li>
|
||||
|
@ -46,11 +46,11 @@ BEGIN {
|
||||
))
|
||||
};
|
||||
|
||||
my $Module_Version = '0.0.7';
|
||||
my $Module_Version = '0.0.8';
|
||||
my $language = 'EN';
|
||||
|
||||
sub Attr_List{
|
||||
return "matrixLogin:password matrixRoom matrixSender matrixMessage matrixQuestion_ matrixQuestion_[0-9]+ matrixAnswer_ matrixAnswer_[0-9]+ $readingFnAttributes";
|
||||
return "matrixLogin:password matrixRoom matrixPoll:0,1 matrixSender matrixMessage matrixQuestion_ matrixQuestion_[0-9]+ matrixAnswer_ matrixAnswer_[0-9]+ $readingFnAttributes";
|
||||
}
|
||||
|
||||
sub Define {
|
||||
@ -86,24 +86,19 @@ sub Undef {
|
||||
sub Startproc {
|
||||
my ($hash) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
Log3($name, 4, "$name : Matrix::Startproc $hash ".AttrVal($name,'matrixPoll','-1'));
|
||||
# Update necessary?
|
||||
Log3($name, 1, "$name: Start V".$hash->{ModuleVersion}." -> V".$Module_Version) if ($hash->{ModuleVersion});
|
||||
$hash->{ModuleVersion} = $Module_Version;
|
||||
$language = AttrVal('global','language','EN');
|
||||
$data{MATRIX}{"$name"}{"softfail"} = 1;
|
||||
Log3($name, 4, "$name : Matrix::Startproc $hash");
|
||||
Login($hash) if (ReadingsVal($name,'poll',0) == 1);
|
||||
Login($hash) if (AttrVal($name,'matrixPoll',0) == 1);
|
||||
}
|
||||
|
||||
sub Login {
|
||||
my $hash = @_;
|
||||
Log3("nn", 4, "nn : Matrix::Login $hash");
|
||||
if ($hash eq "1"){
|
||||
Log3("nn", 4, "nn : Matrix::Login $hash");
|
||||
} else {
|
||||
Log3($hash->{NAME}, 4, "$hash->{NAME} : Matrix::Login $hash");
|
||||
return PerformHttpRequest($hash, 'login', '');
|
||||
}
|
||||
my ($hash) = @_;
|
||||
Log3($hash->{NAME}, 4, "$hash->{NAME} : Matrix::Login $hash");
|
||||
return PerformHttpRequest($hash, 'login', '');
|
||||
}
|
||||
|
||||
##########################
|
||||
@ -124,7 +119,7 @@ sub Notify($$)
|
||||
foreach my $event (@{$events}) {
|
||||
$event = "" if(!defined($event));
|
||||
### Writing log entry
|
||||
Log3($name, 4, "$name : X_Notify $devName - $event");
|
||||
Log3($name, 4, "$name : Matrix::Notify $devName - $event");
|
||||
$language = AttrVal('global','language','EN') if ($event =~ /ATTR global language.*/);
|
||||
# Examples:
|
||||
# $event = "ATTR global language DE"
|
||||
@ -200,7 +195,7 @@ sub Set {
|
||||
if ($cmd eq "msg") {
|
||||
return PerformHttpRequest($hash, $cmd, $value);
|
||||
}
|
||||
elsif ($cmd eq "poll" || $cmd eq "pollFullstate") {
|
||||
elsif ($cmd eq "pollFullstate") {
|
||||
readingsSingleUpdate($hash, $cmd, $value, 1); # Readings erzeugen
|
||||
}
|
||||
elsif ($cmd eq "password") {
|
||||
@ -226,7 +221,7 @@ sub Set {
|
||||
return PerformHttpRequest($hash, $cmd, '');
|
||||
}
|
||||
else {
|
||||
return "Unknown argument $cmd, choose one of filter:noArg password question questionEnd poll:0,1 pollFullstate:0,1 msg register login:noArg refresh:noArg";
|
||||
return "Unknown argument $cmd, choose one of filter:noArg password question questionEnd pollFullstate:0,1 msg register login:noArg refresh:noArg";
|
||||
}
|
||||
|
||||
#return "$opt set to $value. Try to get it.";
|
||||
@ -605,35 +600,36 @@ sub ParseHttpResponse($)
|
||||
|
||||
# PerformHttpRequest or InternalTimer if FAIL >= 3
|
||||
Log3($name, 4, "$name : Matrix::ParseHttpResponse $hash");
|
||||
if ($nextRequest ne "" && ReadingsVal($name,'poll',0) == 1 && $data{MATRIX}{"$name"}{"softfail"} < 3) {
|
||||
if ($nextRequest eq "sync" && $data{MATRIX}{"$name"}{"repeat"}){
|
||||
$def = $data{MATRIX}{"$name"}{"repeat"}->{"def"};
|
||||
$value = $data{MATRIX}{"$name"}{"repeat"}->{"value"};
|
||||
$data{MATRIX}{"$name"}{"repeat"} = undef;
|
||||
PerformHttpRequest($hash, $def, $value);
|
||||
if (AttrVal($name,'matrixPoll',0) == 1){
|
||||
if ($nextRequest ne "" && $data{MATRIX}{"$name"}{"softfail"} < 3) {
|
||||
if ($nextRequest eq "sync" && $data{MATRIX}{"$name"}{"repeat"}){
|
||||
$def = $data{MATRIX}{"$name"}{"repeat"}->{"def"};
|
||||
$value = $data{MATRIX}{"$name"}{"repeat"}->{"value"};
|
||||
$data{MATRIX}{"$name"}{"repeat"} = undef;
|
||||
PerformHttpRequest($hash, $def, $value);
|
||||
} else {
|
||||
PerformHttpRequest($hash, $nextRequest, '');
|
||||
}
|
||||
} else {
|
||||
PerformHttpRequest($hash, $nextRequest, '');
|
||||
}
|
||||
} else {
|
||||
my $pauseLogin;
|
||||
if ($data{MATRIX}{"$name"}{"hardfail"} >= 3){
|
||||
$pauseLogin = 300;
|
||||
} elsif ($data{MATRIX}{"$name"}{"softfail"} >= 3){
|
||||
$pauseLogin = 30;
|
||||
} elsif ($data{MATRIX}{"$name"}{"softfail"} > 0){
|
||||
$pauseLogin = 10;
|
||||
} else {
|
||||
$pauseLogin = 0;
|
||||
}
|
||||
if ($pauseLogin > 0){
|
||||
my $timeToStart = gettimeofday() + $pauseLogin;
|
||||
RemoveInternalTimer($hash->{myTimer}) if($hash->{myTimer});
|
||||
$hash->{myTimer} = { hash=>$hash };
|
||||
InternalTimer($timeToStart, \&FHEM::Devices::Matrix::Login, $hash->{myTimer});
|
||||
} else {
|
||||
Login($hash);
|
||||
my $pauseLogin;
|
||||
if ($data{MATRIX}{"$name"}{"hardfail"} >= 3){
|
||||
$pauseLogin = 300;
|
||||
} elsif ($data{MATRIX}{"$name"}{"softfail"} >= 3){
|
||||
$pauseLogin = 30;
|
||||
} elsif ($data{MATRIX}{"$name"}{"softfail"} > 0){
|
||||
$pauseLogin = 10;
|
||||
} else {
|
||||
$pauseLogin = 0;
|
||||
}
|
||||
if ($pauseLogin > 0){
|
||||
my $timeToStart = gettimeofday() + $pauseLogin;
|
||||
RemoveInternalTimer($hash->{myTimer}) if($hash->{myTimer});
|
||||
$hash->{myTimer} = { hash=>$hash };
|
||||
InternalTimer($timeToStart, \&FHEM::Devices::Matrix::Login, $hash->{myTimer});
|
||||
} else {
|
||||
Login($hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Damit ist die Abfrage zuende.
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user