private static void HandleStateChangedAttribute( INetDaemon _daemon, HomeAssistantStateChangedAttribute hassStateChangedAttribute, INetDaemonApp netDaemonApp, MethodInfo method ) { var(signatureOk, err) = CheckIfStateChangedSignatureIsOk(method); if (!signatureOk) { _daemon.Logger.LogWarning(err); return; } _daemon.ListenState(hassStateChangedAttribute.EntityId, async(entityId, to, from) => { try { if (hassStateChangedAttribute.To != null) { if ((dynamic)hassStateChangedAttribute.To != to?.State) { return; } } if (hassStateChangedAttribute.From != null) { if ((dynamic)hassStateChangedAttribute.From != from?.State) { return; } } // If we don´t accept all changes in the state change // and we do not have a state change so return if (to?.State == from?.State && !hassStateChangedAttribute.AllChanges) { return; } await method.InvokeAsync(netDaemonApp, entityId, to !, from !).ConfigureAwait(false); } catch (Exception e) { _daemon.Logger.LogError(e, "Failed to invoke the ServiceCall funcition"); } }); }
/// <inheritdoc/> public void ListenState(string pattern, Func <string, EntityState?, EntityState?, Task> action) => _daemon?.ListenState(pattern, action);