nixos-configs/devices/homie/modules/home-assistant/netdaemon/apps/Spotify/PauseUnpause/PauseUnpause.cs
matt1432 ce4f9c23ec
All checks were successful
Discord / discord commits (push) Has been skipped
feat(netd): add pause/unpause script
2024-12-02 11:03:43 -05:00

48 lines
1.4 KiB
C#

using System;
using HomeAssistantGenerated;
using NetDaemon.AppModel;
using NetDaemon.HassModel;
using NetDaemon.HassModel.Integration;
namespace NetDaemonConfig.Apps.Spotify.PauseUnpause
{
public record PauseUnpauseData(bool pause);
[NetDaemonApp]
public class PlaySong
{
public PlaySong(IHaContext ha, Services services)
{
ha.RegisterServiceCallBack<PauseUnpauseData>(
"spotify_pause_unpause",
(e) =>
{
try
{
if (e.pause)
{
services.Spotifyplus.PlayerMediaPause(
entityId: SpotifyTypes.DefaultEntityId,
deviceId: SpotifyTypes.DefaultDevId);
}
else
{
services.Spotifyplus.PlayerMediaResume(
entityId: SpotifyTypes.DefaultEntityId,
deviceId: SpotifyTypes.DefaultDevId);
}
}
catch (Exception error)
{
services.Notify.PersistentNotification(
message: error.Message,
title: "Erreur Spotify");
}
}
);
}
}
}