public Task <SaunaResponse> FetchCurrentState(SaunaRequest request)
        {
            if (_cachedResponse == null)
            {
                _cachedResponse = CreateSaunaResponse(0, request);
            }

            return(Task.FromResult(_cachedResponse));
        }
Exemplo n.º 2
0
        public override async Task FetchStateStream(SaunaRequest request, IServerStreamWriter <SaunaResponse> responseStream, ServerCallContext context)
        {
            while (!context.CancellationToken.IsCancellationRequested)
            {
                await Task.Delay(1000);

                var message = new SaunaResponse
                {
                    TimeStamp   = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
                    IsDrySauna  = _randomGenerator.Next(0, 2) == 1,
                    IsInfraRed  = _randomGenerator.Next(0, 2) == 1,
                    Temperature = GetTemperature(request.TemperatureUnit),
                    Description = ""
                };

                if (!context.CancellationToken.IsCancellationRequested)
                {
                    await responseStream.WriteAsync(message);
                }
            }
        }