erster Code für Tasker Support ohne Tests
This commit is contained in:
parent
1c41df29db
commit
f8f74eabe1
@ -74,8 +74,8 @@ eval "use Encode qw(encode encode_utf8);1" or $missingModul .= "Encode ";
|
|||||||
eval "use JSON;1" or $missingModul .= "JSON ";
|
eval "use JSON;1" or $missingModul .= "JSON ";
|
||||||
|
|
||||||
|
|
||||||
my $modulversion = "4.2.0";
|
my $modulversion = "4.1.99.1";
|
||||||
my $flowsetversion = "4.2.0";
|
my $flowsetversion = "4.0.11";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -246,22 +246,35 @@ sub AMADCommBridge_Set($@) {
|
|||||||
|
|
||||||
sub AMADCommBridge_Write($@) {
|
sub AMADCommBridge_Write($@) {
|
||||||
|
|
||||||
my ($hash,$amad_id,$uri,$header,$method) = @_;
|
my ($hash,$amad_id,$uri,$path,$header,$method) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
my $dhash = $defs{$amad_id};
|
||||||
|
my $param;
|
||||||
|
my $remoteServer = AttrVal($dhash->{NAME},'remoteServer','Automagic');
|
||||||
|
|
||||||
|
|
||||||
HttpUtils_NonblockingGet(
|
|
||||||
{
|
|
||||||
url => "http://" . $uri,
|
$param = { url => "http://" . $uri . $path, timeout => 15, hash => $hash, amad_id => $amad_id, method => $method, header => $header, doTrigger => 1, callback => \&AMADCommBridge_ErrorHandling } if($remoteServer eq 'Automagic');
|
||||||
timeout => 15,
|
|
||||||
hash => $hash,
|
$param = { url => "http://" . $uri,
|
||||||
amad_id => $amad_id,
|
data => "{\"message\":\"AMAD=:=$path\", \"sender\":\"AMAD\", \"ttl\":60, \"communication_base_params\":{\"type\":\"Message\", \"fallback\":false, \"via\":\"Wifi\"},\"version\":\"1.62\"}",
|
||||||
method => $method,
|
timeout => 15, hash => $hash, amad_id => $amad_id, method => $method,
|
||||||
header => $header,
|
header => "agent: TeleHeater/2.2.3\r\nUser-Agent: TeleHeater/2.2.3\r\nAccept: application/json",
|
||||||
doTrigger => 1,
|
doTrigger => 1, callback => \&AMADCommBridge_ErrorHandling
|
||||||
callback => \&AMADCommBridge_ErrorHandling,
|
} if($remoteServer eq 'Autoremote');
|
||||||
}
|
|
||||||
);
|
$param = { url => "http://" . $uri,
|
||||||
|
data => "device=AMAD&cmd=".urlEncode($path),
|
||||||
|
timeout => 15, hash => $hash, amad_id => $amad_id, method => $method,
|
||||||
|
header => "agent: TeleHeater/2.2.3\r\nUser-Agent: TeleHeater/2.2.3\r\nAccept: application/json",
|
||||||
|
doTrigger => 1, callback => \&AMADCommBridge_ErrorHandling
|
||||||
|
} if($remoteServer eq 'TNES');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HttpUtils_NonblockingGet($param);
|
||||||
|
|
||||||
Log3 $name, 5, "AMADCommBridge ($name) - Send with URI: $uri, HEADER: $header, METHOD: $method";
|
Log3 $name, 5, "AMADCommBridge ($name) - Send with URI: $uri, HEADER: $header, METHOD: $method";
|
||||||
}
|
}
|
||||||
|
@ -58,8 +58,8 @@ eval "use Encode qw(encode encode_utf8);1" or $missingModul .= "Encode ";
|
|||||||
eval "use JSON;1" or $missingModul .= "JSON ";
|
eval "use JSON;1" or $missingModul .= "JSON ";
|
||||||
|
|
||||||
|
|
||||||
my $modulversion = "4.2.0";
|
my $modulversion = "4.1.99.1";
|
||||||
my $flowsetversion = "4.2.0";
|
my $flowsetversion = "4.0.11";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ sub AMADDevice_Initialize($) {
|
|||||||
"setAPSSID ".
|
"setAPSSID ".
|
||||||
"root:0,1 ".
|
"root:0,1 ".
|
||||||
"disable:1 ".
|
"disable:1 ".
|
||||||
"disableSetCmd:0,1 ".
|
"remoteServer:Automagic,Autoremote,TNES,other ".
|
||||||
$readingFnAttributes;
|
$readingFnAttributes;
|
||||||
|
|
||||||
foreach my $d(sort keys %{$modules{AMADDevice}{defptr}}) {
|
foreach my $d(sort keys %{$modules{AMADDevice}{defptr}}) {
|
||||||
@ -144,24 +144,28 @@ sub AMADDevice_Define($$) {
|
|||||||
if( $param =~ m/IODev=([^\s]*)/ ) {
|
if( $param =~ m/IODev=([^\s]*)/ ) {
|
||||||
|
|
||||||
$iodev = $1;
|
$iodev = $1;
|
||||||
splice( @a, $i, 3 );
|
splice( @a, $i, 4 );
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return "too few parameters: define <name> AMADDevice <HOST-IP> <amad_id>" if( @a != 3 );
|
return "too few parameters: define <name> AMADDevice <HOST-IP> <amad_id> <remoteServer>" if( @a != 4 );
|
||||||
return "Cannot define a AMAD device. Perl modul $missingModul is missing." if ( $missingModul );
|
return "Cannot define a AMAD device. Perl modul $missingModul is missing." if ( $missingModul );
|
||||||
|
|
||||||
|
|
||||||
my ($name,$host,$amad_id) = @a;
|
my ($name,$host,$amad_id,$remoteServer) = @a;
|
||||||
|
|
||||||
$hash->{HOST} = $host;
|
$hash->{HOST} = $host;
|
||||||
$hash->{AMAD_ID} = $amad_id;
|
$hash->{AMAD_ID} = $amad_id;
|
||||||
$hash->{PORT} = 8090;
|
|
||||||
$hash->{VERSIONMODUL} = $modulversion;
|
$hash->{VERSIONMODUL} = $modulversion;
|
||||||
$hash->{VERSIONFLOWSET} = $flowsetversion;
|
$hash->{VERSIONFLOWSET} = $flowsetversion;
|
||||||
|
|
||||||
|
$hash->{PORT} = 8090 if($remoteServer eq 'Automagic');
|
||||||
|
$hash->{PORT} = 1817 if($remoteServer eq 'Autoremote');
|
||||||
|
$hash->{PORT} = 8765 if($remoteServer eq 'TNES');
|
||||||
|
|
||||||
$hash->{helper}{infoErrorCounter} = 0;
|
$hash->{helper}{infoErrorCounter} = 0;
|
||||||
$hash->{helper}{setCmdErrorCounter} = 0;
|
$hash->{helper}{setCmdErrorCounter} = 0;
|
||||||
$hash->{helper}{deviceStateErrorCounter} = 0;
|
$hash->{helper}{deviceStateErrorCounter} = 0;
|
||||||
@ -188,9 +192,10 @@ sub AMADDevice_Define($$) {
|
|||||||
return "AMADDevice device $name on AMADCommBridge $iodev already defined."
|
return "AMADDevice device $name on AMADCommBridge $iodev already defined."
|
||||||
if( defined($d) && $d->{IODev} == $hash->{IODev} && $d->{NAME} ne $name );
|
if( defined($d) && $d->{IODev} == $hash->{IODev} && $d->{NAME} ne $name );
|
||||||
|
|
||||||
Log3 $name, 3, "AMADDevice ($name) - defined with AMAD_ID: $amad_id on port $hash->{PORT}";
|
|
||||||
|
|
||||||
$attr{$name}{room} = "AMAD" if( !defined( $attr{$name}{room} ) );
|
|
||||||
|
CommandAttr(undef,$name . "room AMAD") if(AttrVal($name,'room','none') eq 'none';
|
||||||
|
CommandAttr(undef,$name . "remoteServer $remoteServer") if(AttrVal($name,'remoteServer','none') eq 'none';
|
||||||
|
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
readingsBulkUpdateIfChanged( $hash, "state", "initialized",1);
|
readingsBulkUpdateIfChanged( $hash, "state", "initialized",1);
|
||||||
@ -198,6 +203,9 @@ sub AMADDevice_Define($$) {
|
|||||||
readingsEndUpdate($hash,1);
|
readingsEndUpdate($hash,1);
|
||||||
|
|
||||||
|
|
||||||
|
Log3 $name, 3, "AMADDevice ($name) - defined with AMAD_ID: $amad_id on port $hash->{PORT}";
|
||||||
|
|
||||||
|
|
||||||
if( $init_done ) {
|
if( $init_done ) {
|
||||||
|
|
||||||
InternalTimer( gettimeofday()+3, "AMADDevice_GetUpdate", $hash, 0 ) if( ($hash->{HOST}) );
|
InternalTimer( gettimeofday()+3, "AMADDevice_GetUpdate", $hash, 0 ) if( ($hash->{HOST}) );
|
||||||
@ -353,14 +361,14 @@ sub AMADDevice_statusRequest($) {
|
|||||||
my $fhemip = ReadingsVal($hash->{IODev}->{NAME}, "fhemServerIP", "none");
|
my $fhemip = ReadingsVal($hash->{IODev}->{NAME}, "fhemServerIP", "none");
|
||||||
my $fhemCtlMode = AttrVal($hash->{IODev}->{NAME},'fhemControlMode','none' );
|
my $fhemCtlMode = AttrVal($hash->{IODev}->{NAME},'fhemControlMode','none' );
|
||||||
my $bport = $hash->{IODev}->{PORT};
|
my $bport = $hash->{IODev}->{PORT};
|
||||||
my $disableSetCmd = AttrVal( $name, "disableSetCmd", "0" );
|
my $remoteServer = AttrVal( $name, "remoteServer", "Automagic" );
|
||||||
|
|
||||||
$header .= "\r\nfhemip: $fhemip\r\nfhemdevice: $name\r\nactivetask: $activetask\r\napssid: $apssid\r\nbport: $bport\r\nuserflowstate: $userFlowState\r\namadid: $amad_id\r\nfhemctlmode: $fhemCtlMode";
|
$header .= "\r\nfhemip: $fhemip\r\nfhemdevice: $name\r\nactivetask: $activetask\r\napssid: $apssid\r\nbport: $bport\r\nuserflowstate: $userFlowState\r\namadid: $amad_id\r\nfhemctlmode: $fhemCtlMode";
|
||||||
$method = "GET";
|
$method = "GET";
|
||||||
$path ="/fhem-amad/deviceInfo/"; # Pfad muß so im Automagic als http request Trigger drin stehen
|
$path ="/fhem-amad/deviceInfo/"; # Pfad muß so im Automagic als http request Trigger drin stehen
|
||||||
readingsSingleUpdate( $hash, "lastSetCommand", $path, 1 );
|
readingsSingleUpdate( $hash, "lastSetCommand", $path, 1 );
|
||||||
|
|
||||||
if ($disableSetCmd ne "1"){
|
if ($remoteServer eq "Automagic"){
|
||||||
$uri = $host . ":" . $port . $path;
|
$uri = $host . ":" . $port . $path;
|
||||||
IOWrite($hash,$amad_id,$uri,$header,$method);
|
IOWrite($hash,$amad_id,$uri,$header,$method);
|
||||||
Log3 $name, 5, "AMADDevice ($name) - IOWrite: $uri $method IODevHash=$hash->{IODev}";
|
Log3 $name, 5, "AMADDevice ($name) - IOWrite: $uri $method IODevHash=$hash->{IODev}";
|
||||||
@ -434,18 +442,16 @@ sub AMADDevice_Set($$@) {
|
|||||||
my ($hash, $name, @aa) = @_;
|
my ($hash, $name, @aa) = @_;
|
||||||
my ($cmd, @args) = @aa;
|
my ($cmd, @args) = @aa;
|
||||||
|
|
||||||
my $host = $hash->{HOST};
|
|
||||||
my $port = $hash->{PORT};
|
|
||||||
my $amad_id = $hash->{AMAD_ID};
|
my $amad_id = $hash->{AMAD_ID};
|
||||||
my $uri;
|
|
||||||
my $path;
|
|
||||||
my $header = 'Connection: close';
|
my $header = 'Connection: close';
|
||||||
|
my $uri = $hash->{HOST} . ":" . $hash->{PORT};
|
||||||
|
my $path;
|
||||||
my $method;
|
my $method;
|
||||||
|
|
||||||
my $volMax = AttrVal($name,'setVolMax',15);
|
my $volMax = AttrVal($name,'setVolMax',15);
|
||||||
my $notifyVolMax = AttrVal($name,'setNotifyVolMax',7);
|
my $notifyVolMax = AttrVal($name,'setNotifyVolMax',7);
|
||||||
my $ringSoundVolMax = AttrVal($name,'setRingSoundVolMax',7);
|
my $ringSoundVolMax = AttrVal($name,'setRingSoundVolMax',7);
|
||||||
my $disableSetCmd = AttrVal( $name, "disableSetCmd", "0" );
|
|
||||||
|
|
||||||
if( lc $cmd eq 'screenmsg' ) {
|
if( lc $cmd eq 'screenmsg' ) {
|
||||||
my $msg = join( " ", @args );
|
my $msg = join( " ", @args );
|
||||||
@ -514,6 +520,7 @@ sub AMADDevice_Set($$@) {
|
|||||||
elsif( lc $cmd eq 'screen' ) {
|
elsif( lc $cmd eq 'screen' ) {
|
||||||
my $mod = join( " ", @args );
|
my $mod = join( " ", @args );
|
||||||
|
|
||||||
|
|
||||||
$path = AMADDevice_CreateScreenValue($hash,$mod);
|
$path = AMADDevice_CreateScreenValue($hash,$mod);
|
||||||
return "Please set \"setScreenlockPIN\" Attribut first"
|
return "Please set \"setScreenlockPIN\" Attribut first"
|
||||||
unless($path ne 'NO PIN');
|
unless($path ne 'NO PIN');
|
||||||
@ -721,11 +728,9 @@ sub AMADDevice_Set($$@) {
|
|||||||
|
|
||||||
readingsSingleUpdate( $hash, "lastSetCommand", $path, 1 );
|
readingsSingleUpdate( $hash, "lastSetCommand", $path, 1 );
|
||||||
|
|
||||||
if ($disableSetCmd ne "1"){
|
|
||||||
$uri = $host . ":" . $port . $path;
|
IOWrite($hash,$amad_id,$uri,$path,$header,$method);
|
||||||
IOWrite($hash,$amad_id,$uri,$header,$method);
|
|
||||||
Log3 $name, 5, "AMADDevice ($name) - IOWrite: $uri $method IODevHash=$hash->{IODev}";
|
Log3 $name, 5, "AMADDevice ($name) - IOWrite: $uri $method IODevHash=$hash->{IODev}";
|
||||||
}
|
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -759,7 +764,7 @@ sub AMADDevice_Parse($$) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
return "UNDEFINED $fhemDevice AMADDevice $decode_json->{firstrun}{'amaddevice_ip'} $decode_json->{amad}{'amad_id'} IODev=$name";
|
return "UNDEFINED $fhemDevice AMADDevice $decode_json->{firstrun}{'amaddevice_ip'} $decode_json->{amad}{'amad_id'} $decode_json->{firstrun}{remoteserver} IODev=$name";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user