logintypes from server, readings in commandref

This commit is contained in:
Manfred 2022-11-09 23:15:01 +01:00
parent eb8be5a37f
commit a2317d8b49
2 changed files with 34 additions and 3 deletions

View File

@ -300,6 +300,18 @@ sub Initialize {
</ul>
<a id="Matrix-readings"></a>
<h4>Readings</h4>
</ul>
<ul>
<li><b>device_id</b> - Geräte-ID unter der der MatrixBot registriert ist</li>
<li><b>event_id</b> - ID der letzten Nachricht</li>
<li><b>filter_id</b> - ID des Filters, der Voraussetzung für eine Longpoll-Verbindung zum Server ist</li>
<li><b>home_server</b> - Rückmeldung des Servers unter welchem Namen er erreichbar ist</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>question_id</b> - ID der letzten Frage</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>user_id</b> - Antwort des Servers welcher Account eingeloggt ist</li>
</ul>
=end html_DE
=cut

View File

@ -155,6 +155,9 @@ sub Get {
if ($cmd eq "wellknown") {
return PerformHttpRequest($hash, $cmd, '');
}
elsif ($cmd eq "logintypes") {
return PerformHttpRequest($hash, $cmd, '');
}
elsif ($cmd eq "sync") {
$data{MATRIX}{"$name"}{"FAILS"} = 0;
return PerformHttpRequest($hash, $cmd, '');
@ -163,7 +166,7 @@ sub Get {
return qq("get Matrix $cmd" needs a filter_id to request);
return PerformHttpRequest($hash, $cmd, $value);
}
return "Unknown argument $cmd, choose one of filter sync wellknown";
return "Unknown argument $cmd, choose one of logintypes filter sync wellknown";
}
sub Set {
@ -259,7 +262,9 @@ sub PerformHttpRequest($$$)
my $now = gettimeofday();
my $name = $hash->{NAME};
my $passwd = "";
$passwd = $hash->{helper}->{passwdobj}->getReadPassword($name) if ($def == "login" || $def == "reg2");
if ($def eq "login" || $def eq "reg2"){
$passwd = $hash->{helper}->{passwdobj}->getReadPassword($name) ;
}
#Log3($name, 5, "PerformHttpRequest - $name - $passwd");
@ -280,6 +285,10 @@ sub PerformHttpRequest($$$)
}
my $device_id = ReadingsVal($name, 'device_id', undef) ? ', "device_id":"'.ReadingsVal($name, 'device_id', undef).'"' : "";
if ($def eq "logintypes"){
$param->{'url'} = $hash->{server}."/_matrix/client/r0/login";
$param->{'method'} = 'GET';
}
if ($def eq "register"){
$param->{'url'} = $hash->{server}."/_matrix/client/v3/register";
$param->{'data'} = '{"type":"m.login.password", "identifier":{ "type":"m.id.user", "user":"'.$hash->{user}.'" }, "password":"'.$passwd.'"}';
@ -501,6 +510,16 @@ sub ParseHttpResponse($)
}
}
}
if ($def eq "logintypes"){
my $types = '';
foreach my $flow ( $decoded->{'flows'}->@* ) {
if ($flow->{'type'} =~ /m\.login\.(.*)/) {
#$types .= "$flow->{'type'} ";
$types .= "$1 ";# if ($flow->{'type'} );
}
}
readingsBulkUpdate($hash, "logintypes", $types);
}
if ($def eq "filter"){
readingsBulkUpdate($hash, "filter_id", $decoded->{'filter_id'}) if ($decoded->{'filter_id'});
}