2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

SONOS: New SubProcess-Alive checking, New Features

git-svn-id: https://svn.fhem.de/fhem/trunk@14546 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Reinerlein 2017-06-20 11:45:17 +00:00
parent d36ae0f429
commit 79f3cd1ceb
3 changed files with 564 additions and 277 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
########################################################################################
#
# SONOSPLAYER.pm (c) by Reiner Leins, Mai 2017
# SONOSPLAYER.pm (c) by Reiner Leins, Juni 2017
# rleins at lmsoft dot de
#
# $Id$
@ -348,11 +348,20 @@ sub SONOSPLAYER_Notify($$) {
my $events = deviceEvents($notifyhash, 1);
return if(!$events);
my $triggerCoverTitle = 0;
foreach my $event (@{$events}) {
next if(!defined($event));
# Wenn ein CoverTitle-Trigger gesendet werden muss...
if ($event =~ m/^(currentAlbumArtURL|currentTrackProviderIconRoundURL|currentTrackDuration|currentTrack|numberOfTracks|currentTitle|currentArtist|currentAlbum|nextAlbumArtURL|nextTrackProviderIconRoundURL|nextTitle|nextArtist|nextAlbum|currentSender|currentSenderInfo|currentSenderCurrent|transportState):/is) {
SONOSPLAYER_Log $hash->{NAME}, 5, 'Notify-CoverTitle: '.$event;
$triggerCoverTitle = 1;
}
# Wenn die Positionssimulation betroffen ist...
if ($event =~ m/transportState: (.+)/i) {
SONOSPLAYER_Log $hash->{NAME}, 5, 'Notify: '.$event;
SONOSPLAYER_Log $hash->{NAME}, 5, 'Notify-TransportState: '.$event;
if ($1 eq 'PLAYING') {
$hash->{helper}->{simulateCurrentTrackPosition} = AttrVal($hash->{NAME}, 'simulateCurrentTrackPosition', 0);
@ -362,11 +371,29 @@ sub SONOSPLAYER_Notify($$) {
$hash->{helper}->{simulateCurrentTrackPosition} = 0;
# Einmal noch etwas später aktualisieren...
InternalTimer(gettimeofday() + 0.1, 'SONOSPLAYER_SimulateCurrentTrackPosition', $hash, 0);
InternalTimer(gettimeofday() + 1, 'SONOSPLAYER_SimulateCurrentTrackPosition', $hash, 0);
}
}
}
if ($triggerCoverTitle) {
InternalTimer(gettimeofday(), 'SONOSPLAYER_TriggerCoverTitleLater', $notifyhash, 0);
}
return undef;
}
########################################################################################
#
# SONOSPLAYER_TriggerCoverTitleLater - Refreshs the CoverTitle-Element later via DoTrigger
#
########################################################################################
sub SONOSPLAYER_TriggerCoverTitleLater($) {
my ($hash) = @_;
my $html = SONOSPLAYER_Detail('', $hash->{NAME}, '', 0);
DoTrigger($hash->{NAME}, 'display_covertitle: '.$html, 1);
return undef;
}
@ -383,7 +410,13 @@ sub SONOSPLAYER_SimulateCurrentTrackPosition() {
readingsBeginUpdate($hash);
my $trackDurationSec = SONOS_GetTimeSeconds(ReadingsVal($hash->{NAME}, 'currentTrackDuration', 0)) - 1;
my $trackPositionSec = time - SONOS_GetTimeFromString(ReadingsTimestamp($hash->{NAME}, 'currentTrackPositionSec', 0)) + ReadingsVal($hash->{NAME}, 'currentTrackPositionSec', 0);
my $trackPositionSec = 0;
if (ReadingsVal($hash->{NAME}, 'transportState', 'STOPPED') eq 'PLAYING') {
$trackPositionSec = time - SONOS_GetTimeFromString(ReadingsTimestamp($hash->{NAME}, 'currentTrackPositionSec', 0)) + ReadingsVal($hash->{NAME}, 'currentTrackPositionSec', 0);
} else {
$trackPositionSec = ReadingsVal($hash->{NAME}, 'currentTrackPositionSec', 0);
}
readingsBulkUpdate($hash, 'currentTrackPositionSimulated', SONOS_ConvertSecondsToTime($trackPositionSec));
readingsBulkUpdate($hash, 'currentTrackPositionSimulatedSec', $trackPositionSec);

View File

@ -67,7 +67,7 @@ sub new {
$reuseport = 0 if (!defined($reuseport));
# Create the socket on which search requests go out
$self->{_searchSocket} = IO::Socket::INET->new(Proto => 'udp', LocalPort => $searchPort) || croak("Error creating search socket: $!\n");
$self->{_searchSocket} = IO::Socket::INET->new(Proto => 'udp', LocalPort => $searchPort) || carp("Error creating search socket: $!\n");
setsockopt($self->{_searchSocket},
IP_LEVEL,
IP_MULTICAST_TTL,
@ -76,7 +76,7 @@ sub new {
# Create the socket on which we'll listen for events to which we are
# subscribed.
$self->{_subscriptionSocket} = HTTP::Daemon->new(LocalPort => $subscriptionPort, Reuse=>1, Listen=>20) || croak("Error creating subscription socket: $!\n");
$self->{_subscriptionSocket} = HTTP::Daemon->new(LocalPort => $subscriptionPort, Reuse=>1, Listen=>20) || carp("Error creating subscription socket: $!\n");
$self->{_subscriptionURL} = $args{SubscriptionURL} || DEFAULT_SUBSCRIPTION_URL;
$self->{_subscriptionPort} = $self->{_subscriptionSocket}->sockport();;
@ -88,18 +88,19 @@ sub new {
Reuse => 1,
ReusePort => $reuseport,
LocalPort => SSDP_PORT) ||
carp("Error creating SSDP multicast listen socket: $!\n");
croak("Error creating SSDP multicast listen socket: $!\n");
};
if ($@ =~ /Your vendor has not defined Socket macro SO_REUSEPORT/i) {
$self->{_ssdpMulticastSocket} = IO::Socket::INET->new(
Proto => 'udp',
Reuse => 1,
LocalPort => SSDP_PORT) ||
carp("Error creating SSDP multicast listen socket: $!\n");
} else {
croak("Error creating SSDP multicast listen socket: $!\n");
} elsif($@) {
# Weiterwerfen...
carp($@);
croak($@);
}
my $ip_mreq = inet_aton(SSDP_IP) . INADDR_ANY;
setsockopt($self->{_ssdpMulticastSocket},
IP_LEVEL,
@ -768,7 +769,7 @@ sub unsubscribe {
}
else {
if ($response->code != 412) {
croak("Unsubscription request failed with error: " .
carp("Unsubscription request failed with error: " .
$response->code . " " . $response->message);
}
}
@ -1070,7 +1071,7 @@ sub renew {
$self->{_startTime} = Time::HiRes::time();
}
else {
croak("Renewal of subscription failed with error: " .
carp("Renewal of subscription failed with error: " .
$response->code . " " . $response->message);
}