nixos-configs/configurations/homie/modules/home-assistant/netdaemon/apps/Spotify/PauseUnpause/PauseUnpause.cs
matt1432 61dc9826b9
All checks were successful
Discord / discord commits (push) Has been skipped
feat(netd): improve album search
2024-12-18 19:25:22 -05:00

50 lines
1.5 KiB
C#

using System;
using HomeAssistantGenerated;
using NetDaemon.AppModel;
using NetDaemon.HassModel;
using NetDaemon.HassModel.Integration;
using NetDaemonConfig.Apps.Spotify.Types;
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: Globals.DefaultEntityId,
deviceId: Globals.DefaultDevId);
}
else
{
services.Spotifyplus.PlayerMediaResume(
entityId: Globals.DefaultEntityId,
deviceId: Globals.DefaultDevId);
}
}
catch (Exception error)
{
services.Notify.PersistentNotification(
message: error.Message,
title: "Erreur Spotify");
}
}
);
}
}
}