clean code
This commit is contained in:
parent
6081c5e6c5
commit
0e6a9266b5
105
74_AMADDevice.pm
105
74_AMADDevice.pm
@ -79,6 +79,8 @@ sub AMADDevice_Parse($$);
|
|||||||
sub AMADDevice_statusRequest($);
|
sub AMADDevice_statusRequest($);
|
||||||
sub AMADDevice_CreateVolumeValue($$@);
|
sub AMADDevice_CreateVolumeValue($$@);
|
||||||
sub AMADDevice_CreateTtsMsgValue($@);
|
sub AMADDevice_CreateTtsMsgValue($@);
|
||||||
|
sub AMADDevice_CreateScreenValue($$);
|
||||||
|
sub AMADDevice_CreateChangeBtDeviceValue($$);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -447,7 +449,6 @@ 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) = AMADDevice_CreateTtsMsgValue($hash,@args);
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/ttsMsg?message=".urlEncode($msg)."&msgspeed=".$speed."&msglang=".$lang."&msgvol=".$ttsmsgvol;
|
$uri = $host . ":" . $port . "/fhem-amad/setCommands/ttsMsg?message=".urlEncode($msg)."&msgspeed=".$speed."&msglang=".$lang."&msgvol=".$ttsmsgvol;
|
||||||
@ -455,18 +456,14 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'userflowstate' ) {
|
elsif( lc $cmd eq 'userflowstate' ) {
|
||||||
|
|
||||||
my $datas = join( " ", @args );
|
my $datas = join( " ", @args );
|
||||||
my ($flow,$state) = split( ":", $datas);
|
my ($flow,$state) = split( ":", $datas);
|
||||||
|
|
||||||
$flow =~ s/\s/%20/g;
|
$uri = $host . ":" . $port . "/fhem-amad/setCommands/flowState?flowstate=".$state."&flowname=".urlEncode($flow);
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/flowState?flowstate=".$state."&flowname=".$flow;
|
|
||||||
$method = "POST";
|
$method = "POST";
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = AMADDevice_CreateVolumeValue($hash,$cmd,@args);
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setVolume?volume=$vol";
|
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setVolume?volume=$vol";
|
||||||
@ -474,7 +471,6 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'volumenotification' ) {
|
elsif( lc $cmd eq 'volumenotification' ) {
|
||||||
|
|
||||||
my $vol = join( " ", @args );
|
my $vol = join( " ", @args );
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setNotifiVolume?notifivolume=$vol";
|
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setNotifiVolume?notifivolume=$vol";
|
||||||
@ -482,7 +478,6 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'volumeringsound' ) {
|
elsif( lc $cmd eq 'volumeringsound' ) {
|
||||||
|
|
||||||
my $vol = join( " ", @args );
|
my $vol = join( " ", @args );
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setRingSoundVolume?ringsoundvolume=$vol";
|
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setRingSoundVolume?ringsoundvolume=$vol";
|
||||||
@ -490,7 +485,6 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd =~ /^media/ ) {
|
elsif( lc $cmd =~ /^media/ ) {
|
||||||
|
|
||||||
my $btn = join( " ", @args );
|
my $btn = join( " ", @args );
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/multimediaControl?mplayer=".$cmd."&button=".$btn;
|
$uri = $host . ":" . $port . "/fhem-amad/setCommands/multimediaControl?mplayer=".$cmd."&button=".$btn;
|
||||||
@ -498,7 +492,6 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'screenbrightness' ) {
|
elsif( lc $cmd eq 'screenbrightness' ) {
|
||||||
|
|
||||||
my $bri = join( " ", @args );
|
my $bri = join( " ", @args );
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setBrightness?brightness=$bri";
|
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setBrightness?brightness=$bri";
|
||||||
@ -506,26 +499,12 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'screen' ) {
|
elsif( lc $cmd eq 'screen' ) {
|
||||||
|
|
||||||
my $mod = join( " ", @args );
|
my $mod = join( " ", @args );
|
||||||
my $scot = AttrVal( $name, "setScreenOnForTimer", undef );
|
|
||||||
$scot = 60 if( !$scot );
|
|
||||||
|
|
||||||
if ($mod eq "on" || $mod eq "off") {
|
$uri = AMADDevice_CreateScreenValue($hash,$mod);
|
||||||
|
return "Please set \"setScreenlockPIN\" Attribut first"
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setScreenOnOff?screen=".$mod."&screenontime=".$scot if ($mod eq "on" || $mod eq "off");
|
unless($uri ne 'NO PIN');
|
||||||
$method = "POST";
|
$method = "POST";
|
||||||
}
|
|
||||||
|
|
||||||
elsif ($mod eq "lock" || $mod eq "unlock") {
|
|
||||||
|
|
||||||
return "Please set \"setScreenlockPIN\" Attribut first" if( AttrVal( $name, "setScreenlockPIN", "none" ) eq "none" );
|
|
||||||
my $PIN = AttrVal( $name, "setScreenlockPIN", undef );
|
|
||||||
$PIN = AMADDevice_decrypt($PIN);
|
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/screenlock?lockmod=".$mod."&lockPIN=".$PIN;
|
|
||||||
$method = "POST";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'screenorientation' ) {
|
elsif( lc $cmd eq 'screenorientation' ) {
|
||||||
@ -537,13 +516,11 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'activatevoiceinput' ) {
|
elsif( lc $cmd eq 'activatevoiceinput' ) {
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setvoicecmd";
|
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setvoicecmd";
|
||||||
$method = "POST";
|
$method = "POST";
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'screenfullscreen' ) {
|
elsif( lc $cmd eq 'screenfullscreen' ) {
|
||||||
|
|
||||||
my $mod = join( " ", @args );
|
my $mod = join( " ", @args );
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setScreenFullscreen?fullscreen=$mod";
|
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setScreenFullscreen?fullscreen=$mod";
|
||||||
@ -552,7 +529,6 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'openurl' ) {
|
elsif( lc $cmd eq 'openurl' ) {
|
||||||
|
|
||||||
my $openurl = join( " ", @args );
|
my $openurl = join( " ", @args );
|
||||||
my $browser = AttrVal( $name, "setOpenUrlBrowser", "com.android.chrome|com.google.android.apps.chrome.Main" );
|
my $browser = AttrVal( $name, "setOpenUrlBrowser", "com.android.chrome|com.google.android.apps.chrome.Main" );
|
||||||
my @browserapp = split( /\|/, $browser );
|
my @browserapp = split( /\|/, $browser );
|
||||||
@ -562,7 +538,6 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif (lc $cmd eq 'nextalarmtime') {
|
elsif (lc $cmd eq 'nextalarmtime') {
|
||||||
|
|
||||||
my $value = join( " ", @args );
|
my $value = join( " ", @args );
|
||||||
my @alarm = split( ":", $value );
|
my @alarm = split( ":", $value );
|
||||||
|
|
||||||
@ -571,7 +546,6 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif (lc $cmd eq 'timer') {
|
elsif (lc $cmd eq 'timer') {
|
||||||
|
|
||||||
my $timer = join( " ", @args );
|
my $timer = join( " ", @args );
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setTimer?minute=$timer";
|
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setTimer?minute=$timer";
|
||||||
@ -585,7 +559,6 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'openapp' ) {
|
elsif( lc $cmd eq 'openapp' ) {
|
||||||
|
|
||||||
my $app = join( " ", @args );
|
my $app = join( " ", @args );
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/openApp?app=".$app;
|
$uri = $host . ":" . $port . "/fhem-amad/setCommands/openApp?app=".$app;
|
||||||
@ -593,7 +566,6 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'nfc' ) {
|
elsif( lc $cmd eq 'nfc' ) {
|
||||||
|
|
||||||
my $mod = join( " ", @args );
|
my $mod = join( " ", @args );
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setnfc?nfc=".$mod;
|
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setnfc?nfc=".$mod;
|
||||||
@ -601,7 +573,6 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'system' ) {
|
elsif( lc $cmd eq 'system' ) {
|
||||||
|
|
||||||
my $systemcmd = join( " ", @args );
|
my $systemcmd = join( " ", @args );
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/systemcommand?syscmd=$systemcmd";
|
$uri = $host . ":" . $port . "/fhem-amad/setCommands/systemcommand?syscmd=$systemcmd";
|
||||||
@ -611,7 +582,6 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'donotdisturb' ) {
|
elsif( lc $cmd eq 'donotdisturb' ) {
|
||||||
|
|
||||||
my $disturbmod = join( " ", @args );
|
my $disturbmod = join( " ", @args );
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/donotdisturb?disturbmod=$disturbmod";
|
$uri = $host . ":" . $port . "/fhem-amad/setCommands/donotdisturb?disturbmod=$disturbmod";
|
||||||
@ -619,7 +589,6 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'bluetooth' ) {
|
elsif( lc $cmd eq 'bluetooth' ) {
|
||||||
|
|
||||||
my $mod = join( " ", @args );
|
my $mod = join( " ", @args );
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setbluetooth?bluetooth=$mod";
|
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setbluetooth?bluetooth=$mod";
|
||||||
@ -627,7 +596,6 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'notifysndfile' ) {
|
elsif( lc $cmd eq 'notifysndfile' ) {
|
||||||
|
|
||||||
my $notify = join( " ", @args );
|
my $notify = join( " ", @args );
|
||||||
my $filepath = AttrVal( $name, "setNotifySndFilePath", "/storage/emulated/0/Notifications/" );
|
my $filepath = AttrVal( $name, "setNotifySndFilePath", "/storage/emulated/0/Notifications/" );
|
||||||
|
|
||||||
@ -636,20 +604,14 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'changetobtdevice' ) {
|
elsif( lc $cmd eq 'changetobtdevice' ) {
|
||||||
|
|
||||||
my $swToBtDevice = join( " ", @args );
|
my $swToBtDevice = join( " ", @args );
|
||||||
my @swToBtMac = split( /\|/, $swToBtDevice );
|
|
||||||
my $btDevices = AttrVal( $name, "setBluetoothDevice", "none" ) if( AttrVal( $name, "setBluetoothDevice", "none" ) ne "none" );
|
|
||||||
my @btDevice = split( ',', $btDevices );
|
|
||||||
my @btDeviceOne = split( /\|/, $btDevice[0] );
|
|
||||||
my @btDeviceTwo = split( /\|/, $btDevice[1] );
|
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setbtdevice?swToBtDeviceMac=".$swToBtMac[1]."&btDeviceOne=".$btDeviceOne[1]."&btDeviceTwo=".$btDeviceTwo[1];
|
my ($swToBtMac,$btDeviceOne,$btDeviceTwo) = AMADDevice_CreateChangeBtDeviceValue($hash,$swToBtDevice);
|
||||||
|
$uri = $host . ":" . $port . "/fhem-amad/setCommands/setbtdevice?swToBtDeviceMac=".$swToBtMac."&btDeviceOne=".$btDeviceOne."&btDeviceTwo=".$btDeviceTwo;
|
||||||
$method = "POST";
|
$method = "POST";
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'clearnotificationbar' ) {
|
elsif( lc $cmd eq 'clearnotificationbar' ) {
|
||||||
|
|
||||||
my $appname = join( " ", @args );
|
my $appname = join( " ", @args );
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/clearnotificationbar?app=$appname";
|
$uri = $host . ":" . $port . "/fhem-amad/setCommands/clearnotificationbar?app=$appname";
|
||||||
@ -669,7 +631,6 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'sendintent' ) {
|
elsif( lc $cmd eq 'sendintent' ) {
|
||||||
|
|
||||||
my $intentstring = join( " ", @args );
|
my $intentstring = join( " ", @args );
|
||||||
my ( $action, $exkey1, $exval1, $exkey2, $exval2 ) = split( "[ \t][ \t]*", $intentstring );
|
my ( $action, $exkey1, $exval1, $exkey2, $exval2 ) = split( "[ \t][ \t]*", $intentstring );
|
||||||
$exkey1 = "" if( !$exkey1 );
|
$exkey1 = "" if( !$exkey1 );
|
||||||
@ -682,7 +643,6 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'installflowsource' ) {
|
elsif( lc $cmd eq 'installflowsource' ) {
|
||||||
|
|
||||||
my $flowname = join( " ", @args );
|
my $flowname = join( " ", @args );
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/installFlow?flowname=$flowname";
|
$uri = $host . ":" . $port . "/fhem-amad/setCommands/installFlow?flowname=$flowname";
|
||||||
@ -690,7 +650,6 @@ sub AMADDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elsif( lc $cmd eq 'opencall' ) {
|
elsif( lc $cmd eq 'opencall' ) {
|
||||||
|
|
||||||
my $string = join( " ", @args );
|
my $string = join( " ", @args );
|
||||||
my ($callnumber, $time) = split( "[ \t][ \t]*", $string );
|
my ($callnumber, $time) = split( "[ \t][ \t]*", $string );
|
||||||
$time = "none" if( !$time );
|
$time = "none" if( !$time );
|
||||||
@ -721,10 +680,7 @@ sub AMADDevice_Set($$@) {
|
|||||||
my $string = join( " ", @args );
|
my $string = join( " ", @args );
|
||||||
my ($smsmessage, $smsnumber) = split( "\\|", $string );
|
my ($smsmessage, $smsnumber) = split( "\\|", $string );
|
||||||
|
|
||||||
$smsmessage =~ s/%/%25/g;
|
$uri = $host . ":" . $port . "/fhem-amad/setCommands/sendSms?smsmessage=".urlEncode($smsmessage)."&smsnumber=".$smsnumber;
|
||||||
$smsmessage =~ s/\s/%20/g;
|
|
||||||
|
|
||||||
$uri = $host . ":" . $port . "/fhem-amad/setCommands/sendSms?smsmessage=".$smsmessage."&smsnumber=".$smsnumber;
|
|
||||||
$method = "POST";
|
$method = "POST";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -914,6 +870,47 @@ sub AMADDevice_CreateTtsMsgValue($@) {
|
|||||||
return ($msg,$speed,$lang,$ttsmsgvol);
|
return ($msg,$speed,$lang,$ttsmsgvol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub AMADDevice_CreateScreenValue($$) {
|
||||||
|
|
||||||
|
my ($hash,$mod) = @_;
|
||||||
|
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
my $scot = AttrVal( $name, "setScreenOnForTimer", undef );
|
||||||
|
my $host = $hash->{HOST};
|
||||||
|
my $port = $hash->{PORT};
|
||||||
|
my $uri;
|
||||||
|
$scot = 60 if( !$scot );
|
||||||
|
|
||||||
|
if ($mod eq "on" or $mod eq "off") {
|
||||||
|
return ($host . ":" . $port . "/fhem-amad/setCommands/setScreenOnOff?screen=".$mod."&screenontime=".$scot);
|
||||||
|
}
|
||||||
|
|
||||||
|
elsif ($mod eq "lock" or $mod eq "unlock") {
|
||||||
|
return "NO PIN"
|
||||||
|
unless( AttrVal( $name, "setScreenlockPIN", "none" ) ne "none" );
|
||||||
|
my $PIN = AttrVal( $name, "setScreenlockPIN", undef );
|
||||||
|
$PIN = AMADDevice_decrypt($PIN);
|
||||||
|
|
||||||
|
return ($host . ":" . $port . "/fhem-amad/setCommands/screenlock?lockmod=".$mod."&lockPIN=".$PIN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub AMADDevice_CreateChangeBtDeviceValue($$) {
|
||||||
|
|
||||||
|
my ($hash,$swToBtDevice) = @_;
|
||||||
|
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
my @swToBtMac = split( /\|/, $swToBtDevice );
|
||||||
|
my $btDevices = AttrVal( $name, "setBluetoothDevice", "none" ) if( AttrVal( $name, "setBluetoothDevice", "none" ) ne "none" );
|
||||||
|
my @btDevice = split( ',', $btDevices );
|
||||||
|
my @btDeviceOne = split( /\|/, $btDevice[0] );
|
||||||
|
my @btDeviceTwo = split( /\|/, $btDevice[1] );
|
||||||
|
|
||||||
|
|
||||||
|
return($swToBtMac[1],$btDeviceOne[1],$btDeviceTwo[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user