Skip to content

Commit

Permalink
Merge pull request #8 from amadeo-alex/development
Browse files Browse the repository at this point in the history
HotFix: Local API being enabled causing load process to hang
  • Loading branch information
amadeo-alex authored Nov 8, 2023
2 parents a2133ec + a03958f commit e05bb6a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace HASS.Agent.Shared.HomeAssistant.Commands.InternalCommands
public class SetVolumeCommand : InternalCommand
{
private const string DefaultName = "setvolume";
private static float _volume = -1f;
private readonly float _volume = -1f;

public SetVolumeCommand(string name = DefaultName, string friendlyName = DefaultName, string volume = "", CommandEntityType entityType = CommandEntityType.Button, string id = default) : base(name ?? DefaultName, friendlyName ?? null, volume, entityType, id)
{
Expand All @@ -43,10 +43,10 @@ public override void TurnOn()

try
{
// do we have a value to work with?
if (_volume == -1f)
{
Log.Warning("[SETVOLUME] [{name}] Unable to trigger command, it's configured as action-only", Name);

return;
}

Expand All @@ -55,10 +55,10 @@ public override void TurnOn()
if (audioDevice?.AudioEndpointVolume == null)
{
Log.Warning("[SETVOLUME] [{name}] Unable to trigger command, no default audio endpoint found", Name);

return;
}

// all good, set the volume
audioDevice.AudioEndpointVolume.MasterVolumeLevelScalar = _volume;
}
catch (Exception ex)
Expand All @@ -77,11 +77,11 @@ public override void TurnOnWithAction(string action)

try
{
// check if we got a valid number
var parsed = int.TryParse(action, out var volumeInt);
if (!parsed)
{
Log.Error("[SETVOLUME] [{name}] Unable to trigger command, the provided action value can't be parsed: {val}", Name, action);

return;
}

Expand All @@ -90,10 +90,10 @@ public override void TurnOnWithAction(string action)
if (audioDevice?.AudioEndpointVolume == null)
{
Log.Warning("[SETVOLUME] [{name}] Unable to trigger action for command, no default audio endpoint found", Name);

return;
}

// allg ood, set the volume
audioDevice.AudioEndpointVolume.MasterVolumeLevelScalar = volumeInt / 100.0f; ;
}
catch (Exception ex)
Expand Down
25 changes: 14 additions & 11 deletions src/HASS.Agent.Staging/HASS.Agent/Forms/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,20 @@ private async void Main_Load(object sender, EventArgs e)
// initialize managers
var initTask = Task.Run(async () =>
{
await Task.Run(ApiManager.Initialize);
await Task.Run(HassApiManager.InitializeAsync);
await Task.Run(Variables.MqttManager.Initialize);
await Task.Run(SensorsManager.Initialize);
await Task.Run(CommandsManager.Initialize);
await Task.Run(ServiceManager.Initialize);
await Task.Run(UpdateManager.Initialize);
await Task.Run(SystemStateManager.Initialize);
await Task.Run(CacheManager.Initialize);
await Task.Run(NotificationManager.Initialize);
await Task.Run(MediaManager.InitializeAsync);
_ = Task.Run(ApiManager.Initialize);
var hassApiTask = Task.Run(HassApiManager.InitializeAsync);
var mqttTask = Task.Run(Variables.MqttManager.Initialize);
var sensorTask = Task.Run(SensorsManager.Initialize);
var commandsTask = Task.Run(CommandsManager.Initialize);
var serviceTask = Task.Run(ServiceManager.Initialize);
var upateTask = Task.Run(UpdateManager.Initialize);
var systemStateTask = Task.Run(SystemStateManager.Initialize);
var cacheTask = Task.Run(CacheManager.Initialize);
var notificationTask = Task.Run(NotificationManager.Initialize);
var mediaTask = Task.Run(MediaManager.InitializeAsync);

await Task.WhenAll(hassApiTask, mqttTask, sensorTask, commandsTask, serviceTask,
upateTask, systemStateTask, cacheTask, notificationTask, mediaTask);
});

// handle activation from a previously generated notification
Expand Down

0 comments on commit e05bb6a

Please sign in to comment.