package und device_id
zusätzlich einige Kleinigkeiten bereinigt, question mit zusätzlichem Testfür andere Clients außer Element.
This commit is contained in:
parent
b4b84ebe99
commit
c9879d14be
@ -30,7 +30,7 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
use HttpUtils;
|
use HttpUtils;
|
||||||
use FHEM::Meta;
|
use FHEM::Meta;
|
||||||
use GPUtils qw(GP_Export GP_Import);
|
use GPUtils qw(GP_Export);
|
||||||
|
|
||||||
use JSON;
|
use JSON;
|
||||||
require FHEM::Devices::Matrix::Matrix;
|
require FHEM::Devices::Matrix::Matrix;
|
||||||
@ -42,26 +42,22 @@ BEGIN {
|
|||||||
GP_Export(qw(
|
GP_Export(qw(
|
||||||
Initialize
|
Initialize
|
||||||
));
|
));
|
||||||
GP_Import(qw(
|
|
||||||
readingFnAttributes
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub Initialize {
|
sub Initialize {
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
|
|
||||||
$hash->{DefFn} = \&FHEM::Matrix::Define;
|
$hash->{DefFn} = \&FHEM::Devices::Matrix::Define;
|
||||||
$hash->{UndefFn} = \&FHEM::Matrix::Undef;
|
$hash->{UndefFn} = \&FHEM::Devices::Matrix::Undef;
|
||||||
$hash->{SetFn} = \&FHEM::Matrix::Set;
|
$hash->{Delete} = \&FHEM::Devices::Matrix::Delete;
|
||||||
$hash->{GetFn} = \&FHEM::Matrix::Get;
|
$hash->{SetFn} = \&FHEM::Devices::Matrix::Set;
|
||||||
$hash->{AttrFn} = \&FHEM::Matrix::Attr;
|
$hash->{GetFn} = \&FHEM::Devices::Matrix::Get;
|
||||||
$hash->{ReadFn} = \&FHEM::Matrix::Read;
|
$hash->{AttrFn} = \&FHEM::Devices::Matrix::Attr;
|
||||||
$hash->{RenameFn} = \&FHEM::Matrix::Rename;
|
$hash->{ReadFn} = \&FHEM::Devices::Matrix::Read;
|
||||||
$hash->{NotifyFn} = \&FHEM::Matrix::Notify;
|
$hash->{RenameFn} = \&FHEM::Devices::Matrix::Rename;
|
||||||
|
$hash->{NotifyFn} = \&FHEM::Devices::Matrix::Notify;
|
||||||
|
|
||||||
#$hash->{AttrList} = $FHEM::Devices::Matrix::attr_list;
|
$hash->{AttrList} = FHEM::Devices::Matrix::Attr_List();
|
||||||
$hash->{AttrList} = Attr_List();
|
|
||||||
#$hash->{parseParams} = 1;
|
|
||||||
return FHEM::Meta::InitMod( __FILE__, $hash );
|
return FHEM::Meta::InitMod( __FILE__, $hash );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,12 +12,13 @@
|
|||||||
#package FHEM::Devices::Matrix;
|
#package FHEM::Devices::Matrix;
|
||||||
#(Man-Fred) geh ich Recht in der Annahme, dass hier das gleiche package hin gehört
|
#(Man-Fred) geh ich Recht in der Annahme, dass hier das gleiche package hin gehört
|
||||||
# wie im Modul 98_Matrix?
|
# wie im Modul 98_Matrix?
|
||||||
package FHEM::Matrix;
|
package FHEM::Devices::Matrix;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use HttpUtils;
|
use HttpUtils;
|
||||||
use JSON;
|
use JSON;
|
||||||
|
use GPUtils qw(GP_Import);
|
||||||
use FHEM::Core::Authentication::Passwords qw(:ALL);
|
use FHEM::Core::Authentication::Passwords qw(:ALL);
|
||||||
|
|
||||||
use experimental qw /switch/; #(CoolTux) - als Ersatz für endlos lange elsif Abfragen
|
use experimental qw /switch/; #(CoolTux) - als Ersatz für endlos lange elsif Abfragen
|
||||||
@ -25,6 +26,7 @@ use experimental qw /switch/; #(CoolTux) - als Ersatz für endlos lange elsif A
|
|||||||
BEGIN {
|
BEGIN {
|
||||||
|
|
||||||
GP_Import(qw(
|
GP_Import(qw(
|
||||||
|
readingFnAttributes
|
||||||
readingsBeginUpdate
|
readingsBeginUpdate
|
||||||
readingsBulkUpdate
|
readingsBulkUpdate
|
||||||
readingsEndUpdate
|
readingsEndUpdate
|
||||||
@ -38,7 +40,6 @@ BEGIN {
|
|||||||
ReadingsVal
|
ReadingsVal
|
||||||
HttpUtils_NonblockingGet
|
HttpUtils_NonblockingGet
|
||||||
InternalTimer
|
InternalTimer
|
||||||
data
|
|
||||||
gettimeofday
|
gettimeofday
|
||||||
fhem
|
fhem
|
||||||
))
|
))
|
||||||
@ -82,13 +83,20 @@ sub Define {
|
|||||||
|
|
||||||
sub Undef {
|
sub Undef {
|
||||||
my $hash = shift;
|
my $hash = shift;
|
||||||
my $arg = shift;
|
my $name = shift;
|
||||||
|
|
||||||
my $name = $hash->{NAME};
|
#my $name = $hash->{NAME};
|
||||||
# undef $data
|
|
||||||
# $data{MATRIX}{"$name"} = undef; #(CoolTux) Bin mir gerade nicht sicher woher das $data kommt
|
# $data{MATRIX}{"$name"} = undef; #(CoolTux) Bin mir gerade nicht sicher woher das $data kommt
|
||||||
# meinst Du das %data aus main? Das ist für User. Wenn Du als Modulentwickler
|
# meinst Du das %data aus main? Das ist für User. Wenn Du als Modulentwickler
|
||||||
# etwas zwischenspeichern möchtest dann in $hash->{helper}
|
# etwas zwischenspeichern möchtest dann in $hash->{helper}
|
||||||
|
RemoveInternalTimer($hash->{myTimer}) if($hash->{myTimer});
|
||||||
|
$hash->{myTimer} = undef;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub Delete {
|
||||||
|
my $hash = shift;
|
||||||
|
my $name = shift;
|
||||||
|
|
||||||
$hash->{helper}->{passwdobj}->setDeletePassword($name); #(CoolTux) das ist nicht nötig,
|
$hash->{helper}->{passwdobj}->setDeletePassword($name); #(CoolTux) das ist nicht nötig,
|
||||||
# du löschst jedesmal den Eintrag wenn FHEM beendet wird.
|
# du löschst jedesmal den Eintrag wenn FHEM beendet wird.
|
||||||
@ -184,9 +192,9 @@ sub Rename {
|
|||||||
|
|
||||||
my ($passResp,$passErr);
|
my ($passResp,$passErr);
|
||||||
|
|
||||||
$data{MATRIX}{"$new"} = $data{MATRIX}{"$old"};
|
#$data{MATRIX}{"$new"} = $data{MATRIX}{"$old"};
|
||||||
|
|
||||||
$data{MATRIX}{"$old"} = undef; #(CoolTux) Wenn ein Hash nicht mehr benötigt wird dann delete
|
#$data{MATRIX}{"$old"} = undef; #(CoolTux) Wenn ein Hash nicht mehr benötigt wird dann delete
|
||||||
# Fehler in der nächsten Zeile:
|
# Fehler in der nächsten Zeile:
|
||||||
# delete argument is not a HASH or ARRAY element or slice at lib/FHEM/Devices/Matrix/Matrix.pm line 197.
|
# delete argument is not a HASH or ARRAY element or slice at lib/FHEM/Devices/Matrix/Matrix.pm line 197.
|
||||||
# delete $data{MATRIX}{"$old"}
|
# delete $data{MATRIX}{"$old"}
|
||||||
@ -210,10 +218,14 @@ sub I18N {
|
|||||||
|
|
||||||
my $def = {
|
my $def = {
|
||||||
'EN' => {
|
'EN' => {
|
||||||
'require2' => 'requires 2 arguments'
|
'require2' => 'requires 2 arguments',
|
||||||
|
'beginWithNumber' => 'must begin with a number',
|
||||||
|
'question' => 'a new question'
|
||||||
},
|
},
|
||||||
'DE' => {
|
'DE' => {
|
||||||
'require2' => 'benötigt 2 Argumente'
|
'require2' => 'benötigt 2 Argumente',
|
||||||
|
'beginWithNumber' => 'muss mit einer Ziffer beginnen',
|
||||||
|
'question' => 'Eine neue Frage'
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
my $result = $def->{$language}->{$value};
|
my $result = $def->{$language}->{$value};
|
||||||
@ -257,45 +269,6 @@ sub Get {
|
|||||||
sub Set {
|
sub Set {
|
||||||
my ( $hash, $name, $cmd, @args ) = @_;
|
my ( $hash, $name, $cmd, @args ) = @_;
|
||||||
my $value = join(" ", @args);
|
my $value = join(" ", @args);
|
||||||
#$opt = '?' if (!$opt);
|
|
||||||
|
|
||||||
#Log3($name, 5, "Set $hash->{NAME}: $name - $cmd - $value");
|
|
||||||
#return "set $name needs at least one argument" if (int(@$param) < 3);
|
|
||||||
|
|
||||||
#(CoolTux) Eine endlos Lange elsif Schlange ist nicht zu empfehlen, besser mit switch arbeiten
|
|
||||||
# Im Modulkopf use experimental qw /switch/; verwenden
|
|
||||||
|
|
||||||
# if ($cmd eq "msg") {
|
|
||||||
# return PerformHttpRequest($hash, $cmd, $value);
|
|
||||||
# }
|
|
||||||
# elsif ($cmd eq "pollFullstate") {
|
|
||||||
# readingsSingleUpdate($hash, $cmd, $value, 1); # Readings erzeugen
|
|
||||||
# }
|
|
||||||
# elsif ($cmd eq "password") {
|
|
||||||
# my ($erg,$err) = $hash->{helper}->{passwdobj}->setStorePassword($name,$value);
|
|
||||||
# return undef;
|
|
||||||
# }
|
|
||||||
# elsif ($cmd eq "filter") {
|
|
||||||
# return PerformHttpRequest($hash, $cmd, '');
|
|
||||||
# }
|
|
||||||
# elsif ($cmd eq "question") {
|
|
||||||
# return PerformHttpRequest($hash, $cmd, $value);
|
|
||||||
# }
|
|
||||||
# elsif ($cmd eq "questionEnd") {
|
|
||||||
# return PerformHttpRequest($hash, $cmd, $value);
|
|
||||||
# }
|
|
||||||
# elsif ($cmd eq "register") {
|
|
||||||
# return PerformHttpRequest($hash, $cmd, ''); # 2 steps (ToDo: 3 steps empty -> dummy -> registration_token o.a.)
|
|
||||||
# }
|
|
||||||
# elsif ($cmd eq "login") {
|
|
||||||
# return PerformHttpRequest($hash, $cmd, '');
|
|
||||||
# }
|
|
||||||
# elsif ($cmd eq "refresh") {
|
|
||||||
# return PerformHttpRequest($hash, $cmd, '');
|
|
||||||
# }
|
|
||||||
# else {
|
|
||||||
# return "Unknown argument $cmd, choose one of filter:noArg password question questionEnd pollFullstate:0,1 msg register login:noArg refresh:noArg";
|
|
||||||
# }
|
|
||||||
|
|
||||||
given ($cmd) {
|
given ($cmd) {
|
||||||
when ('msg') {
|
when ('msg') {
|
||||||
@ -344,13 +317,15 @@ sub Attr {
|
|||||||
if($cmd eq "set") {
|
if($cmd eq "set") {
|
||||||
if ($attr_name eq "matrixQuestion_") {
|
if ($attr_name eq "matrixQuestion_") {
|
||||||
my @erg = split(/ /, $attr_value, 2);
|
my @erg = split(/ /, $attr_value, 2);
|
||||||
return qq("attr $name $attr_name" ).I18N('require2') if (!$erg[1] || $erg[0] !~ /[0-9]/);
|
return qq("attr $name $attr_name" ).I18N('require2') if (!$erg[1]);
|
||||||
|
return qq("attr $name $attr_name" ).I18N('question').' '.I18N('beginWithNumber') if ($erg[0] !~ /[0-9]/);
|
||||||
$_[2] = "matrixQuestion_$erg[0]";
|
$_[2] = "matrixQuestion_$erg[0]";
|
||||||
$_[3] = $erg[1];
|
$_[3] = $erg[1];
|
||||||
}
|
}
|
||||||
if ($attr_name eq "matrixAnswer_") {
|
if ($attr_name eq "matrixAnswer_") {
|
||||||
my @erg = split(/ /, $attr_value, 2);
|
my @erg = split(/ /, $attr_value, 2);
|
||||||
return qq(wrong arguments $attr_name") if (!$erg[1] || $erg[0] !~ /[0-9]+/);
|
return qq("attr $name $attr_name" ).I18N('require2') if (!$erg[1]);
|
||||||
|
return qq("attr $name $attr_name" ).I18N('question').' '.I18N('beginWithNumber') if ($erg[0] !~ /[0-9]/);
|
||||||
$_[2] = "matrixAnswer_$erg[0]";
|
$_[2] = "matrixAnswer_$erg[0]";
|
||||||
$_[3] = $erg[1];
|
$_[3] = $erg[1];
|
||||||
}
|
}
|
||||||
@ -414,7 +389,7 @@ sub PerformHttpRequest
|
|||||||
}
|
}
|
||||||
$hash->{helper}->{"msgnumber"} = $hash->{helper}->{"msgnumber"} ? $hash->{helper}->{"msgnumber"} + 1 : 1;
|
$hash->{helper}->{"msgnumber"} = $hash->{helper}->{"msgnumber"} ? $hash->{helper}->{"msgnumber"} + 1 : 1;
|
||||||
my $msgnumber = $hash->{helper}->{"msgnumber"};
|
my $msgnumber = $hash->{helper}->{"msgnumber"};
|
||||||
my $deviceId = ReadingsVal($name, 'deviceId', undef) ? ', "deviceId":"'.ReadingsVal($name, 'deviceId', undef).'"' : "";
|
my $deviceId = ReadingsVal($name, 'deviceId', undef) ? ', "device_id":"'.ReadingsVal($name, 'deviceId', undef).'"' : "";
|
||||||
|
|
||||||
$hash->{helper}->{"busy"} = $hash->{helper}->{"busy"} ? $hash->{helper}->{"busy"} + 1 : 1; # queue is busy until response is received
|
$hash->{helper}->{"busy"} = $hash->{helper}->{"busy"} ? $hash->{helper}->{"busy"} + 1 : 1; # queue is busy until response is received
|
||||||
$hash->{helper}->{"sync"} = 0 if (!$hash->{helper}->{"sync"});
|
$hash->{helper}->{"sync"} = 0 if (!$hash->{helper}->{"sync"});
|
||||||
@ -437,23 +412,24 @@ sub PerformHttpRequest
|
|||||||
msgnumber => $msgnumber # lfd. Nummer Request
|
msgnumber => $msgnumber # lfd. Nummer Request
|
||||||
};
|
};
|
||||||
|
|
||||||
if ($def eq "logintypes"){
|
given ($def) {
|
||||||
|
when ('logintypes') {
|
||||||
$param->{'url'} = $hash->{server}."/_matrix/client/r0/login";
|
$param->{'url'} = $hash->{server}."/_matrix/client/r0/login";
|
||||||
$param->{'method'} = 'GET';
|
$param->{'method'} = 'GET';
|
||||||
}
|
}
|
||||||
if ($def eq "register"){
|
when ('register'){
|
||||||
$param->{'url'} = $hash->{server}."/_matrix/client/v3/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.'"}';
|
$param->{'data'} = '{"type":"m.login.password", "identifier":{ "type":"m.id.user", "user":"'.$hash->{user}.'" }, "password":"'.$passwd.'"}';
|
||||||
}
|
}
|
||||||
if ($def eq "reg1"){
|
when ('reg1'){
|
||||||
$param->{'url'} = $hash->{server}."/_matrix/client/v3/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.'"}';
|
$param->{'data'} = '{"type":"m.login.password", "identifier":{ "type":"m.id.user", "user":"'.$hash->{user}.'" }, "password":"'.$passwd.'"}';
|
||||||
}
|
}
|
||||||
if ($def eq"reg2"){
|
when ('reg2'){
|
||||||
$param->{'url'} = $hash->{server}."/_matrix/client/v3/register";
|
$param->{'url'} = $hash->{server}."/_matrix/client/v3/register";
|
||||||
$param->{'data'} = '{"username":"'.$hash->{user}.'", "password":"'.$passwd.'", "auth": {"session":"'.$hash->{helper}->{"session"}.'","type":"m.login.dummy"}}';
|
$param->{'data'} = '{"username":"'.$hash->{user}.'", "password":"'.$passwd.'", "auth": {"session":"'.$hash->{helper}->{"session"}.'","type":"m.login.dummy"}}';
|
||||||
}
|
}
|
||||||
if ($def eq "login"){
|
when ('login'){
|
||||||
if (AttrVal($name,'matrixLogin','') eq 'token'){
|
if (AttrVal($name,'matrixLogin','') eq 'token'){
|
||||||
$param->{'url'} = $hash->{server}."/_matrix/client/v3/login";
|
$param->{'url'} = $hash->{server}."/_matrix/client/v3/login";
|
||||||
$param->{'data'} = qq({"type":"m.login.token", "token":"$passwd", "user": "$hash->{user}", "txn_id": "z4567gerww", "session":"1234"});
|
$param->{'data'} = qq({"type":"m.login.token", "token":"$passwd", "user": "$hash->{user}", "txn_id": "z4567gerww", "session":"1234"});
|
||||||
@ -463,26 +439,52 @@ sub PerformHttpRequest
|
|||||||
$param->{'data'} = '{"type":"m.login.password", "refresh_token": true, "identifier":{ "type":"m.id.user", "user":"'.$hash->{user}.'" }, "password":"'.$passwd.'"'.$deviceId.'}';
|
$param->{'data'} = '{"type":"m.login.password", "refresh_token": true, "identifier":{ "type":"m.id.user", "user":"'.$hash->{user}.'" }, "password":"'.$passwd.'"'.$deviceId.'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($def eq "login2"){
|
when ('login2'){
|
||||||
$param->{'url'} = $hash->{server}."/_matrix/client/v3/login";
|
$param->{'url'} = $hash->{server}."/_matrix/client/v3/login";
|
||||||
if (AttrVal($name,'matrixLogin','') eq 'token'){
|
if (AttrVal($name,'matrixLogin','') eq 'token'){
|
||||||
$param->{'data'} = qq({"type":"m.login.token", "token":"$passwd", "user": "\@$hash->{user}:matrix.org", "txn_id": "z4567gerww"});
|
$param->{'data'} = qq({"type":"m.login.token", "token":"$passwd", "user": "\@$hash->{user}:matrix.org", "txn_id": "z4567gerww"});
|
||||||
#$param->{'data'} = qq({"type":"m.login.token", "token":"$passwd"});
|
#$param->{'data'} = qq({"type":"m.login.token", "token":"$passwd"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($def eq "refresh"){
|
when ('refresh'){
|
||||||
$param->{'url'} = $hash->{server}.'/_matrix/client/v1/refresh';
|
$param->{'url'} = $hash->{server}.'/_matrix/client/v1/refresh';
|
||||||
$param->{'data'} = '{"refresh_token": "'.$hash->{helper}->{"refresh_token"}.'"}';
|
$param->{'data'} = '{"refresh_token": "'.$hash->{helper}->{"refresh_token"}.'"}';
|
||||||
Log3($name, 5, qq($name $hash->{helper}->{"access_token"} refreshBeg $param->{'msgnumber'}: $hash->{helper}->{"next_refresh"} > $now) );
|
Log3($name, 5, qq($name $hash->{helper}->{"access_token"} refreshBeg $param->{'msgnumber'}: $hash->{helper}->{"next_refresh"} > $now) );
|
||||||
}
|
}
|
||||||
if ($def eq "wellknown"){
|
when ('wellknown'){
|
||||||
$param->{'url'} = $hash->{server}."/.well-known/matrix/client";
|
$param->{'url'} = $hash->{server}."/.well-known/matrix/client";
|
||||||
}
|
}
|
||||||
if ($def eq "msg"){
|
when ('msg'){
|
||||||
$param->{'url'} = $hash->{server}.'/_matrix/client/r0/rooms/'.AttrVal($name, 'matrixMessage', '!!').'/send/m.room.message?access_token='.$hash->{helper}->{"access_token"};
|
$param->{'url'} = $hash->{server}.'/_matrix/client/r0/rooms/'.AttrVal($name, 'matrixMessage', '!!').'/send/m.room.message?access_token='.$hash->{helper}->{"access_token"};
|
||||||
$param->{'data'} = '{"msgtype":"m.text", "body":"'.$value.'"}';
|
$param->{'data'} = '{"msgtype":"m.text", "body":"'.$value.'"}';
|
||||||
}
|
}
|
||||||
if ($def eq "question"){
|
when ('questionX'){
|
||||||
|
$hash->{helper}->{"question"}=$value;
|
||||||
|
$value = AttrVal($name, "matrixQuestion_$value",""); # if ($value =~ /[0-9]/);
|
||||||
|
my @question = split(':',$value);
|
||||||
|
my $size = @question;
|
||||||
|
my $answer;
|
||||||
|
my $q = shift @question;
|
||||||
|
$value =~ s/:/<br>/g;
|
||||||
|
# min. question and one answer
|
||||||
|
if (int(@question) >= 2){
|
||||||
|
$param->{'url'} = $hash->{server}.'/_matrix/client/v3/rooms/'.AttrVal($name, 'matrixMessage', '!!').
|
||||||
|
'/send/m.poll.start?access_token='.$hash->{helper}->{"access_token"};
|
||||||
|
$param->{'data'} = '{"type":"m.poll.start", "content":{"m.poll": {"max_selections": 1,'.
|
||||||
|
'"question": {"org.matrix.msc1767.text": "'.$q.'"},'.
|
||||||
|
'"kind": "org.matrix.msc3381.poll.undisclosed","answers": [';
|
||||||
|
my $comma = '';
|
||||||
|
foreach $answer (@question){
|
||||||
|
$param->{'data'} .= qq($comma {"id": "$answer", "org.matrix.msc1767.text": "$answer"});
|
||||||
|
$comma = ',';
|
||||||
|
}
|
||||||
|
$param->{'data'} .= qq(],"org.matrix.msc1767.text": "$value"}, "m.markup": [{"mimetype": "text/plain", "body": "$value"}]}});
|
||||||
|
} else {
|
||||||
|
Log3($name, 5, "question: $value $size $question[0]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
when ('question'){
|
||||||
$hash->{helper}->{"question"}=$value;
|
$hash->{helper}->{"question"}=$value;
|
||||||
$value = AttrVal($name, "matrixQuestion_$value",""); # if ($value =~ /[0-9]/);
|
$value = AttrVal($name, "matrixQuestion_$value",""); # if ($value =~ /[0-9]/);
|
||||||
my @question = split(':',$value);
|
my @question = split(':',$value);
|
||||||
@ -502,19 +504,19 @@ sub PerformHttpRequest
|
|||||||
$param->{'data'} .= qq($comma {"id": "$answer", "org.matrix.msc1767.text": "$answer"});
|
$param->{'data'} .= qq($comma {"id": "$answer", "org.matrix.msc1767.text": "$answer"});
|
||||||
$comma = ',';
|
$comma = ',';
|
||||||
}
|
}
|
||||||
$param->{'data'} .= qq(],"org.matrix.msc1767.text": "$value"}});
|
$param->{'data'} .= qq(],"org.matrix.msc1767.text": "$value"}, "m.markup": [{"mimetype": "text/plain", "body": "$value"}]});
|
||||||
} else {
|
} else {
|
||||||
Log3($name, 5, "question: $value $size $question[0]");
|
Log3($name, 5, "question: $value $size $question[0]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($def eq "questionEnd"){
|
when ('questionEnd'){
|
||||||
$value = ReadingsVal($name, "questionId", "") if (!$value);
|
$value = ReadingsVal($name, "questionId", "") if (!$value);
|
||||||
$param->{'url'} = $hash->{server}.'/_matrix/client/v3/rooms/'.AttrVal($name, 'matrixMessage', '!!').'/send/m.poll.end?access_token='.$hash->{helper}->{"access_token"};
|
$param->{'url'} = $hash->{server}.'/_matrix/client/v3/rooms/'.AttrVal($name, 'matrixMessage', '!!').'/send/m.poll.end?access_token='.$hash->{helper}->{"access_token"};
|
||||||
$param->{'data'} = '{"m.relates_to": {"rel_type": "m.reference","eventId": "'.$value.'"},"org.matrix.msc3381.poll.end": {},'.
|
$param->{'data'} = '{"m.relates_to": {"rel_type": "m.reference","eventId": "'.$value.'"},"org.matrix.msc3381.poll.end": {},'.
|
||||||
'"org.matrix.msc1767.text": "Antort '.ReadingsVal($name, "answer", "").' erhalten von '.ReadingsVal($name, "sender", "").'"}';
|
'"org.matrix.msc1767.text": "Antort '.ReadingsVal($name, "answer", "").' erhalten von '.ReadingsVal($name, "sender", "").'"}';
|
||||||
}
|
}
|
||||||
if ($def eq "sync"){
|
when ('sync'){
|
||||||
my $since = ReadingsVal($name, "since", undef) ? '&since='.ReadingsVal($name, "since", undef) : "";
|
my $since = ReadingsVal($name, "since", undef) ? '&since='.ReadingsVal($name, "since", undef) : "";
|
||||||
my $full_state = ReadingsVal($name, "pollFullstate",undef);
|
my $full_state = ReadingsVal($name, "pollFullstate",undef);
|
||||||
if ($full_state){
|
if ($full_state){
|
||||||
@ -529,7 +531,7 @@ sub PerformHttpRequest
|
|||||||
$hash->{helper}->{"sync"}++;
|
$hash->{helper}->{"sync"}++;
|
||||||
Log3($name, 5, qq($name $hash->{helper}->{"access_token"} syncBeg $param->{'msgnumber'}: $hash->{helper}->{"next_refresh"} > $now) );
|
Log3($name, 5, qq($name $hash->{helper}->{"access_token"} syncBeg $param->{'msgnumber'}: $hash->{helper}->{"next_refresh"} > $now) );
|
||||||
}
|
}
|
||||||
if ($def eq "filter"){
|
when ('filter'){
|
||||||
if ($value){ # get
|
if ($value){ # get
|
||||||
$param->{'url'} = $hash->{server}.'/_matrix/client/v3/user/'.ReadingsVal($name, "userId",0).'/filter/'.$value.'?access_token='.$hash->{helper}->{"access_token"};
|
$param->{'url'} = $hash->{server}.'/_matrix/client/v3/user/'.ReadingsVal($name, "userId",0).'/filter/'.$value.'?access_token='.$hash->{helper}->{"access_token"};
|
||||||
$param->{'method'} = 'GET';
|
$param->{'method'} = 'GET';
|
||||||
@ -543,6 +545,7 @@ sub PerformHttpRequest
|
|||||||
$param->{'data'} .= '}';
|
$param->{'data'} .= '}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
my $test = "$param->{url}, "
|
my $test = "$param->{url}, "
|
||||||
. ( $param->{data} ? "\r\ndata: $param->{data}, " : "" )
|
. ( $param->{data} ? "\r\ndata: $param->{data}, " : "" )
|
||||||
@ -597,7 +600,7 @@ sub ParseHttpResponse
|
|||||||
} else {
|
} else {
|
||||||
$hash->{helper}->{"softfail"}++;
|
$hash->{helper}->{"softfail"}++;
|
||||||
$hash->{helper}->{"hardfail"}++ if ($hash->{helper}->{"softfail"} > 3);
|
$hash->{helper}->{"hardfail"}++ if ($hash->{helper}->{"softfail"} > 3);
|
||||||
readingsBulkUpdate($hash, "responseError", qq(S$data{MATRIX}{$name}{'softfail'}: $data) );
|
readingsBulkUpdate($hash, "responseError", qq(S $hash->{helper}->{'softfail'}: $data) );
|
||||||
Log3($name, 5, qq($name $hash->{helper}->{"access_token"} ${def}End $param->{'msgnumber'}: $hash->{helper}->{"next_refresh"} > $now) );
|
Log3($name, 5, qq($name $hash->{helper}->{"access_token"} ${def}End $param->{'msgnumber'}: $hash->{helper}->{"next_refresh"} > $now) );
|
||||||
}
|
}
|
||||||
# readingsBulkUpdate($hash, "fullResponse", $data);
|
# readingsBulkUpdate($hash, "fullResponse", $data);
|
||||||
@ -750,28 +753,24 @@ sub ParseHttpResponse
|
|||||||
} else {
|
} else {
|
||||||
PerformHttpRequest($hash, $nextRequest, '');
|
PerformHttpRequest($hash, $nextRequest, '');
|
||||||
}
|
}
|
||||||
|
} elsif ($hash->{helper}->{"softfail"} == 0){
|
||||||
|
# nichts tun, doppelter sync verhindert
|
||||||
} else {
|
} else {
|
||||||
my $pauseLogin;
|
my $pauseLogin;
|
||||||
if ($hash->{helper}->{"hardfail"} >= 3){
|
if ($hash->{helper}->{"hardfail"} >= 3){
|
||||||
$pauseLogin = 300;
|
$pauseLogin = 300; # lange Pause wenn zu viele Fehler
|
||||||
} elsif ($hash->{helper}->{"softfail"} >= 3){
|
} elsif ($hash->{helper}->{"softfail"} >= 3){
|
||||||
$pauseLogin = 30;
|
$pauseLogin = 30; # kurze Pause nach drei Fehlern oder einem 400
|
||||||
} elsif ($hash->{helper}->{"softfail"} > 0){
|
|
||||||
$pauseLogin = 10;
|
|
||||||
} else {
|
} else {
|
||||||
$pauseLogin = 0;
|
$pauseLogin = 10; # nach logischem Fehler ganz kurze Pause
|
||||||
}
|
}
|
||||||
if ($pauseLogin > 0){
|
|
||||||
my $timeToStart = gettimeofday() + $pauseLogin;
|
my $timeToStart = gettimeofday() + $pauseLogin;
|
||||||
RemoveInternalTimer($hash->{myTimer}) if($hash->{myTimer});
|
RemoveInternalTimer($hash->{myTimer}) if($hash->{myTimer});
|
||||||
$hash->{myTimer} = { hash=>$hash };
|
$hash->{myTimer} = { hash=>$hash };
|
||||||
InternalTimer($timeToStart, \&FHEM::Devices::Matrix::Login, $hash->{myTimer});
|
InternalTimer($timeToStart, \&FHEM::Devices::Matrix::Login, $hash->{myTimer});
|
||||||
} else {
|
|
||||||
Login($hash);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
# Damit ist die Abfrage zuende.
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user