Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Apps that were started from HA are not retsrated after a reconnect #1217

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/Runtime/NetDaemon.Runtime/Internal/AppStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ internal class AppStateManager(IAppStateRepository appStateRepository,
IHostEnvironment hostEnvironment) : IAppStateManager, IHandleHomeAssistantAppStateUpdates, IDisposable
{
private readonly CancellationTokenSource _cancelTokenSource = new();
private readonly ConcurrentDictionary<string, ApplicationState> _stateCache = new();

public async Task InitializeAsync(IHomeAssistantConnection haConnection, IAppModelContext appContext)
{
_stateCache.Clear();
if (appContext.Applications.Count > 0 && !hostEnvironment.IsDevelopment())
await appStateRepository.RemoveNotUsedStatesAsync(appContext.Applications.Select(a => a.Id).ToList()!,
_cancelTokenSource.Token);
Expand Down Expand Up @@ -54,8 +52,6 @@ await app.SetStateAsync(

public async Task<ApplicationState> GetStateAsync(string applicationId)
{
if (_stateCache.TryGetValue(applicationId, out var applicationState)) return applicationState;

return await appStateRepository.GetOrCreateAsync(applicationId, _cancelTokenSource.Token)
.ConfigureAwait(false)
? ApplicationState.Enabled
Expand All @@ -64,8 +60,6 @@ public async Task<ApplicationState> GetStateAsync(string applicationId)

public async Task SaveStateAsync(string applicationId, ApplicationState state)
{
_stateCache[applicationId] = state;

var isEnabled = await appStateRepository.GetOrCreateAsync(applicationId, _cancelTokenSource.Token)
.ConfigureAwait(false);

Expand Down
Loading