|
6 | 6 | using Netdaemon.Generated.Reactive; |
7 | 7 | using NetDaemon.Common; |
8 | 8 |
|
9 | | -public class BatteryManager : GeneratedAppBase //NetDaemonRxApp |
10 | | -// public class BatteryManager : NetDaemonRxApp |
| 9 | +namespace NStest |
11 | 10 | { |
12 | | - // private ISchedulerResult _schedulerResult; |
13 | | - private int numberOfRuns = 0; |
14 | 11 |
|
15 | | - public string? HelloWorldSecret { get; set; } |
16 | | - public override async Task InitializeAsync() |
| 12 | + /// <summary> cool multiple lines </summary> |
| 13 | + public class BatteryManager : GeneratedAppBase //NetDaemonRxApp |
| 14 | + // public class BatteryManager : NetDaemonRxApp |
17 | 15 | { |
18 | | - // Remote.Tvrummet.TurnOn(new {activity="TV"}); |
19 | | - // Log(Remote.Tvrummet.State); |
20 | | - // Log(Remote.Tvrummet.Area); |
21 | | - |
22 | | - // SetState("sensor.testing", "on", new { attributeobject = new { aobject = "hello" } }); |
23 | | - // RunEvery(TimeSpan.FromSeconds(5), () => Log("Hello world!")); |
24 | | - // RunDaily("13:00:00", () => Log("Hello world!")); |
25 | | - // RunIn(TimeSpan.FromSeconds(5), () => Entity("light.tomas_rum").TurnOn()); |
26 | | - // Entity("light.tomas_rum") |
27 | | - // .StateChanges |
28 | | - // .Subscribe(s => Log("Chanche {entity}", s.New.State)); |
29 | | - |
30 | | - // StateChanges |
31 | | - // .Where(e => e.New.EntityId.StartsWith("light.")) |
32 | | - // .Subscribe(e => |
33 | | - // { |
34 | | - // Log("Hello!"); |
35 | | - // }); |
36 | | - // EventChanges |
37 | | - // // .Where(e => e.Domain == "scene" && e.Event == "turn_on") |
38 | | - // .Subscribe(e => |
39 | | - // { |
40 | | - // Log("Hello!"); |
41 | | - // }, |
42 | | - // err => LogError(err, "Ohh nooo!"), |
43 | | - // () => Log("Ending event")); |
44 | | - |
45 | | - |
46 | | - |
47 | | - // Event("TEST_EVENT").Call(async (ev, data) => { Log("EVENT2!"); }).Execute(); |
48 | | - |
49 | | - // Scheduler.RunEvery(5000, () => { var x = 0; var z = 4 / x; return Task.CompletedTask; }); |
50 | | - // Entity("sun.sun").WhenStateChange(allChanges: true).Call((entityid, to, from) => throw new Exception("Test")).Execute(); |
51 | | - // var app = (GlobalApp)GetApp("global_app"); |
52 | | - |
53 | | - // Log($"The global app shows {app.SharedThing}"); |
54 | | - // int? test = null; |
55 | | - // bool testa = test.HasValue; |
56 | | - |
57 | | - // await this.LightEx().JulbelysningVardagsrumH.TurnOn().ExecuteAsync(); |
58 | | - // await this.MediaPlayerEx().PlexChromecast.Play().ExecuteAsync(); |
59 | | - // Scheduler.RunIn(TimeSpan.FromSeconds(10), async () => await DoTheMagic("s").ConfigureAwait(false)); |
60 | | - |
| 16 | + // private ISchedulerResult _schedulerResult; |
| 17 | + private int numberOfRuns = 0; |
| 18 | + |
| 19 | + public string? HelloWorldSecret { get; set; } |
| 20 | + public override async Task InitializeAsync() |
| 21 | + { |
| 22 | + // Remote.Tvrummet.TurnOn(new {activity="TV"}); |
| 23 | + // Log(Remote.Tvrummet.State); |
| 24 | + // Log(Remote.Tvrummet.Area); |
| 25 | + |
| 26 | + // SetState("sensor.testing", "on", new { attributeobject = new { aobject = "hello" } }); |
| 27 | + // RunEvery(TimeSpan.FromSeconds(5), () => Log("Hello world!")); |
| 28 | + // RunDaily("13:00:00", () => Log("Hello world!")); |
| 29 | + // RunIn(TimeSpan.FromSeconds(5), () => Entity("light.tomas_rum").TurnOn()); |
| 30 | + // Entity("light.tomas_rum") |
| 31 | + // .StateChanges |
| 32 | + // .Subscribe(s => Log("Chanche {entity}", s.New.State)); |
| 33 | + |
| 34 | + // StateChanges |
| 35 | + // .Where(e => e.New.EntityId.StartsWith("light.")) |
| 36 | + // .Subscribe(e => |
| 37 | + // { |
| 38 | + // Log("Hello!"); |
| 39 | + // }); |
| 40 | + // EventChanges |
| 41 | + // // .Where(e => e.Domain == "scene" && e.Event == "turn_on") |
| 42 | + // .Subscribe(e => |
| 43 | + // { |
| 44 | + // Log("Hello!"); |
| 45 | + // }, |
| 46 | + // err => LogError(err, "Ohh nooo!"), |
| 47 | + // () => Log("Ending event")); |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + // Event("TEST_EVENT").Call(async (ev, data) => { Log("EVENT2!"); }).Execute(); |
| 52 | + |
| 53 | + // Scheduler.RunEvery(5000, () => { var x = 0; var z = 4 / x; return Task.CompletedTask; }); |
| 54 | + // Entity("sun.sun").WhenStateChange(allChanges: true).Call((entityid, to, from) => throw new Exception("Test")).Execute(); |
| 55 | + // var app = (GlobalApp)GetApp("global_app"); |
| 56 | + |
| 57 | + // Log($"The global app shows {app.SharedThing}"); |
| 58 | + // int? test = null; |
| 59 | + // bool testa = test.HasValue; |
| 60 | + |
| 61 | + // await this.LightEx().JulbelysningVardagsrumH.TurnOn().ExecuteAsync(); |
| 62 | + // await this.MediaPlayerEx().PlexChromecast.Play().ExecuteAsync(); |
| 63 | + // Scheduler.RunIn(TimeSpan.FromSeconds(10), async () => await DoTheMagic("s").ConfigureAwait(false)); |
| 64 | + |
| 65 | + } |
| 66 | + |
| 67 | + // async Task DoTheMagic() |
| 68 | + // { |
| 69 | + // Log("WAITING FOR STATE"); |
| 70 | + // // await Entity("binary_sensor.vardagsrum_pir").DelayUntilStateChange(to: "on").Task; |
| 71 | + |
| 72 | + // var task = DelayUntilStateChange(new string[] { "binary_sensor.vardagsrum_pir" }, to: "on", from: "off"); |
| 73 | + |
| 74 | + // await task.Task; |
| 75 | + // Log("STATE IS COOL DAMN IT!!!"); |
| 76 | + |
| 77 | + // } |
| 78 | + // async Task DoTheMagic(string test) |
| 79 | + // { |
| 80 | + // Log("WAITING FOR STATE"); |
| 81 | + // // await Entity("binary_sensor.vardagsrum_pir").DelayUntilStateChange(to: "on").Task; |
| 82 | + |
| 83 | + // var task = DelayUntilStateChange(new string[] { "binary_sensor.vardagsrum_pir" }, to: "on", from: "off"); |
| 84 | + |
| 85 | + // await task.Task; |
| 86 | + // Log("STATE IS COOL DAMN IT!!!"); |
| 87 | + |
| 88 | + // } |
| 89 | + // bool doingWork = false; |
| 90 | + // private async Task DoWork() |
| 91 | + // { |
| 92 | + // if (doingWork) |
| 93 | + // return; |
| 94 | + |
| 95 | + // // Time to do work |
| 96 | + // Entity(Wh) |
| 97 | + // } |
| 98 | + |
| 99 | + [HomeAssistantServiceCall] |
| 100 | + public void CallMeFromHass(dynamic data) |
| 101 | + { |
| 102 | + Log("A call from hass! {data}", data); |
| 103 | + } |
61 | 104 | } |
62 | 105 |
|
63 | | - // async Task DoTheMagic() |
| 106 | + // public static class NotifyExtensions |
64 | 107 | // { |
65 | | - // Log("WAITING FOR STATE"); |
66 | | - // // await Entity("binary_sensor.vardagsrum_pir").DelayUntilStateChange(to: "on").Task; |
67 | | - |
68 | | - // var task = DelayUntilStateChange(new string[] { "binary_sensor.vardagsrum_pir" }, to: "on", from: "off"); |
69 | | - |
70 | | - // await task.Task; |
71 | | - // Log("STATE IS COOL DAMN IT!!!"); |
72 | | - |
| 108 | + // public static async Task NotifyMobile(this NetDaemonApp app, string mobileId, string title, string message) |
| 109 | + // { |
| 110 | + // var data = new Obj |
| 111 | + // { |
| 112 | + // ["title"] = title, |
| 113 | + // ["message"] = message |
| 114 | + // }; |
| 115 | + // await app.CallService("notify", mobileId, data, false); |
| 116 | + // } |
| 117 | + |
| 118 | + // public static async Task NotifyMobileThread(this NetDaemonApp app, string mobileId, string title, string message, string threadId) |
| 119 | + // { |
| 120 | + // var data = new Obj |
| 121 | + // { |
| 122 | + // ["title"] = title, |
| 123 | + // ["message"] = message, |
| 124 | + // ["data"] = new Obj |
| 125 | + // { |
| 126 | + // ["push"] = new Obj |
| 127 | + // { |
| 128 | + // ["thread-id"] = threadId |
| 129 | + // } |
| 130 | + // } |
| 131 | + // }; |
| 132 | + // await app.CallService("notify", mobileId, data, false); |
| 133 | + // } |
73 | 134 | // } |
74 | | - // async Task DoTheMagic(string test) |
75 | | - // { |
76 | | - // Log("WAITING FOR STATE"); |
77 | | - // // await Entity("binary_sensor.vardagsrum_pir").DelayUntilStateChange(to: "on").Task; |
78 | | - |
79 | | - // var task = DelayUntilStateChange(new string[] { "binary_sensor.vardagsrum_pir" }, to: "on", from: "off"); |
80 | 135 |
|
81 | | - // await task.Task; |
82 | | - // Log("STATE IS COOL DAMN IT!!!"); |
83 | | - |
84 | | - // } |
85 | | - // bool doingWork = false; |
86 | | - // private async Task DoWork() |
87 | | - // { |
88 | | - // if (doingWork) |
89 | | - // return; |
90 | | - |
91 | | - // // Time to do work |
92 | | - // Entity(Wh) |
93 | | - // } |
94 | | - |
95 | | - [HomeAssistantServiceCall] |
96 | | - public void CallMeFromHass(dynamic data) |
97 | | - { |
98 | | - Log("A call from hass! {data}", data); |
99 | | - } |
100 | 136 | } |
101 | | - |
102 | | -// public static class NotifyExtensions |
103 | | -// { |
104 | | -// public static async Task NotifyMobile(this NetDaemonApp app, string mobileId, string title, string message) |
105 | | -// { |
106 | | -// var data = new Obj |
107 | | -// { |
108 | | -// ["title"] = title, |
109 | | -// ["message"] = message |
110 | | -// }; |
111 | | -// await app.CallService("notify", mobileId, data, false); |
112 | | -// } |
113 | | - |
114 | | -// public static async Task NotifyMobileThread(this NetDaemonApp app, string mobileId, string title, string message, string threadId) |
115 | | -// { |
116 | | -// var data = new Obj |
117 | | -// { |
118 | | -// ["title"] = title, |
119 | | -// ["message"] = message, |
120 | | -// ["data"] = new Obj |
121 | | -// { |
122 | | -// ["push"] = new Obj |
123 | | -// { |
124 | | -// ["thread-id"] = threadId |
125 | | -// } |
126 | | -// } |
127 | | -// }; |
128 | | -// await app.CallService("notify", mobileId, data, false); |
129 | | -// } |
130 | | -// } |
|
0 commit comments