mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
37_Spotify: trigger events on readings
git-svn-id: https://svn.fhem.de/fhem/trunk@14416 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
dc0c3c12cb
commit
f01e98f87d
@ -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: 37_Spotify: trigger events on reading changes
|
||||||
- bugfix: 37_Spotify: fixed prototype warning
|
- bugfix: 37_Spotify: fixed prototype warning
|
||||||
- feature: 37_Spotify: first release
|
- feature: 37_Spotify: first release
|
||||||
- bugfix: 38_netatmo: fixed blocking connection check on dns error
|
- bugfix: 38_netatmo: fixed blocking connection check on dns error
|
||||||
|
@ -738,12 +738,12 @@ sub Spotify_dispatch($$$) {
|
|||||||
$hash->{helper}{uri} = $json->{uri};
|
$hash->{helper}{uri} = $json->{uri};
|
||||||
|
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
readingsBulkUpdateIfChanged($hash, 'user_id', $json->{id});
|
readingsBulkUpdateIfChanged($hash, 'user_id', $json->{id}, 1);
|
||||||
readingsBulkUpdateIfChanged($hash, 'user_country', $json->{country});
|
readingsBulkUpdateIfChanged($hash, 'user_country', $json->{country}, 1);
|
||||||
readingsBulkUpdateIfChanged($hash, 'user_subscription', $json->{subscription});
|
readingsBulkUpdateIfChanged($hash, 'user_subscription', $json->{subscription}, 1);
|
||||||
readingsBulkUpdateIfChanged($hash, 'user_display_name', $json->{display_name});
|
readingsBulkUpdateIfChanged($hash, 'user_display_name', $json->{display_name}, 1);
|
||||||
readingsBulkUpdateIfChanged($hash, 'user_profile_pic_url', $json->{images}[0]{url}) if(defined $json->{images} && $json->{images} > 0);
|
readingsBulkUpdateIfChanged($hash, 'user_profile_pic_url', $json->{images}[0]{url}, 1) if(defined $json->{images} && $json->{images} > 0);
|
||||||
readingsBulkUpdateIfChanged($hash, 'user_follower_cnt', $json->{followers}{total});
|
readingsBulkUpdateIfChanged($hash, 'user_follower_cnt', $json->{followers}{total}, 1);
|
||||||
readingsEndUpdate($hash, 1);
|
readingsEndUpdate($hash, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -772,10 +772,10 @@ sub Spotify_dispatch($$$) {
|
|||||||
foreach my $device (@{$hash->{helper}{devices}}) {
|
foreach my $device (@{$hash->{helper}{devices}}) {
|
||||||
foreach my $prefix (("device_". $index ."_", 'device_active_')) {
|
foreach my $prefix (("device_". $index ."_", 'device_active_')) {
|
||||||
if($prefix ne 'device_active_' || $device->{is_active}) {
|
if($prefix ne 'device_active_' || $device->{is_active}) {
|
||||||
readingsBulkUpdateIfChanged($hash, $prefix . 'id', $device->{id});
|
readingsBulkUpdateIfChanged($hash, $prefix . 'id', $device->{id}, 1);
|
||||||
readingsBulkUpdateIfChanged($hash, $prefix . 'name', $device->{name});
|
readingsBulkUpdateIfChanged($hash, $prefix . 'name', $device->{name}, 1);
|
||||||
readingsBulkUpdateIfChanged($hash, $prefix . 'type', $device->{type});
|
readingsBulkUpdateIfChanged($hash, $prefix . 'type', $device->{type}, 1);
|
||||||
readingsBulkUpdateIfChanged($hash, $prefix . 'volume', $device->{volume_percent});
|
readingsBulkUpdateIfChanged($hash, $prefix . 'volume', $device->{volume_percent}, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -783,7 +783,7 @@ sub Spotify_dispatch($$$) {
|
|||||||
$hash->{helper}{device_default} = $device if(defined $attr{$name}{defaultPlaybackDeviceID} && $device->{id} eq $attr{$name}{defaultPlaybackDeviceID}); # found users default device
|
$hash->{helper}{device_default} = $device if(defined $attr{$name}{defaultPlaybackDeviceID} && $device->{id} eq $attr{$name}{defaultPlaybackDeviceID}); # found users default device
|
||||||
$index++;
|
$index++;
|
||||||
}
|
}
|
||||||
readingsBulkUpdateIfChanged($hash, 'devices_cnt', $index-1);
|
readingsBulkUpdateIfChanged($hash, 'devices_cnt', $index-1, 1);
|
||||||
readingsEndUpdate($hash, 1);
|
readingsEndUpdate($hash, 1);
|
||||||
|
|
||||||
CommandDeleteReading(undef, "$name device_acitve_.*") if(!defined $hash->{helper}{device_active});
|
CommandDeleteReading(undef, "$name device_acitve_.*") if(!defined $hash->{helper}{device_active});
|
||||||
@ -804,10 +804,10 @@ sub Spotify_dispatch($$$) {
|
|||||||
$hash->{STATE} = $json->{is_playing} ? 'playing' : 'paused';
|
$hash->{STATE} = $json->{is_playing} ? 'playing' : 'paused';
|
||||||
|
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
readingsBulkUpdateIfChanged($hash, 'is_playing', $json->{is_playing} ne 'false' ? 1 : 0);
|
readingsBulkUpdateIfChanged($hash, 'is_playing', $json->{is_playing} ne 'false' ? 1 : 0, 1);
|
||||||
readingsBulkUpdateIfChanged($hash, 'shuffle', $json->{shuffle_state} ? 'on' : 'off');
|
readingsBulkUpdateIfChanged($hash, 'shuffle', $json->{shuffle_state} ? 'on' : 'off', 1);
|
||||||
readingsBulkUpdateIfChanged($hash, 'repeat', $hash->{helper}{repeat});
|
readingsBulkUpdateIfChanged($hash, 'repeat', $hash->{helper}{repeat}, 1);
|
||||||
readingsBulkUpdateIfChanged($hash, 'progress_ms', $json->{progress_ms});
|
readingsBulkUpdateIfChanged($hash, 'progress_ms', $json->{progress_ms}, 1);
|
||||||
|
|
||||||
if(defined $json->{item}) {
|
if(defined $json->{item}) {
|
||||||
my $item = $json->{item};
|
my $item = $json->{item};
|
||||||
@ -820,10 +820,10 @@ sub Spotify_dispatch($$$) {
|
|||||||
if(defined $json->{device} && $json->{device}{is_active}) {
|
if(defined $json->{device} && $json->{device}{is_active}) {
|
||||||
my $device = $json->{device};
|
my $device = $json->{device};
|
||||||
$hash->{helper}{device_active} = $device;
|
$hash->{helper}{device_active} = $device;
|
||||||
readingsBulkUpdateIfChanged($hash, 'device_active_id', $device->{id});
|
readingsBulkUpdateIfChanged($hash, 'device_active_id', $device->{id}, 1);
|
||||||
readingsBulkUpdateIfChanged($hash, 'device_active_name', $device->{name});
|
readingsBulkUpdateIfChanged($hash, 'device_active_name', $device->{name}, 1);
|
||||||
readingsBulkUpdateIfChanged($hash, 'device_active_volume', $device->{volume_percent});
|
readingsBulkUpdateIfChanged($hash, 'device_active_volume', $device->{volume_percent}, 1);
|
||||||
readingsBulkUpdateIfChanged($hash, 'device_active_type', $device->{type});
|
readingsBulkUpdateIfChanged($hash, 'device_active_type', $device->{type}, 1);
|
||||||
} else {
|
} else {
|
||||||
delete $hash->{helper}{device_active};
|
delete $hash->{helper}{device_active};
|
||||||
CommandDeleteReading(undef, "$name device_active_.*");
|
CommandDeleteReading(undef, "$name device_active_.*");
|
||||||
@ -877,25 +877,25 @@ sub Spotify_update($$) {
|
|||||||
sub Spotify_saveTrack($$$$) { # save a track object to the readings
|
sub Spotify_saveTrack($$$$) { # save a track object to the readings
|
||||||
my ($hash, $track, $prefix, $beginUpdate) = @_;
|
my ($hash, $track, $prefix, $beginUpdate) = @_;
|
||||||
readingsBeginUpdate($hash) if($beginUpdate);
|
readingsBeginUpdate($hash) if($beginUpdate);
|
||||||
readingsBulkUpdateIfChanged($hash, $prefix."_name", $track->{name});
|
readingsBulkUpdateIfChanged($hash, $prefix."_name", $track->{name}, 1);
|
||||||
readingsBulkUpdateIfChanged($hash, $prefix."_uri", $track->{uri});
|
readingsBulkUpdateIfChanged($hash, $prefix."_uri", $track->{uri}, 1);
|
||||||
readingsBulkUpdateIfChanged($hash, $prefix."_popularity", $track->{popularity});
|
readingsBulkUpdateIfChanged($hash, $prefix."_popularity", $track->{popularity}, 1);
|
||||||
readingsBulkUpdateIfChanged($hash, $prefix."_duration_ms", $track->{duration_ms});
|
readingsBulkUpdateIfChanged($hash, $prefix."_duration_ms", $track->{duration_ms}, 1);
|
||||||
readingsBulkUpdateIfChanged($hash, $prefix."_artist_name", $track->{artists}[0]{name});
|
readingsBulkUpdateIfChanged($hash, $prefix."_artist_name", $track->{artists}[0]{name}, 1);
|
||||||
readingsBulkUpdateIfChanged($hash, $prefix."_artist_uri", $track->{artists}[0]{uri});
|
readingsBulkUpdateIfChanged($hash, $prefix."_artist_uri", $track->{artists}[0]{uri}, 1);
|
||||||
readingsBulkUpdateIfChanged($hash, $prefix."_album_name", $track->{album}{name});
|
readingsBulkUpdateIfChanged($hash, $prefix."_album_name", $track->{album}{name}, 1);
|
||||||
readingsBulkUpdateIfChanged($hash, $prefix."_album_uri", $track->{album}{uri});
|
readingsBulkUpdateIfChanged($hash, $prefix."_album_uri", $track->{album}{uri}, 1);
|
||||||
readingsEndUpdate($hash, 1) if($beginUpdate);
|
readingsEndUpdate($hash, 1) if($beginUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub Spotify_saveArtist($$$$) { # save an artist object to the readings
|
sub Spotify_saveArtist($$$$) { # save an artist object to the readings
|
||||||
my ($hash, $artist, $prefix, $beginUpdate) = @_;
|
my ($hash, $artist, $prefix, $beginUpdate) = @_;
|
||||||
readingsBeginUpdate($hash) if($beginUpdate);
|
readingsBeginUpdate($hash) if($beginUpdate);
|
||||||
readingsBulkUpdate($hash, $prefix."_name", $artist->{name});
|
readingsBulkUpdate($hash, $prefix."_name", $artist->{name}, 1);
|
||||||
readingsBulkUpdate($hash, $prefix."_uri", $artist->{uri});
|
readingsBulkUpdate($hash, $prefix."_uri", $artist->{uri}, 1);
|
||||||
readingsBulkUpdate($hash, $prefix."_popularity", $artist->{popularity});
|
readingsBulkUpdate($hash, $prefix."_popularity", $artist->{popularity}, 1);
|
||||||
readingsBulkUpdate($hash, $prefix."_follower_cnt", $artist->{followers}{total});
|
readingsBulkUpdate($hash, $prefix."_follower_cnt", $artist->{followers}{total}, 1);
|
||||||
readingsBulkUpdate($hash, $prefix."_profile_pic_url", $artist->{images}[0]{url});
|
readingsBulkUpdate($hash, $prefix."_profile_pic_url", $artist->{images}[0]{url}, 1);
|
||||||
readingsEndUpdate($hash, 1) if($beginUpdate);
|
readingsEndUpdate($hash, 1) if($beginUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user