Example #1
0
        private void SSDP_DeviceFound(object sender, DeviceFoundEventArgs e)
        {
            string location = string.Empty;
            string service  = string.Empty;

            if (!e.Results.TryGetValue("SERVICE", out service))
            {
                return;
            }

            if (service.StartsWith("com.marvell.wm") && e.Results.TryGetValue("LOCATION", out location))
            {
                location = location.Replace("http://", "").Replace("/sys/", "");
                Platform.Current.Logger.Log(LogLevels.Warning, "SearchThermostats_Found {0}", location);
                Platform.Current.Analytics.Event("SearchThermostats_Found", location);

                this.InvokeOnUIThread(async() =>
                {
                    try
                    {
                        ThermostatViewModel vm = Platform.Current.ViewModel.Thermostats.FirstOrDefault(f => f.IPAddress == location);

                        if (vm == null)
                        {
                            vm = this.CreateThermostatViewModel(location);
                            _devicesAdded++;
                            await vm.RefreshAsync(true);
                            Platform.Current.Logger.Log(LogLevels.Warning, "SearchThermostats_Added {0}", location);
                            Platform.Current.Analytics.Event("SearchThermostats_Added", location);
                        }
                        else
                        {
                            Platform.Current.Logger.Log(LogLevels.Warning, "SearchThermostats_AlreadyExists {0}", location);
                            Platform.Current.Analytics.Event("SearchThermostats_AlreadyExists", location);
                        }

                        if (_devicesAdded > 0)
                        {
                            this.SearchStatus = $"Searching...devices found: {_devicesAdded}";
                        }
                    }
                    catch (Exception ex)
                    {
                        await this.HandleExceptionAsync(ex, $"Error while trying to add new thermostat at {location}");
                    }
                });
            }
        }
Example #2
0
        private async Task AddThermostatAsync()
        {
            try
            {
                this.ShowBusyStatus("Adding thermostat...", true);
                if (!string.IsNullOrWhiteSpace(this.IPAddress))
                {
                    ThermostatViewModel vm = this.CreateThermostatViewModel(this.IPAddress);
                    await vm.RefreshAsync(true);

                    Platform.Current.Navigation.Thermostat(vm);
                }
                else
                {
                    Platform.Navigation.Home();
                }
            }
            finally
            {
                this.ClearStatus();
            }
        }