// ReSharper disable once UnusedMethodReturnValue.Global public NotificationContext PublishOnChange(string topic, int address, MqttChannelConfig.Types type, bool retain, MqttQualityOfServiceLevel qualityOfService) { return(type switch { MqttChannelConfig.Types.Integer => logo .IntegerAt(address) .SubscribeToChangeNotification( async logoVariable => await mapping .PublishInteger(logoVariable, topic, retain, qualityOfService) .ConfigureAwait(false)), MqttChannelConfig.Types.Byte => logo .ByteAt(address) .SubscribeToChangeNotification( async logoVariable => await mapping .PublishByte(logoVariable, topic, retain, qualityOfService) .ConfigureAwait(false)), MqttChannelConfig.Types.Float => logo .FloatAt(address) .SubscribeToChangeNotification( async logoVariable => await mapping .PublishFloat(logoVariable, topic, retain, qualityOfService) .ConfigureAwait(false)), _ => throw new ArgumentOutOfRangeException(nameof(type), type, "should be integer, byte or float"), });
public void PulseLogoVariable(Mqtt.Subscription subscription, int address, MqttChannelConfig.Types type, int duration) { if (type != MqttChannelConfig.Types.Byte) { throw new ArgumentOutOfRangeException(nameof(type), type, null); } subscription.MessageReceived += async(sender, args) => await mapping.PulseByte(logo.ByteAt(address), args.ApplicationMessage.Payload, duration); }
public void WriteLogoVariable(Mqtt.Subscription subscription, int address, MqttChannelConfig.Types type) { subscription.MessageReceived += type switch { MqttChannelConfig.Types.Integer => (sender, args) => mapping.ReceivedInteger(logo.IntegerAt(address), args.ApplicationMessage.Payload), MqttChannelConfig.Types.Byte => (sender, args) => mapping.ReceivedByte(logo.ByteAt(address), args.ApplicationMessage.Payload), MqttChannelConfig.Types.Float => (sender, args) => mapping.ReceivedFloat(logo.FloatAt(address), args.ApplicationMessage.Payload), _ => throw new ArgumentOutOfRangeException(nameof(type), type, null) }; }