diff --git a/fhem/CHANGED b/fhem/CHANGED index a9df88cff..a2ec683a9 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 50_Signalbot: support to link 2 FHEM instance under the same number - feature: 93_DbLog: new Attr convertTimezone -> logging in UTC time - bugfix: 93_DbRep: fix set ... deleteOther for SQLite - feature: 60_allergy: alternative data source with Attribute alternative3Day diff --git a/fhem/FHEM/50_Signalbot.pm b/fhem/FHEM/50_Signalbot.pm index d5e978559..d74e3d396 100755 --- a/fhem/FHEM/50_Signalbot.pm +++ b/fhem/FHEM/50_Signalbot.pm @@ -1,6 +1,6 @@ ############################################## #$Id$ -my $Signalbot_VERSION="3.9"; +my $Signalbot_VERSION="3.10"; # Simple Interface to Signal CLI running as Dbus service # Author: Adimarantis # License: GPL @@ -62,6 +62,8 @@ use vars qw($FW_RET); "setPin" => "s", #V0.10.0 "removePin" => "", #V0.10.0 "getGroup" => "ay", #V0.10.0 + "addDevice" => "s", + "listDevices" => "", "sendEndSessionMessage" => "as", #unused "sendRemoteDeleteMessage" => "xas", #unused "sendGroupRemoteDeletemessage" => "xay",#unused @@ -166,7 +168,9 @@ sub Signalbot_Set($@) { # @accounts =@{$hash->{helper}{accountlist}} if defined $hash->{helper}{accountlist}; my $sets= "send:textField ". "updateProfile:textField ". - "reply:textField "; + "reply:textField ". + "addDevice:textField ". + "removeDevice:textField "; $sets.= "addContact:textField ". "createGroup:textField ". "invite:textField ". @@ -177,7 +181,7 @@ sub Signalbot_Set($@) { # "joinGroup:textField " if $version <1000; $sets.= "group:widgetList,13,select,addMembers,removeMembers,addAdmins,removeAdmins,invite,create,delete,block,unblock,update,". "quit,join,1,textField contact:widgetList,5,select,add,delete,block,unblock,1,textField " if $version >=1000; - my $sets_reg= "link:noArg ". + my $sets_reg= "link:textField ". "register:textField "; $sets_reg .= "captcha:textField " if defined ($hash->{helper}{register}); $sets_reg .= "verify:textField " if defined ($hash->{helper}{verification}); @@ -222,7 +226,8 @@ sub Signalbot_Set($@) { # my $ret = Signalbot_setAccount($hash, $number); # undef is success if (!defined $ret) { - Signalbot_refreshGroups($hash); + $ret=Signalbot_setup($hash); + $hash->{STATE} = $ret if defined $ret; $hash->{helper}{qr}=undef; $hash->{helper}{register}=undef; $hash->{helper}{verification}=undef; @@ -232,16 +237,27 @@ sub Signalbot_Set($@) { # $ret = Signalbot_setAccount($hash,$account); return "Error changing account, using previous account $account"; } elsif ($cmd eq "link") { - my $qrcode=Signalbot_CallS($hash,"link","FHEM"); + my $acname=shift @args; + $acname="FHEM" if (!defined $acname); + my $qrcode=Signalbot_CallS($hash,"link",$acname); if (defined $qrcode) { my $qr_url = "https://chart.googleapis.com/chart?cht=qr&chs=200x200"."&chl="; $qr_url .= uri_escape($qrcode); $hash->{helper}{qr}=$qr_url; + $hash->{helper}{uri}=$qrcode; $hash->{helper}{register}=undef; $hash->{helper}{verification}=undef; return undef; } return "Error creating device link:".$hash->{helper}{lasterr}; + } elsif ($cmd eq "addDevice") { + my $url = shift @args; + my $ret = Signalbot_CallS($hash,"addDevice",$url); + LogUnicode $hash->{NAME}, 3 , $hash->{NAME}.": AddDevice for ".$url." returned:" .$ret; + return $ret; + } elsif ($cmd eq "removeDevice") { + my $devID = shift @args; + return Signalbot_removeDevice($hash,$devID); } elsif ( $cmd eq "register") { my $account= shift @args; return "Number needs to start with '+' followed by digits" if !defined Signalbot_checkNumber($account); @@ -550,7 +566,7 @@ sub Signalbot_Get($@) { if ($cmd eq "?") { my $gets="favorites:noArg accounts:noArg helpUnicode:noArg "; $gets.="contacts:all,nonblocked ". - "groups:all,active,nonblocked " if $account ne "none"; + "groups:all,active,nonblocked devices:noArg " if $account ne "none"; $gets .="groupProperties:textField " if $version >= 1000; return "Signalbot_Get: Unknown argument $cmd, choose one of ".$gets; } @@ -569,6 +585,17 @@ sub Signalbot_Get($@) { my @numlist=@{$hash->{helper}{accountlist}}; $ret=$ret.join("\n",@numlist); return $ret; + } elsif ($cmd eq "devices") { + my $ret=Signalbot_CallS($hash,"listDevices"); + my $str="Linked devices:\n\n"; + foreach my $dev (@$ret) { + my ($devpath,$devid,$devname)=@$dev; + if ($devid eq 1 && $devname eq "") { + $devname="main device"; + } + $str.=sprintf("%2i %s\n",$devid,$devname); + } + return $str; } elsif ($cmd eq "favorites") { my $favs = AttrVal($name,"favorites",""); $favs =~ s/[\n\r]//g; @@ -1218,6 +1245,14 @@ sub Signalbot_getGroupProperties($@) { return Signalbot_CallDbus($hash,1,$path,'GetAll',$prototype,'org.freedesktop.DBus.Properties','org.asamk.Signal.Group'); } +sub Signalbot_removeDevice($@) { + my ($hash,$devid) = @_; + return "DeviceID needs to be numeric" if (!looks_like_number($devid)); + return "You should not remove the main device" if $devid eq 1; + my $path=$hash->{helper}{signalpath}."/Devices/".$devid; + my @emptylist; + return Signalbot_CallDbus($hash,1,$path,'removeDevice','','org.asamk.Signal',@emptylist); +} sub Signalbot_CallDbus($@) { my ($hash,$sync,$path,$function,$prototype,$interface,@args) = @_; @@ -2011,6 +2046,7 @@ sub Signalbot_Detail { $ret .= ""; $ret .= "