diff --git a/.gitignore b/.gitignore index 9491a2f..faccde0 100644 --- a/.gitignore +++ b/.gitignore @@ -360,4 +360,8 @@ MigrationBackup/ .ionide/ # Fody - auto-generated XML schema -FodyWeavers.xsd \ No newline at end of file +FodyWeavers.xsd + +# Visual Studio Code +.vscode/ +nuget.config diff --git a/API/MqttClientWrapper.cs b/API/MqttClientWrapper.cs index cfcd944..87107b4 100644 --- a/API/MqttClientWrapper.cs +++ b/API/MqttClientWrapper.cs @@ -27,14 +27,16 @@ public bool IsAttemptingConnection get { return _isAttemptingConnection; } private set { _isAttemptingConnection = value; } } - public MqttClientWrapper(string clientId, string mqttBroker, string username, string password) + public MqttClientWrapper(string clientId, string mqttBroker, string mqttPort, string username, string password) { var factory = new MqttFactory(); _mqttClient = factory.CreateMqttClient() as MqttClient; + int mqttportInt = System.Convert.ToInt32(mqttPort); + _mqttOptions = new MqttClientOptionsBuilder() .WithClientId(clientId) - .WithTcpServer(mqttBroker) + .WithTcpServer(mqttBroker, mqttportInt) .WithCredentials(username, password) .WithCleanSession() .Build(); diff --git a/MainWindow.xaml b/MainWindow.xaml index 2c25d20..07b8d75 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -58,6 +58,8 @@ + + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index c30a675..8a42165 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -17,6 +17,7 @@ using System.Windows; using TEAMS2HA.API; +using TEAMS2HA.Properties; namespace TEAMS2HA { @@ -89,6 +90,8 @@ public static AppSettings Instance public string MqttAddress { get; set; } + public string MqttPort { get; set; } + public string MqttUsername { get; set; } public bool RunAtWindowsBoot { get; set; } @@ -256,6 +259,7 @@ public MainWindow() mqttClientWrapper = new MqttClientWrapper( "TEAMS2HA", _settings.MqttAddress, + _settings.MqttPort, _settings.MqttUsername, _settings.MqttPassword ); @@ -776,6 +780,7 @@ private async void MainPage_Loaded(object sender, RoutedEventArgs e) MqttUserNameBox.Text = _settings.MqttUsername; MQTTPasswordBox.Password = _settings.MqttPassword; MqttAddress.Text = _settings.MqttAddress; + MqttPort.Text = _settings.MqttPort; if (_settings.PlainTeamsToken == null) { TeamsApiKeyBox.Text = "Not Paired"; @@ -924,11 +929,13 @@ private bool SaveSettings() bool mqttSettingsChanged = settings.MqttAddress != MqttAddress.Text || settings.MqttUsername != MqttUserNameBox.Text || + settings.MqttPort != MqttPort.Text || settings.MqttPassword != MQTTPasswordBox.Password; settings.RunAtWindowsBoot = RunAtWindowsBootCheckBox.IsChecked ?? false; settings.RunMinimized = RunMinimisedCheckBox.IsChecked ?? false; settings.MqttAddress = MqttAddress.Text; + settings.MqttPort = MqttPort.Text; settings.MqttUsername = MqttUserNameBox.Text; settings.MqttPassword = MQTTPasswordBox.Password; settings.Theme = isDarkTheme ? "Dark" : "Light"; @@ -949,6 +956,7 @@ private void SaveSettings_Click(object sender, RoutedEventArgs e) mqttClientWrapper = new MqttClientWrapper( "TEAMS2HA", _settings.MqttAddress, + _settings.MqttPort, _settings.MqttUsername, _settings.MqttPassword ); @@ -1094,5 +1102,6 @@ private void ToggleThemeButton_Click(object sender, RoutedEventArgs e) } #endregion Private Methods + } } \ No newline at end of file