mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
70_ENIGMA2: use readingsBulkUpdateIfChanged, fix tuner reading names, use 98_WOL.pm to handle WOL
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@12795 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
c2991de19c
commit
951b28f55b
@ -31,7 +31,6 @@ package main;
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
use IO::Socket;
|
|
||||||
use HttpUtils;
|
use HttpUtils;
|
||||||
use Encode;
|
use Encode;
|
||||||
|
|
||||||
@ -62,7 +61,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 ignoreState:0,1 macaddr:textField wakeupCmd: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 ignoreState:0,1 macaddr:textField wakeupCmd:textField WOL_useUdpBroadcast WOL_port WOL_mode:EW,UDP,BOTH "
|
||||||
. $readingFnAttributes;
|
. $readingFnAttributes;
|
||||||
|
|
||||||
$data{RC_layout}{ENIGMA2_DreamMultimedia_DM500_DM800_SVG} =
|
$data{RC_layout}{ENIGMA2_DreamMultimedia_DM500_DM800_SVG} =
|
||||||
@ -1033,8 +1032,7 @@ sub ENIGMA2_ReceiveCommand($$$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$presence = "absent";
|
$presence = "absent";
|
||||||
readingsBulkUpdate( $hash, "presence", $presence )
|
readingsBulkUpdateIfChanged( $hash, "presence", $presence );
|
||||||
if ( ReadingsVal( $name, "presence", "" ) ne $presence );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1042,8 +1040,7 @@ sub ENIGMA2_ReceiveCommand($$$) {
|
|||||||
# data received
|
# data received
|
||||||
elsif ($data) {
|
elsif ($data) {
|
||||||
$presence = "present";
|
$presence = "present";
|
||||||
readingsBulkUpdate( $hash, "presence", $presence )
|
readingsBulkUpdateIfChanged( $hash, "presence", $presence );
|
||||||
if ( ReadingsVal( $name, "presence", "" ) ne $presence );
|
|
||||||
|
|
||||||
if ( !defined($cmd) || $cmd eq "" ) {
|
if ( !defined($cmd) || $cmd eq "" ) {
|
||||||
Log3 $name, 4, "ENIGMA2 $name: RCV $service";
|
Log3 $name, 4, "ENIGMA2 $name: RCV $service";
|
||||||
@ -1422,20 +1419,12 @@ sub ENIGMA2_ReceiveCommand($$$) {
|
|||||||
if ( $return->{e2about}{$e2reading} eq "False"
|
if ( $return->{e2about}{$e2reading} eq "False"
|
||||||
|| $return->{e2about}{$e2reading} eq "True" )
|
|| $return->{e2about}{$e2reading} eq "True" )
|
||||||
{
|
{
|
||||||
if ( ReadingsVal( $name, $reading, "" ) ne
|
readingsBulkUpdateIfChanged( $hash, $reading,
|
||||||
lc( $return->{e2about}{$e2reading} ) )
|
lc( $return->{e2about}{$e2reading} ) );
|
||||||
{
|
|
||||||
readingsBulkUpdate( $hash, $reading,
|
|
||||||
lc( $return->{e2about}{$e2reading} ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ( ReadingsVal( $name, $reading, "" ) ne
|
readingsBulkUpdateIfChanged( $hash, $reading,
|
||||||
$return->{e2about}{$e2reading} )
|
$return->{e2about}{$e2reading} );
|
||||||
{
|
|
||||||
readingsBulkUpdate( $hash, $reading,
|
|
||||||
$return->{e2about}{$e2reading} );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# model
|
# model
|
||||||
@ -1449,8 +1438,7 @@ sub ENIGMA2_ReceiveCommand($$$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
readingsBulkUpdate( $hash, $reading, "-" )
|
readingsBulkUpdateIfChanged( $hash, $reading, "-" );
|
||||||
if ( ReadingsVal( $name, $reading, "" ) ne "-" );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1467,9 +1455,7 @@ sub ENIGMA2_ReceiveCommand($$$) {
|
|||||||
while ( $i < $arr_size ) {
|
while ( $i < $arr_size ) {
|
||||||
my $counter = $i + 1;
|
my $counter = $i + 1;
|
||||||
my $readingname = "hdd" . $counter . "_model";
|
my $readingname = "hdd" . $counter . "_model";
|
||||||
readingsBulkUpdate( $hash, $readingname,
|
readingsBulkUpdateIfChanged( $hash, $readingname,
|
||||||
$return->{e2about}{e2hddinfo}[$i]{model} )
|
|
||||||
if ( ReadingsVal( $name, $readingname, "" ) ne
|
|
||||||
$return->{e2about}{e2hddinfo}[$i]{model} );
|
$return->{e2about}{e2hddinfo}[$i]{model} );
|
||||||
|
|
||||||
$readingname = "hdd" . $counter . "_capacity";
|
$readingname = "hdd" . $counter . "_capacity";
|
||||||
@ -1499,9 +1485,7 @@ sub ENIGMA2_ReceiveCommand($$$) {
|
|||||||
Log3 $name, 5, "ENIGMA2 $name: single HDD detected";
|
Log3 $name, 5, "ENIGMA2 $name: single HDD detected";
|
||||||
|
|
||||||
my $readingname = "hdd1_model";
|
my $readingname = "hdd1_model";
|
||||||
readingsBulkUpdate( $hash, $readingname,
|
readingsBulkUpdateIfChanged( $hash, $readingname,
|
||||||
$return->{e2about}{e2hddinfo}{model} )
|
|
||||||
if ( ReadingsVal( $name, $readingname, "" ) ne
|
|
||||||
$return->{e2about}{e2hddinfo}{model} );
|
$return->{e2about}{e2hddinfo}{model} );
|
||||||
|
|
||||||
$readingname = "hdd1_capacity";
|
$readingname = "hdd1_capacity";
|
||||||
@ -1542,10 +1526,9 @@ sub ENIGMA2_ReceiveCommand($$$) {
|
|||||||
{
|
{
|
||||||
my $tuner_name = lc( $tuner->{name} );
|
my $tuner_name = lc( $tuner->{name} );
|
||||||
$tuner_name =~ s/\s/_/g;
|
$tuner_name =~ s/\s/_/g;
|
||||||
|
$tuner_name =~ s/[A-Za-z\/\d_\.-]/$1/g;
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, $tuner_name,
|
readingsBulkUpdateIfChanged( $hash, $tuner_name,
|
||||||
$tuner->{type} )
|
|
||||||
if ( ReadingsVal( $name, $tuner_name, "" ) ne
|
|
||||||
$tuner->{type} );
|
$tuner->{type} );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1562,9 +1545,7 @@ sub ENIGMA2_ReceiveCommand($$$) {
|
|||||||
lc( $return->{e2about}{e2tunerinfo}{e2nim}{name} );
|
lc( $return->{e2about}{e2tunerinfo}{e2nim}{name} );
|
||||||
$tuner_name =~ s/\s/_/g;
|
$tuner_name =~ s/\s/_/g;
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, $tuner_name,
|
readingsBulkUpdateIfChanged( $hash, $tuner_name,
|
||||||
$return->{e2about}{e2tunerinfo}{e2nim}{type} )
|
|
||||||
if ( ReadingsVal( $name, $tuner_name, "" ) ne
|
|
||||||
$return->{e2about}{e2tunerinfo}{e2nim}{type} );
|
$return->{e2about}{e2tunerinfo}{e2nim}{type} );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -1657,8 +1638,7 @@ sub ENIGMA2_ReceiveCommand($$$) {
|
|||||||
{
|
{
|
||||||
Log3 $name, 5,
|
Log3 $name, 5,
|
||||||
"ENIGMA2 $name: detected servicereference type: radio";
|
"ENIGMA2 $name: detected servicereference type: radio";
|
||||||
readingsBulkUpdate( $hash, "input", "radio" )
|
readingsBulkUpdateIfChanged( $hash, "input",
|
||||||
if ( ReadingsVal( $name, "input", "" ) ne
|
|
||||||
"radio" );
|
"radio" );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -1814,13 +1794,11 @@ sub ENIGMA2_ReceiveCommand($$$) {
|
|||||||
11 );
|
11 );
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, $reading, $timestring )
|
readingsBulkUpdateIfChanged( $hash, $reading,
|
||||||
if ( ReadingsVal( $name, $reading, "" ) ne
|
|
||||||
$timestring );
|
$timestring );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
readingsBulkUpdate( $hash, $reading, "-" )
|
readingsBulkUpdateIfChanged( $hash, $reading, "-" );
|
||||||
if ( ReadingsVal( $name, $reading, "" ) ne "-" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# next event
|
# next event
|
||||||
@ -1845,13 +1823,11 @@ sub ENIGMA2_ReceiveCommand($$$) {
|
|||||||
11 );
|
11 );
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, $reading, $timestring )
|
readingsBulkUpdateIfChanged( $hash, $reading,
|
||||||
if ( ReadingsVal( $name, $reading, "" ) ne
|
|
||||||
$timestring );
|
$timestring );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
readingsBulkUpdate( $hash, $reading, "-" )
|
readingsBulkUpdateIfChanged( $hash, $reading, "-" );
|
||||||
if ( ReadingsVal( $name, $reading, "" ) ne "-" );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2037,8 +2013,7 @@ sub ENIGMA2_ReceiveCommand($$$) {
|
|||||||
my $recordingsElementsCount = scalar( keys %recordings );
|
my $recordingsElementsCount = scalar( keys %recordings );
|
||||||
my $readingname;
|
my $readingname;
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "recordings", $recordingsElementsCount )
|
readingsBulkUpdateIfChanged( $hash, "recordings",
|
||||||
if ( ReadingsVal( $name, "recordings", "" ) ne
|
|
||||||
$recordingsElementsCount );
|
$recordingsElementsCount );
|
||||||
|
|
||||||
if ( $recordingsElementsCount > 0 ) {
|
if ( $recordingsElementsCount > 0 ) {
|
||||||
@ -2048,16 +2023,14 @@ sub ENIGMA2_ReceiveCommand($$$) {
|
|||||||
$i++;
|
$i++;
|
||||||
|
|
||||||
$readingname = "recordings" . $i . "_servicename";
|
$readingname = "recordings" . $i . "_servicename";
|
||||||
readingsBulkUpdate( $hash, $readingname,
|
readingsBulkUpdateIfChanged( $hash, $readingname, $2 )
|
||||||
$recordings{$i}{servicename} )
|
if ( $recordings{$i}{servicename} =~
|
||||||
if ( ReadingsVal( $name, $readingname, "" ) ne
|
/^(\[[\w=]+\])?([ \w\(\)]+)(\[[\w=\/]+\])?$/ );
|
||||||
$recordings{$i}{servicename} );
|
|
||||||
|
|
||||||
$readingname = "recordings" . $i . "_name";
|
$readingname = "recordings" . $i . "_name";
|
||||||
readingsBulkUpdate( $hash, $readingname,
|
readingsBulkUpdateIfChanged( $hash, $readingname, $2 )
|
||||||
$recordings{$i}{name} )
|
if ( $recordings{$i}{name} =~
|
||||||
if ( ReadingsVal( $name, $readingname, "" ) ne
|
/^(\[[\w=]+\])?([ \w\(\)]+)(\[[\w=\/]+\])?$/ );
|
||||||
$recordings{$i}{name} );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2072,52 +2045,29 @@ sub ENIGMA2_ReceiveCommand($$$) {
|
|||||||
delete( $defs{$name}{READINGS}{$recReading} );
|
delete( $defs{$name}{READINGS}{$recReading} );
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "recordings_next", $recordingsNext_time )
|
readingsBulkUpdateIfChanged( $hash, "recordings_next",
|
||||||
if ( ReadingsVal( $name, "recordings_next", "" ) ne
|
|
||||||
$recordingsNext_time );
|
$recordingsNext_time );
|
||||||
|
readingsBulkUpdateIfChanged( $hash, "recordings_next_hr",
|
||||||
readingsBulkUpdate( $hash, "recordings_next_hr",
|
|
||||||
$recordingsNext_time_hr )
|
|
||||||
if ( ReadingsVal( $name, "recordings_next_hr", "" ) ne
|
|
||||||
$recordingsNext_time_hr );
|
$recordingsNext_time_hr );
|
||||||
|
readingsBulkUpdateIfChanged( $hash, "recordings_next_counter",
|
||||||
readingsBulkUpdate( $hash, "recordings_next_counter",
|
|
||||||
$recordingsNext_counter )
|
|
||||||
if ( ReadingsVal( $name, "recordings_next_counter", "" ) ne
|
|
||||||
$recordingsNext_counter );
|
$recordingsNext_counter );
|
||||||
|
readingsBulkUpdateIfChanged( $hash, "recordings_next_counter_hr",
|
||||||
readingsBulkUpdate( $hash, "recordings_next_counter_hr",
|
|
||||||
$recordingsNext_counter_hr )
|
|
||||||
if ( ReadingsVal( $name, "recordings_next_counter_hr", "" ) ne
|
|
||||||
$recordingsNext_counter_hr );
|
$recordingsNext_counter_hr );
|
||||||
|
readingsBulkUpdateIfChanged( $hash, "recordings_next_servicename",
|
||||||
readingsBulkUpdate( $hash, "recordings_next_servicename",
|
|
||||||
$recordingsNextServicename )
|
|
||||||
if ( ReadingsVal( $name, "recordings_next_servicename", "" ) ne
|
|
||||||
$recordingsNextServicename );
|
$recordingsNextServicename );
|
||||||
|
readingsBulkUpdateIfChanged( $hash, "recordings_next_name",
|
||||||
readingsBulkUpdate( $hash, "recordings_next_name",
|
|
||||||
$recordingsNextName )
|
|
||||||
if ( ReadingsVal( $name, "recordings_next_name", "" ) ne
|
|
||||||
$recordingsNextName );
|
$recordingsNextName );
|
||||||
|
readingsBulkUpdateIfChanged( $hash, "recordings_error",
|
||||||
readingsBulkUpdate( $hash, "recordings_error", $recordingsError )
|
|
||||||
if ( ReadingsVal( $name, "recordings_error", "" ) ne
|
|
||||||
$recordingsError );
|
$recordingsError );
|
||||||
|
readingsBulkUpdateIfChanged( $hash, "recordings_finished",
|
||||||
readingsBulkUpdate( $hash, "recordings_finished",
|
|
||||||
$recordingsFinished )
|
|
||||||
if ( ReadingsVal( $name, "recordings_finished", "" ) ne
|
|
||||||
$recordingsFinished );
|
$recordingsFinished );
|
||||||
}
|
}
|
||||||
|
|
||||||
# volume
|
# volume
|
||||||
elsif ( $service eq "vol" ) {
|
elsif ( $service eq "vol" ) {
|
||||||
if ( ref($return) eq "HASH" && defined( $return->{e2current} ) ) {
|
if ( ref($return) eq "HASH" && defined( $return->{e2current} ) ) {
|
||||||
readingsBulkUpdate( $hash, "volume", $return->{e2current} )
|
readingsBulkUpdateIfChanged( $hash, "volume",
|
||||||
if (
|
$return->{e2current} );
|
||||||
ReadingsVal( $name, "volume", "" ) ne $return->{e2current}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log3 $name, 5,
|
Log3 $name, 5,
|
||||||
@ -2128,8 +2078,7 @@ sub ENIGMA2_ReceiveCommand($$$) {
|
|||||||
my $muteState = "on";
|
my $muteState = "on";
|
||||||
$muteState = "off"
|
$muteState = "off"
|
||||||
if ( lc( $return->{e2ismuted} ) eq "false" );
|
if ( lc( $return->{e2ismuted} ) eq "false" );
|
||||||
readingsBulkUpdate( $hash, "mute", $muteState )
|
readingsBulkUpdateIfChanged( $hash, "mute", $muteState );
|
||||||
if ( ReadingsVal( $name, "mute", "" ) ne $muteState );
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log3 $name, 5,
|
Log3 $name, 5,
|
||||||
@ -2180,18 +2129,15 @@ sub ENIGMA2_ReceiveCommand($$$) {
|
|||||||
my $readingPower = "off";
|
my $readingPower = "off";
|
||||||
$readingPower = "on"
|
$readingPower = "on"
|
||||||
if ( $state eq "on" );
|
if ( $state eq "on" );
|
||||||
readingsBulkUpdate( $hash, "power", $readingPower )
|
readingsBulkUpdateIfChanged( $hash, "power", $readingPower );
|
||||||
if ( ReadingsVal( $name, "power", "" ) ne $readingPower );
|
|
||||||
|
|
||||||
# Set reading for state
|
# Set reading for state
|
||||||
#
|
#
|
||||||
readingsBulkUpdate( $hash, "state", $state )
|
readingsBulkUpdateIfChanged( $hash, "state", $state );
|
||||||
if ( ReadingsVal( $name, "state", "" ) ne $state );
|
|
||||||
|
|
||||||
# Set reading for stateAV
|
# Set reading for stateAV
|
||||||
my $stateAV = ENIGMA2_GetStateAV($hash);
|
my $stateAV = ENIGMA2_GetStateAV($hash);
|
||||||
readingsBulkUpdate( $hash, "stateAV", $stateAV )
|
readingsBulkUpdateIfChanged( $hash, "stateAV", $stateAV );
|
||||||
if ( ReadingsVal( $name, "stateAV", "-" ) ne $stateAV );
|
|
||||||
|
|
||||||
# Set ENIGMA2 online-only readings to "-" in case box is in
|
# Set ENIGMA2 online-only readings to "-" in case box is in
|
||||||
# offline or in standby mode
|
# offline or in standby mode
|
||||||
@ -2200,47 +2146,43 @@ sub ENIGMA2_ReceiveCommand($$$) {
|
|||||||
|| $state eq "undefined" )
|
|| $state eq "undefined" )
|
||||||
{
|
{
|
||||||
foreach my $reading (
|
foreach my $reading (
|
||||||
'servicename', 'providername',
|
'servicename', 'providername',
|
||||||
'servicereference', 'videowidth',
|
'servicereference', 'videowidth',
|
||||||
'videoheight', 'servicevideosize',
|
'videoheight', 'servicevideosize',
|
||||||
'apid', 'vpid',
|
'apid', 'vpid',
|
||||||
'pcrpid', 'pmtpid',
|
'pcrpid', 'pmtpid',
|
||||||
'txtpid', 'tsid',
|
'txtpid', 'tsid',
|
||||||
'onid', 'sid',
|
'onid', 'sid',
|
||||||
'iswidescreen', 'mute',
|
'iswidescreen', 'mute',
|
||||||
'volume', 'channel',
|
'channel', 'currentTitle',
|
||||||
'currentTitle', 'nextTitle',
|
'nextTitle', 'currentMedia',
|
||||||
'currentMedia', 'eventcurrenttime',
|
'eventcurrenttime', 'eventcurrenttime_hr',
|
||||||
'eventcurrenttime_hr', 'eventdescription',
|
'eventdescription', 'eventdescriptionextended',
|
||||||
'eventdescriptionextended', 'eventduration',
|
'eventduration', 'eventduration_hr',
|
||||||
'eventduration_hr', 'eventremaining',
|
'eventremaining', 'eventremaining_hr',
|
||||||
'eventremaining_hr', 'eventstart',
|
'eventstart', 'eventstart_hr',
|
||||||
'eventstart_hr', 'eventtitle',
|
'eventtitle', 'eventname',
|
||||||
'eventname', 'eventcurrenttime_next',
|
'eventcurrenttime_next', 'eventcurrenttime_next_hr',
|
||||||
'eventcurrenttime_next_hr', 'eventdescription_next',
|
'eventdescription_next', 'eventdescriptionextended_next',
|
||||||
'eventdescriptionextended_next', 'eventduration_next',
|
'eventduration_next', 'eventduration_next_hr',
|
||||||
'eventduration_next_hr', 'eventremaining_next',
|
'eventremaining_next', 'eventremaining_next_hr',
|
||||||
'eventremaining_next_hr', 'eventstart_next',
|
'eventstart_next', 'eventstart_next_hr',
|
||||||
'eventstart_next_hr', 'eventtitle_next',
|
'eventtitle_next', 'eventname_next',
|
||||||
'eventname_next',
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
readingsBulkUpdate( $hash, $reading, "-" )
|
readingsBulkUpdateIfChanged( $hash, $reading, "-" );
|
||||||
if ( ReadingsVal( $name, $reading, "" ) ne "-" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# special handling for signal values
|
# special handling for signal values
|
||||||
foreach my $reading ( 'acg', 'ber', 'snr', 'snrdb', ) {
|
foreach my $reading ( 'acg', 'ber', 'snr', 'snrdb', ) {
|
||||||
readingsBulkUpdate( $hash, $reading, "0" )
|
readingsBulkUpdateIfChanged( $hash, $reading, "0" );
|
||||||
if ( ReadingsVal( $name, $reading, "" ) ne "0" );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set ENIGMA2 online+standby readings to "-" in case box is in
|
# Set ENIGMA2 online+standby readings to "-" in case box is in
|
||||||
# offline mode
|
# offline mode
|
||||||
if ( $state eq "absent" || $state eq "undefined" ) {
|
if ( $state eq "absent" || $state eq "undefined" ) {
|
||||||
readingsBulkUpdate( $hash, "input", "-" )
|
readingsBulkUpdateIfChanged( $hash, "input", "-" );
|
||||||
if ( ReadingsVal( $name, "input", "" ) ne "-" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
@ -2286,33 +2228,33 @@ sub ENIGMA2_GetStateAV($) {
|
|||||||
|
|
||||||
###################################
|
###################################
|
||||||
sub ENIGMA2_wake ($$) {
|
sub ENIGMA2_wake ($$) {
|
||||||
my ( $name, $mac_addr ) = @_;
|
if ( !$modules{WOL}{LOADED} && -f "$attr{global}{modpath}/FHEM/98_WOL.pm" )
|
||||||
my $address;
|
{
|
||||||
my $port;
|
my $ret = CommandReload( undef, "98_WOL" );
|
||||||
|
return $ret if ($ret);
|
||||||
|
}
|
||||||
|
elsif ( !-f "$attr{global}{modpath}/FHEM/98_WOL.pm" ) {
|
||||||
|
return "Missing module: $attr{global}{modpath}/FHEM/98_WOL.pm";
|
||||||
|
}
|
||||||
|
|
||||||
if ( !defined $address ) { $address = '255.255.255.255' }
|
my ( $name, $mac ) = @_;
|
||||||
if ( !defined $port || $port !~ /^\d+$/ ) { $port = 9 }
|
my $hash = $defs{$name};
|
||||||
|
my $host =
|
||||||
my $sock = new IO::Socket::INET( Proto => 'udp' )
|
AttrVal( $name, "WOL_useUdpBroadcast",
|
||||||
or die "socket : $!";
|
AttrVal( $name, "useUdpBroadcast", "255.255.255.255" ) );
|
||||||
die "Can't create WOL socket" if ( !$sock );
|
my $port = AttrVal( $name, "WOL_port", "9" );
|
||||||
|
my $mode = AttrVal( $name, "WOL_mode", "BOTH" );
|
||||||
my $ip_addr = inet_aton($address);
|
|
||||||
my $sock_addr = sockaddr_in( $port, $ip_addr );
|
|
||||||
$mac_addr =~ s/://g;
|
|
||||||
my $packet =
|
|
||||||
pack( 'C6H*', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, $mac_addr x 16 );
|
|
||||||
|
|
||||||
setsockopt( $sock, SOL_SOCKET, SO_BROADCAST, 1 )
|
|
||||||
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;
|
||||||
send( $sock, $packet, 0, $sock_addr ) or die "send : $!";
|
|
||||||
close($sock);
|
|
||||||
|
|
||||||
return;
|
if ( $hash->{MODE} eq "BOTH" || $hash->{MODE} eq "EW" ) {
|
||||||
|
WOL_by_ew( $hash, $mac );
|
||||||
|
}
|
||||||
|
if ( $hash->{MODE} eq "BOTH" || $hash->{MODE} eq "UDP" ) {
|
||||||
|
WOL_by_udp( $hash, $mac, $host, $port );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
|
Loading…
x
Reference in New Issue
Block a user