public Task HandleMessage(MqttApplicationMessage message)
        {
            try
            {
                var payload = Encoding.UTF8.GetString(message.Payload);

                var payloadObject = JsonConvert.DeserializeObject <SetVentilationLevel>(payload);

                byte highest(byte left, int right) => left > right ? left : (byte)right;

                var serialCommand = new SetVentilationLevelCommand();
                serialCommand.ExhaustAbsent = highest(serialCommand.ExhaustAbsent, payloadObject.DesiredVentilationOut);
                serialCommand.ExhaustLow    = highest(serialCommand.ExhaustLow, payloadObject.DesiredVentilationOut);
                serialCommand.ExhaustMedium = highest(serialCommand.ExhaustMedium, payloadObject.DesiredVentilationOut);
                serialCommand.ExhaustHigh   = highest(serialCommand.ExhaustHigh, payloadObject.DesiredVentilationOut);

                serialCommand.SupplyAbsent = highest(serialCommand.SupplyAbsent, payloadObject.DesiredVentilationIn);
                serialCommand.SupplyLow    = highest(serialCommand.SupplyLow, payloadObject.DesiredVentilationIn);
                serialCommand.SupplyMedium = highest(serialCommand.SupplyMedium, payloadObject.DesiredVentilationIn);
                serialCommand.SupplyHigh   = highest(serialCommand.SupplyHigh, payloadObject.DesiredVentilationIn);

                commandClient.SendCommandWithAck(serialCommand);

                return(Task.CompletedTask);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());

                throw;
            }
        }
Esempio n. 2
0
        public async Task HandleMessage(MqttApplicationMessage message)
        {
            try
            {
                var serialCommand = new SetComfortTemperatureCommand();
                serialCommand.ComfortTemperature = double.Parse(Encoding.UTF8.GetString(message.Payload));

                commandClient.SendCommandWithAck(serialCommand);
            }
            catch (Exception ex)
            {
                await Console.Error.WriteLineAsync(ex.ToString());
            }
        }