Skip to content

Commit dc49458

Browse files
authored
Added possible cause to exception message. (#1307)
* Added possible cause to exception message. * Updated message. * Updated exception message.
1 parent 16dc04e commit dc49458

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/HassModel/NetDaemon.HassModel/Internal/EntityStateCache.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ private void HandleEvent(HassEvent hassEvent)
5252
public EntityState? GetState(string entityId)
5353
{
5454
return !_initialized
55-
? throw new InvalidOperationException("StateCache has not been initialized yet")
56-
: (_latestStates.GetValueOrDefault(entityId)?.Value);
55+
? throw new InvalidOperationException(
56+
"StateCache has not been initialized. This may occur if NetDaemon has not yet completed its initial connection to Home Assistant. " +
57+
"This should not happen with a standard NetDaemon deployment. If you're using a custom deployment, ensure that initialization is complete " +
58+
"before accessing entity state by awaiting `WaitForInitializationAsync` on `INetDaemonRuntime`."
59+
)
60+
: _latestStates.GetValueOrDefault(entityId)?.Value;
5761
}
5862

5963
public void Dispose()

0 commit comments

Comments
 (0)