2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

70_BRAVIA.pm: new attribute wolBroadcast

git-svn-id: https://svn.fhem.de/fhem/trunk@20868 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
vuffiraa 2020-01-02 15:34:22 +00:00
parent 264c306b8e
commit d43f6a7bfe
2 changed files with 35 additions and 28 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: 70_BRAVIA: new attribute wolBroadcast used as address for WOL packet
- change: 74_XiaomiBTLESens: add special patch from charlie71 - change: 74_XiaomiBTLESens: add special patch from charlie71
- bugfix: 93_DbLog: fix behavior if value is empty and attribute - bugfix: 93_DbLog: fix behavior if value is empty and attribute
addStateEvent is set (default), Forum: #106769 addStateEvent is set (default), Forum: #106769

View File

@ -30,6 +30,8 @@ package main;
use strict; use strict;
use warnings; use warnings;
use vars qw( $readingFnAttributes );
################################### ###################################
sub BRAVIA_Initialize($) { sub BRAVIA_Initialize($) {
my ($hash) = @_; my ($hash) = @_;
@ -41,7 +43,7 @@ sub BRAVIA_Initialize($) {
$hash->{DefFn} = "BRAVIA::Define"; $hash->{DefFn} = "BRAVIA::Define";
$hash->{UndefFn} = "BRAVIA::Undefine"; $hash->{UndefFn} = "BRAVIA::Undefine";
$hash->{AttrList} = "disable:0,1 macaddr:textField channelsMax:textField " . $::readingFnAttributes; $hash->{AttrList} = "disable:0,1 macaddr:textField channelsMax:textField wolBroadcast:textField " . $readingFnAttributes;
$::data{RC_layout}{BRAVIA_SVG} = "BRAVIA::RClayout_SVG"; $::data{RC_layout}{BRAVIA_SVG} = "BRAVIA::RClayout_SVG";
$::data{RC_layout}{BRAVIA} = "BRAVIA::RClayout"; $::data{RC_layout}{BRAVIA} = "BRAVIA::RClayout";
@ -453,16 +455,21 @@ sub Set($@) {
elsif ( lc( $a[1] ) eq "remotecontrol" ) { elsif ( lc( $a[1] ) eq "remotecontrol" ) {
Log3($name, 2, "BRAVIA set $name " . $a[1] . " " . $a[2]); Log3($name, 2, "BRAVIA set $name " . $a[1] . " " . $a[2]);
if ( $presence eq "present" ) { if ( !defined( $a[2] ) ) {
if ( !defined( $a[2] ) ) { my $commandKeys = "";
my $commandKeys = ""; for (sort keys %{GetRemotecontrolCommand("GetRemotecontrolCommands")}) {
for (sort keys %{GetRemotecontrolCommand("GetRemotecontrolCommands")}) { $commandKeys = $commandKeys . " " . $_;
$commandKeys = $commandKeys . " " . $_;
}
return "No argument given, choose one of" . $commandKeys;
} }
return "No argument given, choose one of" . $commandKeys;
}
$cmd = uc( $a[2] );
$cmd = uc( $a[2] ); if ( $cmd eq "WOL" ) {
my $macAddr = AttrVal( $name, "macaddr", "" );
$macAddr = ReadingsVal( $name, "macAddr", "") if ($macAddr eq "");
wake( $name, $macAddr ) if ( $macAddr ne "" && $macAddr ne "-" );
}
elsif ( $presence eq "present" ) {
if ( $cmd eq "MUTE" ) { if ( $cmd eq "MUTE" ) {
Set( $hash, $name, "mute" ); Set( $hash, $name, "mute" );
@ -473,11 +480,6 @@ sub Set($@) {
elsif ( $cmd eq "CHANDOWN" ) { elsif ( $cmd eq "CHANDOWN" ) {
Set( $hash, $name, "channelDown" ); Set( $hash, $name, "channelDown" );
} }
elsif ( $cmd eq "WOL" ) {
my $macAddr = AttrVal( $name, "macaddr", "" );
$macAddr = ReadingsVal( $name, "macAddr", "") if ($macAddr eq "");
wake( $name, $macAddr ) if ( $macAddr ne "" && $macAddr ne "-" );
}
elsif ( $cmd ne "" ) { elsif ( $cmd ne "" ) {
SendCommand( $hash, "ircc", $cmd ); SendCommand( $hash, "ircc", $cmd );
} }
@ -597,15 +599,15 @@ sub Set($@) {
return "No 2nd argument given" if ( !defined( $a[2] ) ); return "No 2nd argument given" if ( !defined( $a[2] ) );
shift(@a); shift(@a); shift(@a); shift(@a);
my $appStr; my $appStr;
# Resolve app uri + data # Resolve app uri + data
my $app_name; my $app_name;
my $app_uri; my $app_uri;
my $app_data; my $app_data;
while (@a) { while (@a) {
my $arg = shift(@a); my $arg = shift(@a);
if (defined($appStr)) { if (defined($appStr)) {
$appStr .= "#"; $appStr .= "#";
$appStr .= $arg; $appStr .= $arg;
@ -617,7 +619,7 @@ sub Set($@) {
$app_uri = $hash->{helper}{device}{appPreset}{ $appStr }{uri}; $app_uri = $hash->{helper}{device}{appPreset}{ $appStr }{uri};
$app_data = join(" ", @a); $app_data = join(" ", @a);
} }
} }
return "Unknown app '" . $appStr . "' on that device." unless defined($app_uri); return "Unknown app '" . $appStr . "' on that device." unless defined($app_uri);
@ -748,8 +750,8 @@ sub Set($@) {
elsif ( $a[1] eq "text" ) { elsif ( $a[1] eq "text" ) {
return "No 2nd argument given" if ( !defined( $a[2] ) ); return "No 2nd argument given" if ( !defined( $a[2] ) );
shift(@a); shift(@a); shift(@a); shift(@a);
my $text = join(" ", @a); my $text = join(" ", @a);
Log3($name, 2, "BRAVIA set $name text $text"); Log3($name, 2, "BRAVIA set $name text $text");
SendCommand( $hash, "text", $text ); SendCommand( $hash, "text", $text );
@ -1197,7 +1199,7 @@ sub ReceiveCommand($$$) {
################################### ###################################
sub wake ($$) { sub wake ($$) {
my ( $name, $mac_addr ) = @_; my ( $name, $mac_addr ) = @_;
my $address = '255.255.255.255'; my $address = AttrVal($name, 'wolBroadcast', '255.255.255.255');
my $port = 9; my $port = 9;
my $sock = new IO::Socket::INET( Proto => 'udp' ) my $sock = new IO::Socket::INET( Proto => 'udp' )
@ -1213,7 +1215,7 @@ sub wake ($$) {
setsockopt( $sock, SOL_SOCKET, SO_BROADCAST, 1 ) setsockopt( $sock, SOL_SOCKET, SO_BROADCAST, 1 )
or die "setsockopt : $!"; or die "setsockopt : $!";
Log3($name, 4, "BRAVIA $name: Waking up by sending Wake-On-Lan magic package to $mac_addr"); Log3($name, 4, "BRAVIA $name: Waking up by sending Wake-On-Lan magic packet to $mac_addr");
send( $sock, $packet, 0, $sock_addr ) or die "send : $!"; send( $sock, $packet, 0, $sock_addr ) or die "send : $!";
close($sock); close($sock);
@ -2054,7 +2056,7 @@ sub GetRemotecontrolCommand($) {
return $commands; return $commands;
} }
else { else {
# return command itself if not mapped # return command itself if not mapped
return $command; return $command;
} }
} }
@ -2261,7 +2263,7 @@ sub GetNormalizedName($) {
<li><a name="stop"></a><i>stop</i><br> <li><a name="stop"></a><i>stop</i><br>
Stops recording, playing of an internal App, etc.</li> Stops recording, playing of an internal App, etc.</li>
<li><a name="text"></a><i>text</i><br> <li><a name="text"></a><i>text</i><br>
Includes the given text into an input field on display.</li> Includes the given text into an input field on display.</li>
<li><a name="toggle"></a><i>toggle</i><br> <li><a name="toggle"></a><i>toggle</i><br>
Toggles power status of TV.</li> Toggles power status of TV.</li>
<li><a name="tvpause"></a><i>tvpause</i><br> <li><a name="tvpause"></a><i>tvpause</i><br>
@ -2288,7 +2290,9 @@ sub GetNormalizedName($) {
<li><a name="channelsMax"></a><i>channelsMax</i><br> <li><a name="channelsMax"></a><i>channelsMax</i><br>
Maximum amount of channels to be displayed, default is 50.</li> Maximum amount of channels to be displayed, default is 50.</li>
<li><a name="macaddr"></a><i>macaddr</i><br> <li><a name="macaddr"></a><i>macaddr</i><br>
Enables power on of TV using WOL.</li> Enables power on of TV using Wake-On-Lan.</li>
<li><a name="wolBroadcast"></a><i>wolBroadcast</i><br>
Broadcast address for Wake-On-Lan magic packets, default is 255.255.255.255.</li>
</ul> </ul>
</ul> </ul>
</ul> </ul>
@ -2405,7 +2409,9 @@ sub GetNormalizedName($) {
<li><a name="channelsMax"></a><i>channelsMax</i><br> <li><a name="channelsMax"></a><i>channelsMax</i><br>
Maximale Anzahl der im FHEMWEB angezeigten Kanäle. Der Standartwert ist 50.</li> Maximale Anzahl der im FHEMWEB angezeigten Kanäle. Der Standartwert ist 50.</li>
<li><a name="macaddr"></a><i>macaddr</i><br> <li><a name="macaddr"></a><i>macaddr</i><br>
Ermöglicht das Einschalten des TV per WOL.</li> Ermöglicht das Einschalten des TV per Wake-On-Lan.</li>
<li><a name="wolBroadcast"></a><i>wolBroadcast</i><br>
Broadcast-Adresse für die Wake-On-Lan <i>Magic Packets</i>. Der Standartwert ist 255.255.255.255.</li>
</ul> </ul>
</ul> </ul>
</ul> </ul>