nixos-configs/configurations/homie/modules/home-assistant/netdaemon/apps/Spotify/PauseUnpause/PauseUnpause.cs

51 lines
1.5 KiB
C#
Raw Normal View History

2024-12-02 11:03:43 -05:00
using System;
using HomeAssistantGenerated;
using NetDaemon.AppModel;
using NetDaemon.HassModel;
using NetDaemon.HassModel.Integration;
2024-12-18 19:25:22 -05:00
using NetDaemonConfig.Apps.Spotify.Types;
2024-12-02 11:03:43 -05:00
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(
2024-12-18 19:25:22 -05:00
entityId: Globals.DefaultEntityId,
deviceId: Globals.DefaultDevId);
2024-12-02 11:03:43 -05:00
}
else
{
services.Spotifyplus.PlayerMediaResume(
2024-12-18 19:25:22 -05:00
entityId: Globals.DefaultEntityId,
deviceId: Globals.DefaultDevId);
2024-12-02 11:03:43 -05:00
}
}
catch (Exception error)
{
services.Notify.PersistentNotification(
message: error.Message,
title: "Erreur Spotify");
}
}
);
}
}
}