private async Task CalibrationMinimumLight(IContext context) { if (context.Message is StopCommand stopCommand) { // Ignore previous commands if we receive any if (stopCommand[MessageProperties.Context] == "MAX") { return; } Become(StandardMode); ForwardToPowerAdapter(TurnOffCommand.Default); ResetStateValues(); TryCalculateSpectrum(); Logger.LogInformation($"Calibration of {Uid} : calibration finished with MIN: {_Minimum}, MAX: {_Maximum}, RANGE: {_Range}"); await Task.Delay(WAIT_AFTER_CHANGE).ConfigureAwait(false); ForwardToPowerAdapter(TurnOnCommand.Create(CHANGE_POWER_STATE_TIME)); } else if (context.Message is PropertyChangedEvent minimumState) { await MessageBroker.SendAfterDelay(ActorMessageContext.Create(Self, StopCommand.Create("MIN")), TimeSpan.FromMilliseconds(1500)).ConfigureAwait(false); _Minimum = minimumState.AsDouble(MessageProperties.NewValue); } else { await StandardMode(context).ConfigureAwait(false); } }
protected override async Task OnStarted(IContext context) { await base.OnStarted(context).ConfigureAwait(false); _hostName = AsString(MessageProperties.Hostname); _poolInterval = AsIntTime(MessageProperties.PoolInterval, DEFAULT_POOL_INTERVAL); _zone = AsInt(MessageProperties.Zone); await MessageBroker.SendAfterDelay(ActorMessageContext.Create(Self, RefreshCommand.Default), TimeSpan.FromSeconds(1)); await ScheduleDeviceLightRefresh(_poolInterval).ConfigureAwait(false); }
private async Task HandleEventInTrigger(Trigger trigger) { if (await trigger.ValidateCondition().ConfigureAwait(false)) { foreach (var command in trigger.Commands) { if (command.ContainsProperty(MessageProperties.ExecutionDelay)) { var executionDelay = command.AsTime(MessageProperties.ExecutionDelay); var cancelPrevious = command.AsBool(MessageProperties.CancelPrevious, false); await MessageBroker.SendAfterDelay(ActorMessageContext.Create(Self, command), executionDelay, cancelPrevious).ConfigureAwait(false); continue; } MessageBroker.Send(command, Self); } } }
private async Task CalibrationMaximumLight(IContext context) { if (context.Message is StopCommand stopCommand) { Become(CalibrationMinimumLight); ForwardToPowerAdapter(TurnOffCommand.Default); await Task.Delay(WAIT_AFTER_CHANGE).ConfigureAwait(false); Logger.LogInformation($"Calibration of {Uid} : waiting to reach MIN state"); ForwardToPowerAdapter(TurnOnCommand.Default); } else if (context.Message is PropertyChangedEvent maximumState) { // Resend stop message to cancel scheduled message await MessageBroker.SendAfterDelay(ActorMessageContext.Create(Self, StopCommand.Create("MAX")), TimeSpan.FromMilliseconds(1500), true).ConfigureAwait(false); _Maximum = maximumState.AsDouble(MessageProperties.NewValue); } else { await StandardMode(context).ConfigureAwait(false); } }
protected Task DelayDeviceRefresh(TimeSpan interval) { return(MessageBroker.SendAfterDelay(ActorMessageContext.Create(Self, RefreshLightCommand.Default), interval, false, _disposables.Token)); }
protected Task ScheduleDeviceLightRefresh(TimeSpan interval) { return(MessageBroker.SendWithSimpleRepeat(ActorMessageContext.Create(Self, RefreshLightCommand.Default), interval, _disposables.Token)); }