1
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-05-07 22:29:19 +00:00

ENIGMA2: add new attribute wakeupCmd to define alternative commands to turn on a device in deep standby mode

git-svn-id: https://svn.fhem.de/fhem/trunk@9133 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2015-08-26 08:52:30 +00:00
parent c3076d5e15
commit ed045dba2a

View File

@ -24,7 +24,7 @@
# along with fhem. If not, see <http://www.gnu.org/licenses/>. # along with fhem. If not, see <http://www.gnu.org/licenses/>.
# #
# #
# Version: 1.4.4 # Version: 1.4.5
# #
# Major Version History: # Major Version History:
# - 1.4.0 - 2014-11-27 # - 1.4.0 - 2014-11-27
@ -83,7 +83,7 @@ sub ENIGMA2_Initialize($) {
$hash->{UndefFn} = "ENIGMA2_Undefine"; $hash->{UndefFn} = "ENIGMA2_Undefine";
$hash->{AttrList} = $hash->{AttrList} =
"https:0,1 http-method:GET,POST http-noshutdown:1,0 disable:0,1 bouquet-tv bouquet-radio timeout remotecontrol:standard,advanced,keyboard lightMode:0,1 macaddr:textField " "https:0,1 http-method:GET,POST http-noshutdown:1,0 disable:0,1 bouquet-tv bouquet-radio timeout remotecontrol:standard,advanced,keyboard lightMode:0,1 macaddr:textField wakeupCmd:textField "
. $readingFnAttributes; . $readingFnAttributes;
$data{RC_layout}{ENIGMA2_DreamMultimedia_DM500_DM800_SVG} = $data{RC_layout}{ENIGMA2_DreamMultimedia_DM500_DM800_SVG} =
@ -123,7 +123,7 @@ sub ENIGMA2_GetStatus($;$) {
InternalTimer( gettimeofday() + $interval, "ENIGMA2_GetStatus", $hash, 0 ); InternalTimer( gettimeofday() + $interval, "ENIGMA2_GetStatus", $hash, 0 );
return return
if ( defined( $attr{$name}{disable} ) && $attr{$name}{disable} == 1 ); if ( AttrVal( $name, "disable", 0 ) == 1 );
if ( !$update ) { if ( !$update ) {
ENIGMA2_SendCommand( $hash, "powerstate" ); ENIGMA2_SendCommand( $hash, "powerstate" );
@ -353,17 +353,27 @@ sub ENIGMA2_Set($@) {
elsif ( lc( $a[1] ) eq "on" ) { elsif ( lc( $a[1] ) eq "on" ) {
if ( $hash->{READINGS}{state}{VAL} eq "absent" ) { if ( $hash->{READINGS}{state}{VAL} eq "absent" ) {
Log3 $name, 3, "ENIGMA2 set $name " . $a[1] . " (wakeup)"; Log3 $name, 3, "ENIGMA2 set $name " . $a[1] . " (wakeup)";
my $wakeupCmd = AttrVal( $name, "wakeupCmd", "" );
my $macAddr =
AttrVal( $name, "macaddr", ReadingsVal( $name, "lanmac", "" ) );
if ( if ( $wakeupCmd ne "" ) {
( $wakeupCmd =~ s/\$DEVICE/$name/g;
defined( $hash->{READINGS}{lanmac}{VAL} ) $wakeupCmd =~ s/\$MACADDR/$macAddr/g;
&& $hash->{READINGS}{lanmac}{VAL} ne "-"
) if ( $wakeupCmd =~ s/^[ \t]*\{|\}[ \t]*$//g ) {
|| ( defined( $attr{$name}{macaddr} ) Log3 $name, 4,
&& $attr{$name}{macaddr} ne "" ) "ENIGMA2 executing wake-up command (Perl): $wakeupCmd";
) $result = eval $wakeupCmd;
{ }
$result = ENIGMA2_wake($hash); else {
Log3 $name, 4,
"ENIGMA2 executing wake-up command (fhem): $wakeupCmd";
$result = fhem $wakeupCmd;
}
}
elsif ( $macAddr ne "" && $macAddr ne "-" ) {
$result = ENIGMA2_wake( $name, $macAddr );
return "wake-up command sent"; return "wake-up command sent";
} }
else { else {
@ -2313,45 +2323,34 @@ sub ENIGMA2_Undefine($$) {
} }
################################### ###################################
sub ENIGMA2_wake ($) { sub ENIGMA2_wake ($$) {
my ($hash) = @_; my ( $name, $mac_addr ) = @_;
my $name = $hash->{NAME};
my $mac_addr =
( defined( $attr{$name}{macaddr} ) )
? $attr{$name}{macaddr}
: $hash->{READINGS}{lanmac}{VAL};
my $address; my $address;
my $port; my $port;
if ( $mac_addr ne "-" ) { if ( !defined $address ) { $address = '255.255.255.255' }
if ( !defined $address ) { $address = '255.255.255.255' } if ( !defined $port || $port !~ /^\d+$/ ) { $port = 9 }
if ( !defined $port || $port !~ /^\d+$/ ) { $port = 9 }
my $sock = new IO::Socket::INET( Proto => 'udp' ) my $sock = new IO::Socket::INET( Proto => 'udp' )
or die "socket : $!"; or die "socket : $!";
die "Can't create WOL socket" if ( !$sock ); die "Can't create WOL socket" if ( !$sock );
my $ip_addr = inet_aton($address); my $ip_addr = inet_aton($address);
my $sock_addr = sockaddr_in( $port, $ip_addr ); my $sock_addr = sockaddr_in( $port, $ip_addr );
$mac_addr =~ s/://g; $mac_addr =~ s/://g;
my $packet = my $packet =
pack( 'C6H*', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, $mac_addr x 16 ); pack( 'C6H*', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, $mac_addr x 16 );
setsockopt( $sock, SOL_SOCKET, SO_BROADCAST, 1 ) setsockopt( $sock, SOL_SOCKET, SO_BROADCAST, 1 )
or die "setsockopt : $!"; or die "setsockopt : $!";
Log3 $name, 4, Log3 $name, 4,
"ENIGMA2 $name: Waking up by sending Wake-On-Lan magic package to " "ENIGMA2 $name: Waking up by sending Wake-On-Lan magic package to "
. $mac_addr; . $mac_addr;
send( $sock, $packet, 0, $sock_addr ) or die "send : $!"; send( $sock, $packet, 0, $sock_addr ) or die "send : $!";
close($sock); close($sock);
}
else {
Log3 $name, 3,
"ENIGMA2 $name: Unknown MAC address. Please turn on device manually once.";
}
return 1; return;
} }
##################################### #####################################
@ -3141,6 +3140,9 @@ sub ENIGMA2_GetRemotecontrolCommand($) {
<li> <li>
<b>timeout</b> - Set different polling timeout in seconds (default=6) <b>timeout</b> - Set different polling timeout in seconds (default=6)
</li> </li>
<li>
<b>wakeupCmd</b> - Set a command to be executed when turning on an absent device. Can be an FHEM command or Perl command in {}. Available variables: ENIGMA2 device name -> $DEVICE, ENIGMA2 device MAC address -> $MACADDR (default=Wake-on-LAN)
</li>
</ul> </ul>
</div><br> </div><br>
<br> <br>