Exemplo n.º 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}");
                    }
                });
            }
        }
Exemplo n.º 2
0
        private ThermostatViewModel CreateThermostatViewModel(string ipAddress)
        {
            ThermostatViewModel vm = Platform.Current.ViewModel.Thermostats.FirstOrDefault(f => f.IPAddress == ipAddress);

            if (vm == null)
            {
                Platform.Current.Logger.Log(LogLevels.Warning, "CreateThermostatViewModel_Added {0}", ipAddress);
                Platform.Current.Analytics.Event("CreateThermostatViewModel_Added", ipAddress);
                Platform.Current.AppSettingsRoaming.IPAddresses.Add(ipAddress);
                Platform.Current.SaveSettings();
                vm = new ThermostatViewModel(ipAddress);
                Platform.Current.ViewModel.Thermostats.Add(vm);
            }
            else
            {
                Platform.Current.Logger.Log(LogLevels.Warning, "CreateThermostatViewModel_AlreadyExists {0}", ipAddress);
                Platform.Current.Analytics.Event("CreateThermostatViewModel_AlreadyExists", ipAddress);
            }

            return(vm);
        }
Exemplo n.º 3
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();
            }
        }