change AMADDevice modul to package
This commit is contained in:
parent
f8d5410e8a
commit
b7afd2ebda
@ -76,8 +76,8 @@ eval "use JSON;1" or $missingModul .= "JSON ";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
my $modulversion = "4.2.3";
|
my $modulversion = "4.4.0";
|
||||||
my $flowsetversion = "4.2.5";
|
my $flowsetversion = "4.4.0";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -236,12 +236,8 @@ sub AMADCommBridge_Set($@) {
|
|||||||
|
|
||||||
AMADCommBridge_Close($hash);
|
AMADCommBridge_Close($hash);
|
||||||
|
|
||||||
} elsif( $cmd eq 'fhemServerIP' ) {
|
|
||||||
|
|
||||||
readingsSingleUpdate($hash,$cmd,$arg,1);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
my $list = "open:noArg close:noArg fhemServerIP";
|
my $list = "open:noArg close:noArg";
|
||||||
return "Unknown argument $cmd, choose one of $list";
|
return "Unknown argument $cmd, choose one of $list";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1068,7 +1064,6 @@ sub AMADCommBridge_ParseMsg($$) {
|
|||||||
<ul><br>
|
<ul><br>
|
||||||
<li>JSON_ERROR - JSON Error message reported by Perl</li>
|
<li>JSON_ERROR - JSON Error message reported by Perl</li>
|
||||||
<li>JSON_ERROR_STRING - The string that caused the JSON error message</li>
|
<li>JSON_ERROR_STRING - The string that caused the JSON error message</li>
|
||||||
<li>fhemServerIP - The IP address of the FHEM server, is set by the module based on the JSON string from the installation wizard. Can also be set by user using set command</li>
|
|
||||||
<li>receiveFhemCommand - is set the fhemControlMode attribute to trigger, the reading is set as soon as an FHEM command is sent. A notification can then be triggered.</br>
|
<li>receiveFhemCommand - is set the fhemControlMode attribute to trigger, the reading is set as soon as an FHEM command is sent. A notification can then be triggered.</br>
|
||||||
If set instead of trigger setControl as value for fhemControlMode, the reading is not executed but the set command executed immediately.</li>
|
If set instead of trigger setControl as value for fhemControlMode, the reading is not executed but the set command executed immediately.</li>
|
||||||
<li>receiveVoiceCommand - The speech control is activated by AMAD (set DEVICE activateVoiceInput), the last recognized voice command is written into this reading.</li>
|
<li>receiveVoiceCommand - The speech control is activated by AMAD (set DEVICE activateVoiceInput), the last recognized voice command is written into this reading.</li>
|
||||||
@ -1141,7 +1136,6 @@ sub AMADCommBridge_ParseMsg($$) {
|
|||||||
<ul><br>
|
<ul><br>
|
||||||
<li>JSON_ERROR - JSON Fehlermeldung welche von Perl gemeldet wird</li>
|
<li>JSON_ERROR - JSON Fehlermeldung welche von Perl gemeldet wird</li>
|
||||||
<li>JSON_ERROR_STRING - der String welcher die JSON Fehlermeldung verursacht hat</li>
|
<li>JSON_ERROR_STRING - der String welcher die JSON Fehlermeldung verursacht hat</li>
|
||||||
<li>fhemServerIP - die Ip-Adresse des FHEM Servers, wird vom Modul auf Basis des JSON Strings vom Installationsassistenten gesetzt. Kann aber auch mittels set Befehles vom User gesetzt werden</li>
|
|
||||||
<li>receiveFhemCommand - ist das Attribut fhemControlMode auf trigger gestellt, wird das Reading gesetzt sobald ein FHEM Befehl übersendet wird. Hierauf kann dann ein Notify triggern.</br>
|
<li>receiveFhemCommand - ist das Attribut fhemControlMode auf trigger gestellt, wird das Reading gesetzt sobald ein FHEM Befehl übersendet wird. Hierauf kann dann ein Notify triggern.</br>
|
||||||
Wird anstelle von trigger setControl als Wert für fhemControlMode eingestellt, wird das Reading nicht gestzt sondern der set Befehl sofort ausgeführt.</li>
|
Wird anstelle von trigger setControl als Wert für fhemControlMode eingestellt, wird das Reading nicht gestzt sondern der set Befehl sofort ausgeführt.</li>
|
||||||
<li>receiveVoiceCommand - wird die Sprachsteuerung von AMAD aktiviert (set DEVICE activateVoiceInput) so wird der letzte erkannten Sprachbefehle in dieses Reading geschrieben.</li>
|
<li>receiveVoiceCommand - wird die Sprachsteuerung von AMAD aktiviert (set DEVICE activateVoiceInput) so wird der letzte erkannten Sprachbefehle in dieses Reading geschrieben.</li>
|
||||||
|
370
74_AMADDevice.pm
370
74_AMADDevice.pm
@ -44,49 +44,14 @@
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package main;
|
package main;
|
||||||
|
|
||||||
|
|
||||||
my $missingModul = "";
|
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
use FHEM::Meta;
|
||||||
|
|
||||||
eval "use Encode qw(encode encode_utf8);1" or $missingModul .= "Encode ";
|
my $modulversion = '4.4.0';
|
||||||
eval "use JSON;1" or $missingModul .= "JSON ";
|
my $flowsetversion = '4.4.0';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
my $modulversion = "4.2.7";
|
|
||||||
my $flowsetversion = "4.2.5";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Declare functions
|
|
||||||
sub AMADDevice_Attr(@);
|
|
||||||
sub AMADDevice_Notify($$);
|
|
||||||
sub AMADDevice_checkDeviceState($);
|
|
||||||
sub AMADDevice_decrypt($);
|
|
||||||
sub AMADDevice_Define($$);
|
|
||||||
sub AMADDevice_encrypt($);
|
|
||||||
sub AMADDevice_GetUpdate($);
|
|
||||||
sub AMADDevice_Initialize($);
|
|
||||||
sub AMADDevice_WriteReadings($$);
|
|
||||||
sub AMADDevice_Set($$@);
|
|
||||||
sub AMADDevice_Undef($$);
|
|
||||||
sub AMADDevice_Parse($$);
|
|
||||||
sub AMADDevice_statusRequest($);
|
|
||||||
sub AMADDevice_CreateVolumeValue($$@);
|
|
||||||
sub AMADDevice_CreateTtsMsgValue($@);
|
|
||||||
sub AMADDevice_CreateScreenValue($$);
|
|
||||||
sub AMADDevice_CreateChangeBtDeviceValue($$);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sub AMADDevice_Initialize($) {
|
sub AMADDevice_Initialize($) {
|
||||||
|
|
||||||
@ -95,40 +60,40 @@ sub AMADDevice_Initialize($) {
|
|||||||
$hash->{Match} = '{"amad": \{"amad_id":.+}}';
|
$hash->{Match} = '{"amad": \{"amad_id":.+}}';
|
||||||
|
|
||||||
|
|
||||||
$hash->{SetFn} = "AMADDevice_Set";
|
$hash->{SetFn} = 'FHEM::AMADDevice::Set';
|
||||||
$hash->{DefFn} = "AMADDevice_Define";
|
$hash->{DefFn} = 'FHEM::AMADDevice::Define';
|
||||||
$hash->{UndefFn} = "AMADDevice_Undef";
|
$hash->{UndefFn} = 'FHEM::AMADDevice::Undef';
|
||||||
$hash->{AttrFn} = "AMADDevice_Attr";
|
$hash->{AttrFn} = 'FHEM::AMADDevice::Attr';
|
||||||
$hash->{NotifyFn} = "AMADDevice_Notify";
|
$hash->{NotifyFn} = 'FHEM::AMADDevice::Notify';
|
||||||
$hash->{ParseFn} = "AMADDevice_Parse";
|
$hash->{ParseFn} = 'FHEM::AMADDevice::Parse';
|
||||||
|
|
||||||
$hash->{AttrList} = "setOpenApp ".
|
$hash->{AttrList} = 'setOpenApp '.
|
||||||
"checkActiveTask ".
|
'checkActiveTask '.
|
||||||
"setFullscreen:0,1 ".
|
'setFullscreen:0,1 '.
|
||||||
"setScreenOrientation:0,1 ".
|
'setScreenOrientation:0,1 '.
|
||||||
"setScreenBrightness:noArg ".
|
'setScreenBrightness:noArg '.
|
||||||
"setBluetoothDevice ".
|
'setBluetoothDevice '.
|
||||||
"setScreenlockPIN ".
|
'setScreenlockPIN '.
|
||||||
"setScreenOnForTimer ".
|
'setScreenOnForTimer '.
|
||||||
"setOpenUrlBrowser ".
|
'setOpenUrlBrowser '.
|
||||||
"setNotifySndFilePath ".
|
'setNotifySndFilePath '.
|
||||||
"setTtsMsgSpeed ".
|
'setTtsMsgSpeed '.
|
||||||
"setTtsMsgLang:de,en ".
|
'setTtsMsgLang:de,en '.
|
||||||
"setTtsMsgVol ".
|
'setTtsMsgVol '.
|
||||||
"setUserFlowState ".
|
'setUserFlowState '.
|
||||||
"setVolUpDownStep:1,2,4,5 ".
|
'setVolUpDownStep:1,2,4,5 '.
|
||||||
"setVolMax ".
|
'setVolMax '.
|
||||||
"setVolFactor:2,3,4,5 ".
|
'setVolFactor:2,3,4,5 '.
|
||||||
"setNotifyVolMax ".
|
'setNotifyVolMax '.
|
||||||
"setRingSoundVolMax ".
|
'setRingSoundVolMax '.
|
||||||
"setAPSSID ".
|
'setAPSSID '.
|
||||||
"root:0,1 ".
|
'root:0,1 '.
|
||||||
"disable:1 ".
|
'disable:1 '.
|
||||||
"IODev ".
|
'IODev '.
|
||||||
"remoteServer:Automagic,Autoremote,TNES,other ".
|
'remoteServer:Automagic,Autoremote,TNES,other '.
|
||||||
"setTakeScreenshotResolution:1280x720,1920x1080,1920x1200 ".
|
'setTakeScreenshotResolution:1280x720,1920x1080,1920x1200 '.
|
||||||
"setTakePictureResolution:800x600,1024x768,1280x720,1600x1200,1920x1080 ".
|
'setTakePictureResolution:800x600,1024x768,1280x720,1600x1200,1920x1080 '.
|
||||||
"setTakePictureCamera:Back,Front ".
|
'setTakePictureCamera:Back,Front '.
|
||||||
$readingFnAttributes;
|
$readingFnAttributes;
|
||||||
|
|
||||||
foreach my $d(sort keys %{$modules{AMADDevice}{defptr}}) {
|
foreach my $d(sort keys %{$modules{AMADDevice}{defptr}}) {
|
||||||
@ -137,15 +102,63 @@ sub AMADDevice_Initialize($) {
|
|||||||
$hash->{VERSIONMODUL} = $modulversion;
|
$hash->{VERSIONMODUL} = $modulversion;
|
||||||
$hash->{VERSIONFLOWSET} = $flowsetversion;
|
$hash->{VERSIONFLOWSET} = $flowsetversion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return FHEM::Meta::InitMod( __FILE__, $hash );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMADDevice_Define($$) {
|
## unserer packagename
|
||||||
|
package FHEM::AMADDevice;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use POSIX;
|
||||||
|
use FHEM::Meta;
|
||||||
|
|
||||||
|
use GPUtils qw(GP_Import)
|
||||||
|
; # wird für den Import der FHEM Funktionen aus der fhem.pl benötigt
|
||||||
|
|
||||||
|
my $missingModul = '';
|
||||||
|
|
||||||
|
eval "use Encode qw(encode encode_utf8);1" or $missingModul .= 'Encode ';
|
||||||
|
eval "use JSON;1" or $missingModul .= 'JSON ';
|
||||||
|
|
||||||
|
## Import der FHEM Funktionen
|
||||||
|
BEGIN {
|
||||||
|
GP_Import(
|
||||||
|
qw(readingsSingleUpdate
|
||||||
|
readingsBulkUpdate
|
||||||
|
readingsBulkUpdateIfChanged
|
||||||
|
readingsBeginUpdate
|
||||||
|
readingsEndUpdate
|
||||||
|
CommandDeleteReading
|
||||||
|
defs
|
||||||
|
modules
|
||||||
|
Log3
|
||||||
|
CommandAttr
|
||||||
|
attr
|
||||||
|
AttrVal
|
||||||
|
ReadingsVal
|
||||||
|
IsDisabled
|
||||||
|
deviceEvents
|
||||||
|
init_done
|
||||||
|
gettimeofday
|
||||||
|
InternalTimer
|
||||||
|
RemoveInternalTimer
|
||||||
|
IOWrite
|
||||||
|
ReadingsAge
|
||||||
|
urlEncode
|
||||||
|
AssignIoPort)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub Define($$) {
|
||||||
|
|
||||||
my ( $hash, $def ) = @_;
|
my ( $hash, $def ) = @_;
|
||||||
my @a = split( "[ \t]+", $def );
|
my @a = split( '[ \t]+', $def );
|
||||||
|
|
||||||
return "too few parameters: define <name> AMADDevice <HOST-IP> <amad_id> <remoteServer>" if( @a != 5 );
|
return $@ unless ( FHEM::Meta::SetInternals($hash) );
|
||||||
return "Cannot define a AMADDevice device. Perl modul $missingModul is missing." if ( $missingModul );
|
return 'too few parameters: define <name> AMADDevice <HOST-IP> <amad_id> <remoteServer>' if( @a != 5 );
|
||||||
|
return 'Cannot define a AMADDevice device. Perl modul ' . $missingModul . ' is missing.' if ( $missingModul );
|
||||||
|
|
||||||
|
|
||||||
my $name = $a[0];
|
my $name = $a[0];
|
||||||
@ -157,7 +170,8 @@ sub AMADDevice_Define($$) {
|
|||||||
$hash->{AMAD_ID} = $amad_id;
|
$hash->{AMAD_ID} = $amad_id;
|
||||||
$hash->{VERSIONMODUL} = $modulversion;
|
$hash->{VERSIONMODUL} = $modulversion;
|
||||||
$hash->{VERSIONFLOWSET} = $flowsetversion;
|
$hash->{VERSIONFLOWSET} = $flowsetversion;
|
||||||
$hash->{NOTIFYDEV} = "global,$name";
|
$hash->{NOTIFYDEV} = 'global,'.$name;
|
||||||
|
$hash->{MODEL} = $remoteServer;
|
||||||
|
|
||||||
$hash->{PORT} = 8090 if($remoteServer eq 'Automagic');
|
$hash->{PORT} = 8090 if($remoteServer eq 'Automagic');
|
||||||
$hash->{PORT} = 1817 if($remoteServer eq 'Autoremote');
|
$hash->{PORT} = 1817 if($remoteServer eq 'Autoremote');
|
||||||
@ -172,16 +186,18 @@ sub AMADDevice_Define($$) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
CommandAttr(undef,"$name IODev $modules{AMADCommBridge}{defptr}{BRIDGE}->{NAME}") if(AttrVal($name,'IODev','none') eq 'none');
|
CommandAttr(undef,$name . ' IODev ' . $modules{AMADCommBridge}{defptr}{BRIDGE}->{NAME})
|
||||||
|
if( defined($modules{AMADCommBridge}{defptr}{BRIDGE}->{NAME})
|
||||||
|
and AttrVal($name,'IODev','none') eq 'none');
|
||||||
|
|
||||||
my $iodev = AttrVal($name,'IODev','none');
|
my $iodev = AttrVal($name,'IODev','none');
|
||||||
|
|
||||||
AssignIoPort($hash,$iodev) if( !$hash->{IODev} );
|
AssignIoPort($hash,$iodev) if( !$hash->{IODev} );
|
||||||
|
|
||||||
if(defined($hash->{IODev}->{NAME})) {
|
if(defined($hash->{IODev}->{NAME})) {
|
||||||
Log3 $name, 3, "AMADDevice ($name) - I/O device is " . $hash->{IODev}->{NAME};
|
Log3($name, 3, "AMADDevice ($name) - I/O device is " . $hash->{IODev}->{NAME});
|
||||||
} else {
|
} else {
|
||||||
Log3 $name, 1, "AMADDevice ($name) - no I/O device";
|
Log3($name, 1, "AMADDevice ($name) - no I/O device");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -189,21 +205,21 @@ sub AMADDevice_Define($$) {
|
|||||||
|
|
||||||
my $d = $modules{AMADDevice}{defptr}{$amad_id};
|
my $d = $modules{AMADDevice}{defptr}{$amad_id};
|
||||||
|
|
||||||
return "AMADDevice device $name on AMADCommBridge $iodev already defined."
|
return 'AMADDevice device ' . $name . ' on AMADCommBridge ' . $iodev . ' already defined.'
|
||||||
if( defined($d) and $d->{IODev} == $hash->{IODev} and $d->{NAME} ne $name );
|
if( defined($d) and $d->{IODev} == $hash->{IODev} and $d->{NAME} ne $name );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CommandAttr(undef,"$name room AMAD") if(AttrVal($name,'room','none') eq 'none');
|
CommandAttr(undef,$name . ' room AMAD') if(AttrVal($name,'room','none') eq 'none');
|
||||||
CommandAttr(undef,"$name remoteServer $remoteServer") if(AttrVal($name,'remoteServer','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);
|
||||||
readingsBulkUpdateIfChanged( $hash, "deviceState", "unknown",1);
|
readingsBulkUpdateIfChanged( $hash, 'deviceState', 'unknown',1);
|
||||||
readingsEndUpdate($hash,1);
|
readingsEndUpdate($hash,1);
|
||||||
|
|
||||||
|
|
||||||
Log3 $name, 3, "AMADDevice ($name) - defined with AMAD_ID: $amad_id on port $hash->{PORT}";
|
Log3($name, 3, "AMADDevice ($name) - defined with AMAD_ID: $amad_id on port $hash->{PORT}");
|
||||||
|
|
||||||
|
|
||||||
$modules{AMADDevice}{defptr}{$amad_id} = $hash;
|
$modules{AMADDevice}{defptr}{$amad_id} = $hash;
|
||||||
@ -211,7 +227,7 @@ sub AMADDevice_Define($$) {
|
|||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMADDevice_Undef($$) {
|
sub Undef($$) {
|
||||||
|
|
||||||
my ( $hash, $arg ) = @_;
|
my ( $hash, $arg ) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
@ -224,95 +240,93 @@ sub AMADDevice_Undef($$) {
|
|||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMADDevice_Attr(@) {
|
sub Attr(@) {
|
||||||
|
|
||||||
my ( $cmd, $name, $attrName, $attrVal ) = @_;
|
my ( $cmd, $name, $attrName, $attrVal ) = @_;
|
||||||
my $hash = $defs{$name};
|
my $hash = $defs{$name};
|
||||||
|
|
||||||
my $orig = $attrVal;
|
my $orig = $attrVal;
|
||||||
|
|
||||||
if( $attrName eq "remoteServer" ) {
|
if( $attrName eq 'remoteServer' ) {
|
||||||
if( $cmd eq "set" ) {
|
if( $cmd eq 'set' ) {
|
||||||
if( $attrVal eq "Automagic" ) {
|
if( $attrVal eq 'Automagic' ) {
|
||||||
$hash->{PORT} = 8090;
|
$hash->{PORT} = 8090;
|
||||||
Log3 $name, 3, "AMADDevice ($name) - set remoteServer to Automagic";
|
Log3($name, 3, "AMADDevice ($name) - set remoteServer to Automagic");
|
||||||
|
|
||||||
} elsif( $attrVal eq "Autoremote" ) {
|
} elsif( $attrVal eq 'Autoremote' ) {
|
||||||
$hash->{PORT} = 1817;
|
$hash->{PORT} = 1817;
|
||||||
Log3 $name, 3, "AMADDevice ($name) - set remoteServer to Autoremote";
|
Log3($name, 3, "AMADDevice ($name) - set remoteServer to Autoremote");
|
||||||
|
|
||||||
} elsif( $attrVal eq "TNES" ) {
|
} elsif( $attrVal eq 'TNES' ) {
|
||||||
$hash->{PORT} = 8765;
|
$hash->{PORT} = 8765;
|
||||||
Log3 $name, 3, "AMADDevice ($name) - set remoteServer to TNES";
|
Log3($name, 3, "AMADDevice ($name) - set remoteServer to TNES");
|
||||||
|
|
||||||
} elsif( $attrVal eq "other" ) {
|
} elsif( $attrVal eq 'other' ) {
|
||||||
$hash->{PORT} = 1111;
|
$hash->{PORT} = 1111;
|
||||||
Log3 $name, 3, "AMADDevice ($name) - set remoteServer to other";
|
Log3($name, 3, "AMADDevice ($name) - set remoteServer to other");
|
||||||
}
|
}
|
||||||
|
|
||||||
$hash->{DEF} = "$hash->{HOST} $hash->{AMAD_ID} $attrVal";
|
$hash->{DEF} = $hash->{HOST} . ' ' . $hash->{AMAD_ID} . ' ' . $attrVal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( $attrName eq "disable" ) {
|
elsif( $attrName eq 'disable' ) {
|
||||||
if( $cmd eq "set" ) {
|
if( $cmd eq 'set' ) {
|
||||||
if( $attrVal eq "0" ) {
|
if( $attrVal eq '0' ) {
|
||||||
readingsSingleUpdate ( $hash, "state", "active", 1 );
|
readingsSingleUpdate ( $hash, 'state', 'active', 1 );
|
||||||
Log3 $name, 3, "AMADDevice ($name) - enabled";
|
Log3($name, 3, "AMADDevice ($name) - enabled");
|
||||||
} else {
|
} else {
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
readingsSingleUpdate ( $hash, "state", "disabled", 1 );
|
readingsSingleUpdate ( $hash, 'state', 'disabled', 1 );
|
||||||
Log3 $name, 3, "AMADDevice ($name) - disabled";
|
Log3($name, 3, "AMADDevice ($name) - disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
readingsSingleUpdate ( $hash, "state", "active", 1 );
|
readingsSingleUpdate ( $hash, 'state', 'active', 1 );
|
||||||
Log3 $name, 3, "AMADDevice ($name) - enabled";
|
Log3($name, 3, "AMADDevice ($name) - enabled");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( $attrName eq "checkActiveTask" ) {
|
elsif( $attrName eq 'checkActiveTask' ) {
|
||||||
if( $cmd eq "del" ) {
|
if( $cmd eq 'del' ) {
|
||||||
CommandDeleteReading( undef, "$name checkActiveTask" );
|
CommandDeleteReading( undef, $name . ' checkActiveTask' );
|
||||||
}
|
}
|
||||||
|
|
||||||
Log3 $name, 3, "AMADDevice ($name) - $cmd $attrName $attrVal and run statusRequest";
|
Log3($name, 3, "AMADDevice ($name) - $cmd $attrName $attrVal and run statusRequest");
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( $attrName eq "setScreenlockPIN" ) {
|
elsif( $attrName eq 'setScreenlockPIN' ) {
|
||||||
if( $cmd eq "set" and $attrVal ) {
|
if( $cmd eq 'set' and $attrVal ) {
|
||||||
|
|
||||||
$attrVal = AMADDevice_encrypt($attrVal);
|
$attrVal = encrypt($attrVal);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
CommandDeleteReading( undef, "$name screenLock" );
|
CommandDeleteReading( undef, $name . ' screenLock' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( $attrName eq "setUserFlowState" ) {
|
elsif( $attrName eq 'setUserFlowState' ) {
|
||||||
if( $cmd eq "del" ) {
|
if( $cmd eq 'del' ) {
|
||||||
|
|
||||||
CommandDeleteReading( undef, "$name userFlowState" );
|
CommandDeleteReading( undef, $name . ' userFlowState' );
|
||||||
}
|
}
|
||||||
|
|
||||||
Log3 $name, 3, "AMADDevice ($name) - $cmd $attrName $attrVal and run statusRequest";
|
Log3($name, 3, "AMADDevice ($name) - $cmd $attrName $attrVal and run statusRequest");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( $cmd eq 'set' ) {
|
||||||
|
|
||||||
if( $cmd eq "set" ) {
|
|
||||||
if( $attrVal and $orig ne $attrVal ) {
|
if( $attrVal and $orig ne $attrVal ) {
|
||||||
|
|
||||||
$attr{$name}{$attrName} = $attrVal;
|
$attr{$name}{$attrName} = $attrVal;
|
||||||
return $attrName ." set to ". $attrVal if( $init_done );
|
return $attrName . ' set to ' . $attrVal if( $init_done );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMADDevice_Notify($$) {
|
sub Notify($$) {
|
||||||
|
|
||||||
my ($hash,$dev) = @_;
|
my ($hash,$dev) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
@ -324,7 +338,7 @@ sub AMADDevice_Notify($$) {
|
|||||||
return if (!$events);
|
return if (!$events);
|
||||||
|
|
||||||
|
|
||||||
AMADDevice_statusRequest($hash) if( (grep /^DELETEATTR.$name.setAPSSID$/,@{$events}
|
statusRequest($hash) if( (grep /^DELETEATTR.$name.setAPSSID$/,@{$events}
|
||||||
or grep /^ATTR.$name.setAPSSID.*/,@{$events}
|
or grep /^ATTR.$name.setAPSSID.*/,@{$events}
|
||||||
or grep /^DELETEATTR.$name.checkActiveTask$/,@{$events}
|
or grep /^DELETEATTR.$name.checkActiveTask$/,@{$events}
|
||||||
or grep /^ATTR.$name.checkActiveTask.*/,@{$events}
|
or grep /^ATTR.$name.checkActiveTask.*/,@{$events}
|
||||||
@ -332,19 +346,19 @@ sub AMADDevice_Notify($$) {
|
|||||||
or grep /^ATTR.$name.setUserFlowState.*/,@{$events})
|
or grep /^ATTR.$name.setUserFlowState.*/,@{$events})
|
||||||
and $init_done and $devname eq 'global' );
|
and $init_done and $devname eq 'global' );
|
||||||
|
|
||||||
AMADDevice_GetUpdate($hash) if( (grep /^DEFINED.$name$/,@{$events}
|
GetUpdate($hash) if( (grep /^DEFINED.$name$/,@{$events}
|
||||||
or grep /^INITIALIZED$/,@{$events}
|
or grep /^INITIALIZED$/,@{$events}
|
||||||
or grep /^MODIFIED.$name$/,@{$events})
|
or grep /^MODIFIED.$name$/,@{$events})
|
||||||
and $devname eq 'global' and $init_done );
|
and $devname eq 'global' and $init_done );
|
||||||
|
|
||||||
AMADDevice_checkDeviceState($hash) if( (grep /^DELETEATTR.$name.disable$/,@{$events}
|
checkDeviceState($hash) if( (grep /^DELETEATTR.$name.disable$/,@{$events}
|
||||||
or grep /^ATTR.$name.disable.0$/,@{$events})
|
or grep /^ATTR.$name.disable.0$/,@{$events})
|
||||||
and $devname eq 'global' and $init_done );
|
and $devname eq 'global' and $init_done );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMADDevice_GetUpdate($) {
|
sub GetUpdate($) {
|
||||||
|
|
||||||
my ( $hash ) = @_;
|
my ( $hash ) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
@ -355,19 +369,19 @@ sub AMADDevice_GetUpdate($) {
|
|||||||
|
|
||||||
if( $init_done and ( ReadingsVal( $name, "deviceState", "unknown" ) eq "unknown" or ReadingsVal( $name, "deviceState", "online" ) eq "online" ) and AttrVal( $name, "disable", 0 ) ne "1" and ReadingsVal( $bname, "fhemServerIP", "not set" ) ne "not set" ) {
|
if( $init_done and ( ReadingsVal( $name, "deviceState", "unknown" ) eq "unknown" or ReadingsVal( $name, "deviceState", "online" ) eq "online" ) and AttrVal( $name, "disable", 0 ) ne "1" and ReadingsVal( $bname, "fhemServerIP", "not set" ) ne "not set" ) {
|
||||||
|
|
||||||
AMADDevice_statusRequest($hash);
|
statusRequest($hash);
|
||||||
AMADDevice_checkDeviceState( $hash );
|
checkDeviceState( $hash );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
Log3 $name, 4, "AMADDevice ($name) - GetUpdate, FHEM or Device not ready yet";
|
Log3 $name, 4, "AMADDevice ($name) - GetUpdate, FHEM or Device not ready yet";
|
||||||
Log3 $name, 3, "AMADDevice ($bname) - GetUpdate, Please set $bname fhemServerIP <IP-FHEM> NOW!" if( ReadingsVal( $bname, "fhemServerIP", "none" ) eq "none" );
|
# Log3 $name, 3, "AMADDevice ($bname) - GetUpdate, Please set $bname fhemServerIP <IP-FHEM> NOW!" if( ReadingsVal( $bname, "fhemServerIP", "null" ) eq "null" );
|
||||||
|
|
||||||
InternalTimer( gettimeofday()+30, "AMADDevice_GetUpdate", $hash, 0 );
|
InternalTimer( gettimeofday()+30, "FHEM::AMADDevice::GetUpdate", $hash, 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMADDevice_statusRequest($) {
|
sub statusRequest($) {
|
||||||
|
|
||||||
my $hash = shift;
|
my $hash = shift;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
@ -384,7 +398,7 @@ sub AMADDevice_statusRequest($) {
|
|||||||
my $activetask = AttrVal( $name, "checkActiveTask", "none" );
|
my $activetask = AttrVal( $name, "checkActiveTask", "none" );
|
||||||
my $userFlowState = AttrVal( $name, "setUserFlowState", "none" );
|
my $userFlowState = AttrVal( $name, "setUserFlowState", "none" );
|
||||||
my $apssid = AttrVal( $name, "setAPSSID", "none" );
|
my $apssid = AttrVal( $name, "setAPSSID", "none" );
|
||||||
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};
|
||||||
|
|
||||||
@ -400,7 +414,7 @@ sub AMADDevice_statusRequest($) {
|
|||||||
Log3 $name, 5, "AMADDevice ($name) - IOWrite: $uri $method IODevHash=$hash->{IODev}";
|
Log3 $name, 5, "AMADDevice ($name) - IOWrite: $uri $method IODevHash=$hash->{IODev}";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMADDevice_WriteReadings($$) {
|
sub WriteReadings($$) {
|
||||||
|
|
||||||
my ( $hash, $decode_json ) = @_;
|
my ( $hash, $decode_json ) = @_;
|
||||||
|
|
||||||
@ -468,7 +482,7 @@ sub AMADDevice_WriteReadings($$) {
|
|||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMADDevice_Set($$@) {
|
sub Set($$@) {
|
||||||
|
|
||||||
my ($hash, $name, @aa) = @_;
|
my ($hash, $name, @aa) = @_;
|
||||||
my ($cmd, @args) = @aa;
|
my ($cmd, @args) = @aa;
|
||||||
@ -496,7 +510,7 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'ttsmsg' ) {
|
elsif( lc $cmd eq 'ttsmsg' ) {
|
||||||
my ($msg,$speed,$lang,$ttsmsgvol) = AMADDevice_CreateTtsMsgValue($hash,@args);
|
my ($msg,$speed,$lang,$ttsmsgvol) = CreateTtsMsgValue($hash,@args);
|
||||||
|
|
||||||
$path = "/fhem-amad/setCommands/ttsMsg?message=".urlEncode($msg)."&msgspeed=".$speed."&msglang=".$lang."&msgvol=".$ttsmsgvol;
|
$path = "/fhem-amad/setCommands/ttsMsg?message=".urlEncode($msg)."&msgspeed=".$speed."&msglang=".$lang."&msgvol=".$ttsmsgvol;
|
||||||
$method = "POST";
|
$method = "POST";
|
||||||
@ -518,7 +532,7 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'volume' or $cmd eq 'mute' or $cmd =~ 'volume[Down|Up]' ) {
|
elsif( lc $cmd eq 'volume' or $cmd eq 'mute' or $cmd =~ 'volume[Down|Up]' ) {
|
||||||
my $vol = AMADDevice_CreateVolumeValue($hash,$cmd,@args);
|
my $vol = CreateVolumeValue($hash,$cmd,@args);
|
||||||
|
|
||||||
$path = "/fhem-amad/setCommands/setVolume?volume=$vol";
|
$path = "/fhem-amad/setCommands/setVolume?volume=$vol";
|
||||||
$method = "POST";
|
$method = "POST";
|
||||||
@ -563,7 +577,7 @@ sub AMADDevice_Set($$@) {
|
|||||||
my $mod = join( " ", @args );
|
my $mod = join( " ", @args );
|
||||||
|
|
||||||
|
|
||||||
$path = AMADDevice_CreateScreenValue($hash,$mod);
|
$path = 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');
|
||||||
$method = "POST";
|
$method = "POST";
|
||||||
@ -616,7 +630,7 @@ sub AMADDevice_Set($$@) {
|
|||||||
|
|
||||||
elsif( lc $cmd eq 'statusrequest' ) {
|
elsif( lc $cmd eq 'statusrequest' ) {
|
||||||
|
|
||||||
AMADDevice_statusRequest($hash);
|
statusRequest($hash);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -668,7 +682,7 @@ sub AMADDevice_Set($$@) {
|
|||||||
elsif( lc $cmd eq 'changetobtdevice' ) {
|
elsif( lc $cmd eq 'changetobtdevice' ) {
|
||||||
my $swToBtDevice = join( " ", @args );
|
my $swToBtDevice = join( " ", @args );
|
||||||
|
|
||||||
my ($swToBtMac,$btDeviceOne,$btDeviceTwo) = AMADDevice_CreateChangeBtDeviceValue($hash,$swToBtDevice);
|
my ($swToBtMac,$btDeviceOne,$btDeviceTwo) = CreateChangeBtDeviceValue($hash,$swToBtDevice);
|
||||||
$path = "/fhem-amad/setCommands/setbtdevice?swToBtDeviceMac=".$swToBtMac."&btDeviceOne=".$btDeviceOne."&btDeviceTwo=".$btDeviceTwo;
|
$path = "/fhem-amad/setCommands/setbtdevice?swToBtDeviceMac=".$swToBtMac."&btDeviceOne=".$btDeviceOne."&btDeviceTwo=".$btDeviceTwo;
|
||||||
$method = "POST";
|
$method = "POST";
|
||||||
}
|
}
|
||||||
@ -806,7 +820,7 @@ sub AMADDevice_Set($$@) {
|
|||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMADDevice_Parse($$) {
|
sub Parse($$) {
|
||||||
|
|
||||||
my ($io_hash,$json) = @_;
|
my ($io_hash,$json) = @_;
|
||||||
my $name = $io_hash->{NAME};
|
my $name = $io_hash->{NAME};
|
||||||
@ -828,7 +842,7 @@ sub AMADDevice_Parse($$) {
|
|||||||
if( my $hash = $modules{AMADDevice}{defptr}{$amad_id} ) {
|
if( my $hash = $modules{AMADDevice}{defptr}{$amad_id} ) {
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
AMADDevice_WriteReadings($hash,$decode_json);
|
WriteReadings($hash,$decode_json);
|
||||||
Log3 $name, 4, "AMADDevice ($name) - find logical device: $hash->{NAME}";
|
Log3 $name, 4, "AMADDevice ($name) - find logical device: $hash->{NAME}";
|
||||||
|
|
||||||
return $hash->{NAME};
|
return $hash->{NAME};
|
||||||
@ -843,27 +857,27 @@ sub AMADDevice_Parse($$) {
|
|||||||
##################################
|
##################################
|
||||||
#### my little helpers ###########
|
#### my little helpers ###########
|
||||||
|
|
||||||
sub AMADDevice_checkDeviceState($) {
|
sub checkDeviceState($) {
|
||||||
|
|
||||||
my ( $hash ) = @_;
|
my ( $hash ) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
Log3 $name, 4, "AMADDevice ($name) - AMADDevice_checkDeviceState: run Check";
|
Log3 $name, 4, "AMADDevice ($name) - checkDeviceState: run Check";
|
||||||
|
|
||||||
|
|
||||||
if( ReadingsAge( $name, ".deviceState", 240 ) > 240 ) {
|
if( ReadingsAge( $name, ".deviceState", 240 ) > 240 ) {
|
||||||
|
|
||||||
AMADDevice_statusRequest( $hash ) if( $hash->{helper}{deviceStateErrorCounter} == 0 );
|
statusRequest( $hash ) if( $hash->{helper}{deviceStateErrorCounter} == 0 );
|
||||||
readingsSingleUpdate( $hash, "deviceState", "offline", 1 ) if( ReadingsAge( $name, ".deviceState", 300) > 300 and $hash->{helper}{deviceStateErrorCounter} > 0 and ReadingsVal($name,'deviceState','online') ne 'offline' );
|
readingsSingleUpdate( $hash, "deviceState", "offline", 1 ) if( ReadingsAge( $name, ".deviceState", 300) > 300 and $hash->{helper}{deviceStateErrorCounter} > 0 and ReadingsVal($name,'deviceState','online') ne 'offline' );
|
||||||
$hash->{helper}{deviceStateErrorCounter} = ( $hash->{helper}{deviceStateErrorCounter} + 1 );
|
$hash->{helper}{deviceStateErrorCounter} = ( $hash->{helper}{deviceStateErrorCounter} + 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
InternalTimer( gettimeofday()+240, "AMADDevice_checkDeviceState", $hash, 0 );
|
InternalTimer( gettimeofday()+240, "FHEM::AMADDevice::checkDeviceState", $hash, 0 );
|
||||||
|
|
||||||
Log3 $name, 4, "AMADDevice ($name) - AMADDevice_checkDeviceState: set new Timer";
|
Log3 $name, 4, "AMADDevice ($name) - checkDeviceState: set new Timer";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMADDevice_encrypt($) {
|
sub encrypt($) {
|
||||||
|
|
||||||
my ($decodedPIN) = @_;
|
my ($decodedPIN) = @_;
|
||||||
my $key = getUniqueId();
|
my $key = getUniqueId();
|
||||||
@ -880,7 +894,7 @@ sub AMADDevice_encrypt($) {
|
|||||||
return 'crypt:'. $encodedPIN;
|
return 'crypt:'. $encodedPIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMADDevice_decrypt($) {
|
sub decrypt($) {
|
||||||
|
|
||||||
my ($encodedPIN) = @_;
|
my ($encodedPIN) = @_;
|
||||||
my $key = getUniqueId();
|
my $key = getUniqueId();
|
||||||
@ -897,7 +911,7 @@ sub AMADDevice_decrypt($) {
|
|||||||
return $decodedPIN;
|
return $decodedPIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMADDevice_CreateVolumeValue($$@) {
|
sub CreateVolumeValue($$@) {
|
||||||
|
|
||||||
my ($hash,$cmd,@args) = @_;
|
my ($hash,$cmd,@args) = @_;
|
||||||
|
|
||||||
@ -942,7 +956,7 @@ sub AMADDevice_CreateVolumeValue($$@) {
|
|||||||
return $vol;
|
return $vol;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMADDevice_CreateTtsMsgValue($@) {
|
sub CreateTtsMsgValue($@) {
|
||||||
|
|
||||||
my ($hash,@args) = @_;
|
my ($hash,@args) = @_;
|
||||||
|
|
||||||
@ -970,7 +984,7 @@ sub AMADDevice_CreateTtsMsgValue($@) {
|
|||||||
return ($msg,$speed,$lang,$ttsmsgvol);
|
return ($msg,$speed,$lang,$ttsmsgvol);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMADDevice_CreateScreenValue($$) {
|
sub CreateScreenValue($$) {
|
||||||
|
|
||||||
my ($hash,$mod) = @_;
|
my ($hash,$mod) = @_;
|
||||||
|
|
||||||
@ -986,13 +1000,13 @@ sub AMADDevice_CreateScreenValue($$) {
|
|||||||
return "NO PIN"
|
return "NO PIN"
|
||||||
unless( AttrVal( $name, "setScreenlockPIN", "none" ) ne "none" );
|
unless( AttrVal( $name, "setScreenlockPIN", "none" ) ne "none" );
|
||||||
my $PIN = AttrVal( $name, "setScreenlockPIN", undef );
|
my $PIN = AttrVal( $name, "setScreenlockPIN", undef );
|
||||||
$PIN = AMADDevice_decrypt($PIN);
|
$PIN = decrypt($PIN);
|
||||||
|
|
||||||
return ("/fhem-amad/setCommands/screenlock?lockmod=".$mod."&lockPIN=".$PIN);
|
return ("/fhem-amad/setCommands/screenlock?lockmod=".$mod."&lockPIN=".$PIN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMADDevice_CreateChangeBtDeviceValue($$) {
|
sub CreateChangeBtDeviceValue($$) {
|
||||||
|
|
||||||
my ($hash,$swToBtDevice) = @_;
|
my ($hash,$swToBtDevice) = @_;
|
||||||
|
|
||||||
@ -1403,4 +1417,50 @@ sub AMADDevice_CreateChangeBtDeviceValue($$) {
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
=end html_DE
|
=end html_DE
|
||||||
|
|
||||||
|
=for :application/json;q=META.json 74_AMADDevice.pm
|
||||||
|
{
|
||||||
|
"abstract": "Integrates Android devices into FHEM and displays several settings",
|
||||||
|
"x_lang": {
|
||||||
|
"de": {
|
||||||
|
"abstract": "Integriert Android-Geräte in FHEM und zeigt verschiedene Einstellungen an"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"fhem-mod-device",
|
||||||
|
"fhem-core",
|
||||||
|
"Android",
|
||||||
|
"Tablet",
|
||||||
|
"Handy",
|
||||||
|
"AMAD"
|
||||||
|
],
|
||||||
|
"release_status": "stable",
|
||||||
|
"license": "GPL_2",
|
||||||
|
"author": [
|
||||||
|
"Marko Oldenburg <leongaultier@gmail.com>"
|
||||||
|
],
|
||||||
|
"x_fhem_maintainer": [
|
||||||
|
"CoolTux"
|
||||||
|
],
|
||||||
|
"x_fhem_maintainer_github": [
|
||||||
|
"LeonGaultier"
|
||||||
|
],
|
||||||
|
"prereqs": {
|
||||||
|
"runtime": {
|
||||||
|
"requires": {
|
||||||
|
"FHEM": 5.00918799,
|
||||||
|
"perl": 5.016,
|
||||||
|
"Meta": 0,
|
||||||
|
"Encode": 0,
|
||||||
|
"JSON": 0
|
||||||
|
},
|
||||||
|
"recommends": {
|
||||||
|
},
|
||||||
|
"suggests": {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
=end :application/json;q=META.json
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
Loading…
x
Reference in New Issue
Block a user