Skip to content

Commit

Permalink
Remove (incorrect) delete of old stete objects + small refactor (#327)
Browse files Browse the repository at this point in the history
* Remove (incorrect) delete of old stete objects + small refactor

* simplified a bit
  • Loading branch information
FrankBakkerNl committed Feb 26, 2021
1 parent e1a1a15 commit 6ef5733
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/Daemon/NetDaemon.Daemon/Daemon/NetDaemonHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -781,22 +781,13 @@ internal async Task RefreshInternalStatesAndSetArea()
_hassEntities[entity.EntityId] = entity;
}
var hassStates = await _hassClient.GetAllStates(_cancelToken).ConfigureAwait(false);
var initialStates = hassStates.Select(n => n.Map())
.ToDictionary(n => n.EntityId);

foreach (var entityId in initialStates.Keys.Where(k => !initialStates.ContainsKey(k)))
foreach (var state in hassStates.Select(s=>s.Map()))
{
InternalState.TryRemove(entityId, out _);
}

foreach (var key in initialStates.Keys)
{
var state = initialStates[key];
state = state with
InternalState[state.EntityId] = state with
{
Area = GetAreaForEntityId(state.EntityId)
};
InternalState[key] = state;
}
}

Expand Down

0 comments on commit 6ef5733

Please sign in to comment.