-
Notifications
You must be signed in to change notification settings - Fork 0
/
AwtrixPush.cs
43 lines (39 loc) · 1.31 KB
/
AwtrixPush.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using Serilog;
using System;
using System.Net;
using System.Net.Http;
using System.Text;
namespace GlobalMute
{
internal class AwtrixPush(string host, int indicator, string muteColor)
{
private readonly string host = host;
private readonly int indicator = indicator;
private readonly string muteColor = muteColor;
public void PostMuteStateToDisplay(bool status)
{
var url = host + "/api/indicator" + indicator;
HttpClient client = new HttpClient
{
BaseAddress = new Uri(url)
};
string color = "0";
if (status)
{
color = muteColor;
}
var content = new StringContent("{\"color\":\"" + color + "\"}", Encoding.UTF8, "application/json");
var result = client.PostAsync(url, content).Result;
if (result == null || result.StatusCode != HttpStatusCode.OK)
{
Log.Error("Error pushing to AWTRIX");
return;
}
Log.Information("AWTRIX Response: {Result}", result.Content.ReadAsStringAsync().Result);
if (result.Content.ReadAsStringAsync().Result != "OK")
{
Log.Error("Invalid AWTRIX response");
}
}
}
}