diff --git a/fhem/CHANGED b/fhem/CHANGED
index 578b47669..925dd4dc5 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.
+ - change: 71_YAMAHA_NP: More secure FM frequency input
- feature: FHEMWEB/Event Monitor: optional FHEM Log monitor.
- feature: 50_Telegrambot: multiple contacts for send etc/removed depreacted
messageTo,sendImageTo,sendPhotoTo/allowunknowncontacts
diff --git a/fhem/FHEM/71_YAMAHA_NP.pm b/fhem/FHEM/71_YAMAHA_NP.pm
index 688d2f25d..8172414b1 100644
--- a/fhem/FHEM/71_YAMAHA_NP.pm
+++ b/fhem/FHEM/71_YAMAHA_NP.pm
@@ -5,16 +5,21 @@
# 71_YAMAHA_NP.pm
#
# An FHEM Perl module for controlling the Yamaha CD-Receiver CRX-N560(D)
-# (aka MCR-N560D) via Ethernet connection.
-# The module should also work with devices controlled by the
-# Yamaha Network Player App for *OS and Andr*id
-# (e.g. NP-S2000, CD-N500, CD-N301, R-N500, R-N301).
+# (aka MCR-N560D) via Ethernet.
#
-# Copyright by Radoslaw Watroba
-# (e-mail: ra666ack@googlemail.com)
+# The module might also work with devices such as
+# NP-S2000, CD-N500, CD-N301, R-N500, R-N301 controlled by the
+# Yamaha Network Player App.
#
-# Inspired by the 71_YAMAHA_AVR module by Markus Bloch
-# (e-mail: Notausstieg0309@googlemail.com)
+# *OS:
+# https://itunes.apple.com/us/app/network-player-controller-us/id467502483?mt=8
+#
+# Andr*id:
+# https://play.google.com/store/apps/details?id=com.yamaha.npcontroller
+#
+# Copyright by Radoslaw Watroba (ra666ack@googlemail.com)
+#
+# (Inspired by Markus Bloch and the module 71_YAMAHA_AVR)
#
# This file is part of fhem.
#
@@ -249,6 +254,8 @@ sub YAMAHA_NP_Set
Log3 $name, 5, "YAMAHA_NP ($name) - set ".join(" ", @a);
+ # Processing of incoming commands.
+
if($what eq "on")
{
YAMAHA_NP_SendCommand($hash, "On" ,$what, "On");
@@ -285,17 +292,17 @@ sub YAMAHA_NP_Set
}
else
{
- return "No inputs are avaible. Please try an statusUpdate.";
+ return "No inputs avaible. Please try an statusRequest.";
}
}
else
{
- return "input can only be used when device is powered on";
+ return "Switch device on first.";
}
}
else
{
- return $inputs_piped eq "" ? "No inputs are available. Please try an statusUpdate." : "No input parameter was given";
+ return $inputs_piped eq "" ? "No inputs available. Please try an statusRequest first." : "No input parameter given.";
}
}
elsif($what eq "mute")
@@ -319,7 +326,7 @@ sub YAMAHA_NP_Set
}
else
{
- return "mute can only used when device is powered on";
+ return "Switch device on in order to mute it.";
}
}
}
@@ -331,7 +338,7 @@ sub YAMAHA_NP_Set
}
else
{
- return "Dimmer value must be 1..3";
+ return "Dimmer value must be 1 .. 3";
}
}
elsif($what =~ /^(volumeStraight|volume|volumeUp|volumeDown)$/)
@@ -650,7 +657,7 @@ sub YAMAHA_NP_Set
}
elsif($what eq "timerVolume")
{
- # if lower than minimum VOLUMESTRAIGHTMIN or higher than max VOLUMESTRAIGHTMAX set target volume to the corresponding limts
+ # if lower than minimum VOLUMESTRAIGHTMIN or higher than max VOLUMESTRAIGHTMAX set target volume to the corresponding limits
if($a[2] >= $hash->{helper}{VOLUMESTRAIGHTMIN} and $a[2] <= $hash->{helper}{VOLUMESTRAIGHTMAX})
{
$hash->{helper}{timerVolume} = $a[2];
@@ -695,25 +702,47 @@ sub YAMAHA_NP_Set
}
}
elsif($what eq "tunerFMFrequency")
- {
- if ( $a[2] =~ /^[0-9,.E]+$/ ) # Check if value is numeric
- {
- if( $a[2] >= 87.50 and $a[2] <= 108.00)
- {
- my $frequency = $a[2];
- $frequency =~ s/\.//; # Remove decimal point
- YAMAHA_NP_SendCommand($hash, "".$frequency."<\/Freq><\/FM><\/Tuning><\/Play_Control><\/Tuner>", "tunerFMFrequency", $a[2]);
- }
- else
- {
- return "Frequency value must be in the range 87.50 ... 108.00 of the format (x)xx.xx"
- }
- }
- else
- {
- return "Frequency value must be numeric in the range 87.50 ... 108.00 of the format (x)xx.xx"
- }
- }
+ {
+ if(length($a[2]) <= 6 and length($a[2]) >= 5) # Check the string length (x)xx.xx
+ {
+ if ( $a[2] =~ /^[0-9,.E]+$/ ) # Check if value is numeric
+ {
+ if( $a[2] >= 87.50 and $a[2] <= 108.00) # Check if within the value range
+ {
+ if(substr($a[2], -3, 1) eq '.') # Check for decimal point
+ {
+ my $lastDigit = substr($a[2], -1, 1);
+ if(($lastDigit eq "0") or ($lastDigit eq "5"))
+ {
+ my $frequency = $a[2];
+ $frequency =~ s/\.//; # Remove decimal point
+ YAMAHA_NP_SendCommand($hash, "".$frequency."<\/Freq><\/FM><\/Tuning><\/Play_Control><\/Tuner>", "tunerFMFrequency", $a[2]);
+ }
+ else
+ {
+ return "Last digit must be '0' or '5'";
+ }
+ }
+ else
+ {
+ return "Missing decimal point. Accepted format (x)xx.xx"
+ }
+ }
+ else
+ {
+ return "Frequency value must be in the range 87.50 ... 108.00 of the format (x)xx.xx";
+ }
+ }
+ else
+ {
+ return "Frequency value must be numeric in the range 87.50 ... 108.00 of the format (x)xx.xx";
+ }
+ }
+ else
+ {
+ return "Frequency length must be 5 or 6 characters e.g. 89.50 or 108.00";
+ }
+ }
else
{
return $usage;
@@ -1369,7 +1398,7 @@ sub YAMAHA_NP_ParseResponse
readingsBulkUpdate($hash, "volume", YAMAHA_NP_volume_abs2rel($hash, $hash->{helper}{targetVolume}));
# New "volume"value: The CRX-N560D cannot provide the current volume in time after a volume change.
# Therefore updated locally.
- # Volume will be updated during the next timer loop.
+ # Volume will be updated during the next statusRequest timer loop.
}
}
@@ -1545,6 +1574,7 @@ sub YAMAHA_NP_html2txt
1;
=pod
+
=begin html
@@ -1675,7 +1705,6 @@ sub YAMAHA_NP_html2txt
volumeUp [<VOL_MIN>...<VOL_MAX>] - increases the volume by one device's absolute step. <VOL_MIN> and <VOL_MAX> are read and set from the device automatically.
volumeDown [<VOL_MIN>...<VOL_MAX>] - increases the volume by one device's absolute step. <VOL_MIN> and <VOL_MAX> are read and set from the device automatically.
-
A typical example is powering the device remotely and tuning the favourite radio station:
Add the following code into the fhem.cfg configuration file:
@@ -1701,7 +1730,6 @@ sub YAMAHA_NP_html2txt
It's a good idea to insert a 'sleep' instruction between each fhem commands due to internal processing time of the network player. During that time the following commands might be ignored...
-
Now the function can be called by typing the following line in the FHEM command line or by the notify-definitions:
@@ -1801,7 +1829,9 @@ sub YAMAHA_NP_html2txt
However, even if the standbyMode is set to "Eco" the device can be powered off. In that case it has to be switched on manually.
+
=end html
+
=begin html_DE
@@ -2048,5 +2078,7 @@ sub YAMAHA_NP_html2txt
Das Abschalten funktioniert auch standbyMode "Normal" Modus.
+
=end html_DE
+
=cut