2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-05-05 02:19:31 +00:00

FULLY: New commands for sound playback

git-svn-id: https://svn.fhem.de/fhem/trunk@17568 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
zap 2018-10-19 08:40:24 +00:00
parent 4573f6f224
commit 995823375f
2 changed files with 62 additions and 23 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # Do not insert empty lines here, update check depends on it.
- feature: 89_FULLY: New commands for sound playback and photo.
- bugfix: 74_XiaomiBTLESens: fix disableForTimer Problem after reboot - bugfix: 74_XiaomiBTLESens: fix disableForTimer Problem after reboot
- feature: 31_HUEDevice: added water reading for Xiaomi Aqara Water sensor - feature: 31_HUEDevice: added water reading for Xiaomi Aqara Water sensor
- bugfix: 73_GardenaSmartBridge/Device - bugfix: 73_GardenaSmartBridge/Device

View File

@ -1,6 +1,6 @@
############################################################################## ##############################################################################
# #
# 89_FULLY.pm 0.8 # 89_FULLY.pm 0.9
# #
# $Id$ # $Id$
# #
@ -35,9 +35,10 @@ sub FULLY_Abort ($);
sub FULLY_UpdateReadings ($$); sub FULLY_UpdateReadings ($$);
sub FULLY_Ping ($$); sub FULLY_Ping ($$);
my $FULLY_VERSION = "0.8"; my $FULLY_VERSION = "0.9";
my $FULLY_TIMEOUT = 4; my $FULLY_TIMEOUT = 4;
my $FULLY_POLL_INTERVAL = 3600; my $FULLY_POLL_INTERVAL = 3600;
my $FULLY_REQUIRED_VERSION = 1.27;
my $FULLY_FHEM_COMMAND = qq( my $FULLY_FHEM_COMMAND = qq(
function SendRequest(FHEM_Address, Devicename, Command) { function SendRequest(FHEM_Address, Devicename, Command) {
@ -93,15 +94,14 @@ sub FULLY_Define ($$)
$hash->{host} = $$a[2]; $hash->{host} = $$a[2];
$hash->{version} = $FULLY_VERSION; $hash->{version} = $FULLY_VERSION;
$hash->{onForTimer} = 'off'; $hash->{onForTimer} = 'off';
# $hash->{remoteAdmin} = '<html><a href="http://'.$hash->{host}.':2323">Remote Admin</a></html>';
$hash->{fully}{password} = $$a[3]; $hash->{fully}{password} = $$a[3];
$hash->{fully}{schedule} = 0; $hash->{fully}{schedule} = 0;
Log3 $name, 1, "FULLY: Version $FULLY_VERSION Opening device ".$hash->{host}; Log3 $name, 1, "FULLY: [$name] Version $FULLY_VERSION Opening device ".$hash->{host};
my $result = FULLY_GetDeviceInfo ($name); my $result = FULLY_GetDeviceInfo ($name);
if (!FULLY_UpdateReadings ($hash, $result)) { if (!FULLY_UpdateReadings ($hash, $result)) {
Log3 $name, 2, "FULLY: Update of device info failed"; Log3 $name, 2, "FULLY: [$name] Update of device info failed";
} }
if (@$a == 5) { if (@$a == 5) {
@ -130,7 +130,7 @@ sub FULLY_Attr ($@)
if ($attrval >= 10 && $attrval <= 86400) { if ($attrval >= 10 && $attrval <= 86400) {
my $curval = AttrVal ($name, 'pollInterval', $FULLY_POLL_INTERVAL); my $curval = AttrVal ($name, 'pollInterval', $FULLY_POLL_INTERVAL);
if ($attrval != $curval) { if ($attrval != $curval) {
Log3 $name, 2, "FULLY: Polling interval set to $attrval"; Log3 $name, 2, "FULLY: [$name] Polling interval set to $attrval";
RemoveInternalTimer ($hash); RemoveInternalTimer ($hash);
$hash->{nextUpdate} = strftime "%d.%m.%Y %H:%M:%S", localtime (time+$attrval); $hash->{nextUpdate} = strftime "%d.%m.%Y %H:%M:%S", localtime (time+$attrval);
InternalTimer (gettimeofday()+$attrval, "FULLY_UpdateDeviceInfo", $hash, 0); InternalTimer (gettimeofday()+$attrval, "FULLY_UpdateDeviceInfo", $hash, 0);
@ -218,17 +218,21 @@ sub FULLY_Set ($@)
my ($hash, $a, $h) = @_; my ($hash, $a, $h) = @_;
my $name = shift @$a; my $name = shift @$a;
my $opt = shift @$a; my $opt = shift @$a;
my $options = "brightness clearCache:noArg exit:noArg lock:noArg motionDetection:on,off ". my $options = "brightness photo:noArg clearCache:noArg exit:noArg lock:noArg motionDetection:on,off ".
"off:noArg on:noArg on-for-timer restart:noArg screenOffTimer screenSaver:start,stop ". "off:noArg on:noArg on-for-timer playSound restart:noArg screenOffTimer screenSaver:start,stop ".
"screenSaverTimer screenSaverURL speak startURL unlock:noArg url"; "screenSaverTimer screenSaverURL speak startURL stopSound:noArg unlock:noArg url ".
"volume";
my $response; my $response;
# Fully commands without argument # Fully commands without argument
my %cmds = ( my %cmds = (
"clearCache" => "clearCache", "clearCache" => "clearCache",
"exit" => "exitApp", "restart" => "restartApp", "photo" => "getCamshot",
"exit" => "exitApp",
"restart" => "restartApp",
"on" => "screenOn", "off" => "screenOff", "on" => "screenOn", "off" => "screenOff",
"lock" => "enabledLockedMode", "unlock" => "disableLockedMode" "lock" => "enabledLockedMode", "unlock" => "disableLockedMode",
"stopSound" => "stopSound"
); );
my $disable = AttrVal ($name, 'disable', 0); my $disable = AttrVal ($name, 'disable', 0);
@ -329,6 +333,22 @@ sub FULLY_Set ($@)
my $enctext = urlEncode ($text); my $enctext = urlEncode ($text);
$response = FULLY_Execute ($hash, "textToSpeech", { "text" => "$enctext" }, 1); $response = FULLY_Execute ($hash, "textToSpeech", { "text" => "$enctext" }, 1);
} }
elsif ($opt eq 'playSound') {
my $url = shift @$a;
my $loop = shift @$a;
$loop = defined ($loop) ? 'true' : 'false';
return "Usage: set $name playSound {url} [loop]" if (!defined ($url));
$response = FULLY_Execute ($hash, "playSound",
{ "url" => "$url", "loop" => "$loop"}, 1);
}
elsif ($opt eq 'volume') {
my $level = shift @$a;
my $stream = shift @$a;
return "Usage: set $name volume {level} {stream}"
if (!defined ($stream) || $level !~ /^[0-9]+$/ || $stream !~ /^[0-9]+$/);
$response = FULLY_Execute ($hash, "setAudioVolume",
{ "level" => "$level", "stream" => "$stream"}, 1);
}
elsif ($opt eq 'url') { elsif ($opt eq 'url') {
my $url = shift @$a; my $url = shift @$a;
my $cmd = defined ($url) ? "loadURL" : "loadStartURL"; my $cmd = defined ($url) ? "loadURL" : "loadStartURL";
@ -340,7 +360,7 @@ sub FULLY_Set ($@)
my $result = FULLY_ProcessDeviceInfo ($name, $response); my $result = FULLY_ProcessDeviceInfo ($name, $response);
if (!FULLY_UpdateReadings ($hash, $result)) { if (!FULLY_UpdateReadings ($hash, $result)) {
Log3 $name, 2, "FULLY: Command failed"; Log3 $name, 2, "FULLY: [$name] Command failed";
return "FULLY: Command failed"; return "FULLY: Command failed";
} }
@ -365,11 +385,11 @@ sub FULLY_Get ($@)
if ($opt eq 'info') { if ($opt eq 'info') {
my $result = FULLY_Execute ($hash, 'deviceInfo', undef, 1); my $result = FULLY_Execute ($hash, 'deviceInfo', undef, 1);
if (!defined ($result) || $result eq '') { if (!defined ($result) || $result eq '') {
Log3 $name, 2, "FULLY: Command failed"; Log3 $name, 2, "FULLY: [$name] Command failed";
return "FULLY: Command failed"; return "FULLY: Command failed";
} }
elsif ($response =~ /Wrong password/) { elsif ($response =~ /Wrong password/) {
Log3 $name, 2, "FULLY: Wrong password"; Log3 $name, 2, "FULLY: [$name] Wrong password";
return "FULLY: Wrong password"; return "FULLY: Wrong password";
} }
@ -386,7 +406,7 @@ sub FULLY_Get ($@)
elsif ($opt eq 'update') { elsif ($opt eq 'update') {
my $result = FULLY_GetDeviceInfo ($name); my $result = FULLY_GetDeviceInfo ($name);
if (!FULLY_UpdateReadings ($hash, $result)) { if (!FULLY_UpdateReadings ($hash, $result)) {
Log3 $name, 2, "FULLY: Command failed"; Log3 $name, 2, "FULLY: [$name] Command failed";
return "FULLY: Command failed"; return "FULLY: Command failed";
} }
} }
@ -428,7 +448,7 @@ sub FULLY_Execute ($$$$)
my $i = 0; my $i = 0;
while ($i <= $repeatCommand && (!defined ($response) || $response eq '')) { while ($i <= $repeatCommand && (!defined ($response) || $response eq '')) {
$response = GetFileFromURL ("$url&password=".$hash->{fully}{password}, $timeout); $response = GetFileFromURL ("$url&password=".$hash->{fully}{password}, $timeout);
Log3 $name, 4, "FULLY: HTTP response empty" if (defined ($response) && $response eq ''); Log3 $name, 4, "FULLY: [$name] HTTP response empty" if (defined ($response) && $response eq '');
$i++; $i++;
} }
@ -511,6 +531,10 @@ sub FULLY_ProcessDeviceInfo ($$)
elsif ($rn eq 'screen_status') { elsif ($rn eq 'screen_status') {
$parameters .= "|state=$rv"; $parameters .= "|state=$rv";
} }
elsif ($rn eq 'fully_version') {
Log3 $name, 1, "FULLY: [$name] Version of fully browser is $rv. Version $FULLY_REQUIRED_VERSION is required."
if ($rv < $FULLY_REQUIRED_VERSION);
}
$parameters .= "|$rn=$rv"; $parameters .= "|$rn=$rv";
} }
@ -535,10 +559,10 @@ sub FULLY_GotDeviceInfo ($)
my $rc = FULLY_UpdateReadings ($hash, $string); my $rc = FULLY_UpdateReadings ($hash, $string);
if (!$rc) { if (!$rc) {
Log3 $name, 2, "FULLY: Request timed out"; Log3 $name, 2, "FULLY: [$name] Request timed out";
if ($hash->{fully}{schedule} == 0) { if ($hash->{fully}{schedule} == 0) {
$hash->{fully}{schedule} += 1; $hash->{fully}{schedule} += 1;
Log3 $name, 2, "FULLY: Rescheduling in $timeout seconds."; Log3 $name, 2, "FULLY: [$name] Rescheduling in $timeout seconds.";
$pollInterval = $timeout; $pollInterval = $timeout;
} }
else { else {
@ -565,10 +589,10 @@ sub FULLY_Abort ($)
delete $hash->{fully}{bc} if (exists ($hash->{fully}{bc})); delete $hash->{fully}{bc} if (exists ($hash->{fully}{bc}));
Log3 $name, 2, "FULLY: request timed out"; Log3 $name, 2, "FULLY: [$name] request timed out";
if ($hash->{fully}{schedule} == 0) { if ($hash->{fully}{schedule} == 0) {
$hash->{fully}{schedule} += 1; $hash->{fully}{schedule} += 1;
Log3 $name, 2, "FULLY: Rescheduling in $timeout seconds."; Log3 $name, 2, "FULLY: [$name] Rescheduling in $timeout seconds.";
$pollInterval = $timeout; $pollInterval = $timeout;
} }
else { else {
@ -591,13 +615,13 @@ sub FULLY_UpdateReadings ($$)
my $rc = 1; my $rc = 1;
if (!defined ($result) || $result eq '') { if (!defined ($result) || $result eq '') {
Log3 $name, 2, "FULLY: empty response"; Log3 $name, 2, "FULLY: [$name] empty response";
return 0; return 0;
} }
my @parameters = split ('\|', $result); my @parameters = split ('\|', $result);
if (scalar (@parameters) == 0) { if (scalar (@parameters) == 0) {
Log3 $name, 2, "FULLY: empty response"; Log3 $name, 2, "FULLY: [$name] empty response";
return 0; return 0;
} }
@ -642,7 +666,7 @@ sub FULLY_Ping ($$)
$temp = qx(ping -c $count $host 2>&1); $temp = qx(ping -c $count $host 2>&1);
} }
Log3 $name, 4, "FULLY: Ping response = $temp" if (defined ($temp)); Log3 $name, 4, "FULLY: [$name] Ping response = $temp" if (defined ($temp));
sleep (1); sleep (1);
@ -696,6 +720,13 @@ sub FULLY_Ping ($$)
<li><b>set &lt;name&gt; on-for-timer [{ &lt;Seconds&gt; | <u>forever</u> | off }]</b><br/> <li><b>set &lt;name&gt; on-for-timer [{ &lt;Seconds&gt; | <u>forever</u> | off }]</b><br/>
Set timer for display. Default is forever. Set timer for display. Default is forever.
</li><br/> </li><br/>
<li><b>set &lt;name&gt; photo</b><br/>
Take a picture with device cam. Setting motion detection must be enabled. Picture
can be viewed in remote admin interface under device info.
</li><br/>
<li><b>set &lt;name&gt; playSound &lt;url&gt; [loop]</b><br/>
Play sound from URL.
</li><br/>
<li><b>set &lt;name&gt; restart</b><br/> <li><b>set &lt;name&gt; restart</b><br/>
Restart Fully. Restart Fully.
</li><br/> </li><br/>
@ -718,9 +749,16 @@ sub FULLY_Ping ($$)
<li><b>set &lt;name&gt; startURL &lt;URL&gt;</b><br/> <li><b>set &lt;name&gt; startURL &lt;URL&gt;</b><br/>
Show this URL when FULLY starts.<br/> Show this URL when FULLY starts.<br/>
</li><br/> </li><br/>
<li><b>set &lt;name&gt; stopSound</b><br/>
Stop playback of sound if playback has been started with option <i>loop</i>.
</li><br/>
<li><b>set &lt;name&gt; url [&lt;URL&gt;]</b><br/> <li><b>set &lt;name&gt; url [&lt;URL&gt;]</b><br/>
Navigate to <i>URL</i>. If no URL is specified navigate to start URL. Navigate to <i>URL</i>. If no URL is specified navigate to start URL.
</li><br/> </li><br/>
<li><b>set &lt;name&gt; volume &lt;level&gt; &lt;stream&gt;</b><br/>
Set audio volume. Range of parameter <i>level</i> is 0-100, range of parameter
<i>stream</i> is 1-10.
</li><br/>
</ul> </ul>
<br/> <br/>