Skip to content

Commit

Permalink
Merge pull request #75 from eugeneniemand/NoMoqUnitTest
Browse files Browse the repository at this point in the history
No moq unit test
  • Loading branch information
eugeneniemand authored Jan 24, 2024
2 parents fe0b7d6 + b4ea95e commit 903df9f
Show file tree
Hide file tree
Showing 87 changed files with 21,637 additions and 10,660 deletions.
13 changes: 13 additions & 0 deletions .idea/.idea.netdaemon-app-template/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.netdaemon-app-template/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/.idea.netdaemon-app-template/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
global using NetDaemon.Extensions.Scheduler;
global using NetDaemon.HassModel.Entities;
global using NetDaemon.HassModel;
global using Niemand.Helpers;
global using NetDaemon.Helpers;
global using System.Threading;
global using System.Threading.Tasks;
11 changes: 8 additions & 3 deletions Helpers/Extentions.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
using System.Text;
using Microsoft.Extensions.DependencyInjection;
using Niemand;
using Niemand.Helpers;

namespace Niemand.Helpers;
namespace NetDaemon.Helpers;

public static class Extentions
{
private const int MustBeLessThan = 100000000; // 8 decimal digits

public static IServiceCollection AddGeneratedCode(this IServiceCollection serviceCollection)
public static IServiceCollection SetupDependencies(this IServiceCollection serviceCollection)
=> serviceCollection
.AddTransient<IEntities, Entities>()
.AddTransient<IServices, Services>()
.AddTransient<IAlexa, Alexa>()
.AddSingleton<IVoiceProvider, VoiceProvider>();
.AddSingleton<IVoiceProvider, VoiceProvider>()
.AddScoped<People>()
.AddSingleton<IServiceProvider>(sp => sp);


public static string GetFixedHash(this string s)
{
Expand Down
21 changes: 15 additions & 6 deletions Helpers/Notifications/Alexa.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ namespace Niemand.Helpers;

public class Alexa : IAlexa
{
public enum NotificationType
{
Prompt,
Announcement,
Tts
}

private readonly IDictionary<string, AlexaDeviceConfig> _devices;
private readonly IEntities _entities;
private readonly IHaContext _ha;
private readonly ILogger<Alexa> _logger;
private readonly Subject<Config> _messages = new();
private readonly IScheduler _scheduler;
private readonly IServices _services;
private readonly IVoiceProvider _voice;

private readonly Subject<PromptResponse> _promptResponses = new();
private readonly IScheduler _scheduler;
private readonly IServices _services;
private readonly IVoiceProvider _voice;


public Alexa(IHaContext ha, IEntities entities, IServices services, IScheduler scheduler, IVoiceProvider voice, IAppConfig<AlexaConfig> config, ILogger<Alexa> logger)
Expand Down Expand Up @@ -47,7 +56,7 @@ public void Announce(string mediaPlayer, string message) =>
public void Prompt(string mediaPlayer, string message, string eventId) =>
QueueNotification(new Config { Entity = mediaPlayer, Message = message, EventId = eventId }, "prompt");

public Subject<PromptResponse> PromptResponses { get; } = new();
public IObservable<PromptResponse> PromptResponses => _promptResponses;

public void TextToSpeech(Config config) =>
QueueNotification(config, "tts");
Expand Down Expand Up @@ -103,7 +112,7 @@ private async Task ProcessNotifications(IEnumerable<Config> cfgs)

foreach (var cfg in cfgs)
{
message += ( message != "" ? ",,,," : "" ) + cfg.Message;
message += ( message != "" ? ",,,and," : "" ) + cfg.Message;
entities = cfg.Entities;
notificationType = cfg.NotifyType;
eventId = cfg.EventId;
Expand Down Expand Up @@ -158,7 +167,7 @@ private void SetupResponseHandler(IHaContext haContext)
if (responseEvent?.Data == null) return;
if (responseEvent?.Data?.ResponsePersonId != null)
responseEvent.Data.ResponsePersonName = People[responseEvent.Data.ResponsePersonId].Name;
PromptResponses.OnNext(responseEvent.Data);
_promptResponses.OnNext(responseEvent.Data);
});
}

Expand Down
2 changes: 1 addition & 1 deletion Helpers/Notifications/AlexaConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public class AlexaConfig
{
public IDictionary<string, AlexaPeopleConfig> People { get; set; }
public IDictionary<string, AlexaDeviceConfig> Devices { get; set; }
public IDictionary<string, AlexaPeopleConfig> People { get; set; }
}
2 changes: 1 addition & 1 deletion Helpers/Notifications/AlexaDeviceConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Niemand.Helpers;
namespace NetDaemon.Helpers;

public class AlexaDeviceConfig
{
Expand Down
8 changes: 3 additions & 5 deletions Helpers/Notifications/IAlexa.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using System.Reactive.Subjects;

namespace Niemand.Helpers;
namespace Niemand.Helpers;

public interface IAlexa
{
public Dictionary<string, AlexaPeopleConfig> People { get; }
public IObservable<PromptResponse> PromptResponses { get; }
void Announce(Alexa.Config config);
void Announce(string mediaPlayer, string message);
void Prompt(string mediaPlayer, string message, string eventId);
void TextToSpeech(Alexa.Config config);
void TextToSpeech(string mediaPlayer, string message);
public Subject<PromptResponse> PromptResponses { get; }
public Dictionary<string, AlexaPeopleConfig> People { get; }
}
2 changes: 1 addition & 1 deletion Helpers/Notifications/IVoiceProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Niemand.Helpers;
namespace NetDaemon.Helpers;

public interface IVoiceProvider
{
Expand Down
2 changes: 1 addition & 1 deletion Helpers/Notifications/PromptResponse.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace Niemand.Helpers;
namespace NetDaemon.Helpers;

public record PromptResponse
{
Expand Down
2 changes: 1 addition & 1 deletion Helpers/Notifications/PromptResponseType.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace Niemand.Helpers;
namespace NetDaemon.Helpers;

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum PromptResponseType
Expand Down
2 changes: 1 addition & 1 deletion Helpers/Notifications/VoiceProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Niemand.Helpers;
namespace NetDaemon.Helpers;

public class VoiceProvider : IVoiceProvider
{
Expand Down
2 changes: 1 addition & 1 deletion Helpers/Shared.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Niemand.Helpers;
namespace NetDaemon.Helpers;

public static class Shared
{
Expand Down
Loading

0 comments on commit 903df9f

Please sign in to comment.