Skip to content

Commit c3d66de

Browse files
committed
updates deps and cleanup
1 parent f494252 commit c3d66de

File tree

13 files changed

+893
-810
lines changed

13 files changed

+893
-810
lines changed

mediocre.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1111
README.md = README.md
1212
EndProjectSection
1313
EndProject
14-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mediocre", "mediocre\mediocre.csproj", "{D77C1D23-0D05-4CE3-857D-47F03DE89BC0}"
14+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "mediocre", "mediocre\mediocre.csproj", "{D77C1D23-0D05-4CE3-857D-47F03DE89BC0}"
1515
EndProject
1616
Global
1717
GlobalSection(SolutionConfigurationPlatforms) = preSolution

mediocre/Device.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
namespace Mediocre {
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Threading.Tasks;
1+
namespace Mediocre;
62

7-
using YeelightAPI;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Threading.Tasks;
87

9-
public static class Device {
10-
public static async Task<IEnumerable<YeelightAPI.Device>> All(string? filter) {
11-
DeviceLocator.MaxRetryCount = 3;
12-
return await DeviceLocator.DiscoverAsync();
13-
}
8+
using YeelightAPI;
149

15-
public static async Task<IDeviceController> InitFirst(int port) {
16-
Log.Dbg($"looking for Yeelight devices...");
17-
DeviceLocator.MaxRetryCount = 3;
18-
var devices = await DeviceLocator.DiscoverAsync();
19-
Log.Dbg($"found {devices.Count()} devices.");
10+
public static class Device {
11+
public static async Task<IEnumerable<YeelightAPI.Device>> All(string? filter) {
12+
DeviceLocator.MaxRetryCount = 3;
13+
return await DeviceLocator.DiscoverAsync();
14+
}
15+
16+
public static async Task<IDeviceController> InitFirst(int port) {
17+
Log.Dbg($"looking for Yeelight devices...");
18+
DeviceLocator.MaxRetryCount = 3;
19+
var devices = await DeviceLocator.DiscoverAsync();
20+
Log.Dbg($"found {devices.Count()} devices.");
2021

21-
var device = devices.FirstOrDefault() ?? throw new InvalidOperationException("No device found.");
22-
device.OnError += Log.Err;
23-
device.OnNotificationReceived += Log.Dbg;
24-
Log.Dbg($"selected device {device}.");
22+
var device = devices.FirstOrDefault() ?? throw new InvalidOperationException("No device found.");
23+
device.OnError += Log.Err;
24+
device.OnNotificationReceived += Log.Dbg;
25+
Log.Dbg($"selected device {device}.");
2526

26-
await device.Connect().Log($"connecting to {device}.");
27-
await device.TurnOn().Log($"turning on {device}.");
28-
await device.StartMusicMode(port: port).Log($"activating music mode on {device}.");
27+
await device.Connect().Log($"connecting to {device}.");
28+
await device.TurnOn().Log($"turning on {device}.");
29+
await device.StartMusicMode(port: port).Log($"activating music mode on {device}.");
2930

30-
return device;
31-
}
31+
return device;
3232
}
3333
}

mediocre/Log.cs

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
1-
namespace Mediocre {
2-
using System;
3-
using System.Threading.Tasks;
1+
namespace Mediocre;
2+
using System;
3+
using System.Threading.Tasks;
44

5-
using Newtonsoft.Json;
5+
using Newtonsoft.Json;
66

7-
using YeelightAPI;
7+
using YeelightAPI;
88

9-
public static class Log {
10-
public static bool Verbose;
9+
public static class Log {
10+
public static bool Verbose;
1111

12-
public static void Msg(FormattableString msg) => Console.WriteLine(msg);
12+
public static void Msg(FormattableString msg) => Console.WriteLine(msg);
1313

14-
public static void Dbg(FormattableString msg) {
15-
if (!Verbose) return;
14+
public static void Dbg(FormattableString msg) {
15+
if (!Verbose) return;
1616

17-
using (ConsoleWith.FG(ConsoleColor.DarkGray))
18-
Console.WriteLine(msg);
19-
}
20-
21-
public static void Err(FormattableString msg) {
22-
using (ConsoleWith.FG(ConsoleColor.DarkRed))
23-
Console.WriteLine(msg);
24-
}
17+
using (ConsoleWith.FG(ConsoleColor.DarkGray))
18+
Console.WriteLine(msg);
19+
}
2520

26-
public static void Dbg(object sender, NotificationReceivedEventArgs e) {
27-
if (Verbose) Dbg($"device received: {JsonConvert.SerializeObject(e.Result)}");
28-
}
21+
public static void Err(FormattableString msg) {
22+
using (ConsoleWith.FG(ConsoleColor.DarkRed))
23+
Console.WriteLine(msg);
24+
}
2925

30-
public static void Err(object sender, UnhandledExceptionEventArgs e)
31-
=> Err($"device error: {e}");
26+
public static void Dbg(object sender, NotificationReceivedEventArgs e) {
27+
if (Verbose) Dbg($"device received: {JsonConvert.SerializeObject(e.Result)}");
3228
}
3329

34-
public static class CmdResultExt {
35-
public static async Task Log(this Task<bool> cmdResult, FormattableString msg) {
36-
if (await cmdResult)
37-
Mediocre.Log.Dbg(msg);
38-
else
39-
Mediocre.Log.Err($"{msg} failed.");
40-
}
30+
public static void Err(object sender, UnhandledExceptionEventArgs e)
31+
=> Err($"device error: {e}");
32+
}
33+
34+
public static class CmdResultExt {
35+
public static async Task Log(this Task<bool> cmdResult, FormattableString msg) {
36+
if (await cmdResult)
37+
Mediocre.Log.Dbg(msg);
38+
else
39+
Mediocre.Log.Err($"{msg} failed.");
4140
}
4241
}

0 commit comments

Comments
 (0)