Exemple #1
0
        /// <inheritdoc />
        public bool IsReadyToProgramWorkout(string serialNumber)
        {
            if (string.IsNullOrWhiteSpace(serialNumber))
            {
                _logger.LogError("Serial number must be defined when determining state.");
                return(false);
            }

            GetOperationalStateCommand operationalStateCommand = new();
            GetWorkoutStateCommand     workoutStateCommand     = new();

            ICommandList commandList = _commandListFactory.Create();

            commandList.Add(operationalStateCommand);
            commandList.Add(workoutStateCommand);
            commandList.Prepare();

            _pmCommunicator.Send(serialNumber, commandList);

            OperationalState?operationalState = operationalStateCommand.Value;

            if (!operationalState.HasValue)
            {
                _logger.LogWarning("Operational state is unknown.");
                return(false);
            }

            if (operationalState.Value != OperationalState.Ready &&
                operationalState.Value != OperationalState.Workout)
            {
                return(false);
            }

            WorkoutState?workoutState = workoutStateCommand.Value;

            if (!workoutState.HasValue)
            {
                _logger.LogWarning("Workout state is unknown.");
                return(false);
            }

            return(workoutState.Value == WorkoutState.WaitingToBegin);
        }
        /// <summary>
        /// Gets the current workout state for a specified location
        /// </summary>
        /// <param name="serialNumber">The serial number</param>
        /// <returns>The current workout state</returns>
        private WorkoutState?GetWorkoutState(string serialNumber)
        {
            ICommandList commands = _commandListFactory.Create();

            commands.Add(new GetWorkoutStateCommand());
            commands.Prepare();

            try
            {
                _pmCommunicator.Send(serialNumber, commands);
            }
            catch (Exception e)
            {
                _logger.LogWarning(e, "Error occurred while checking workout state prior to polling");
                return(WorkoutState.WaitingToBegin);
            }

            return(commands.FirstOrDefault()?.Value);
        }