public AddSensorViewModel(Router router, ThingsDeviceModel showModel = null) { _router = router; _showModel = showModel; if (_showModel != null) { DeviceID = showModel.DeviceId; DeviceEUI = showModel.Device.DeviceEUI; Description = showModel.Description; AppKey = showModel.AppId; AppEUI = showModel.Device.AppEUI; } AddDevice = ReactiveCommand.Create(() => { }); AddDevice.Subscribe(async unit => { try { if (!DeviceID.StartsWith(ThingsNetworkDevicesApi.HackathonDeviceIdPrefix)) { throw new Exception("Device ID must start with " + ThingsNetworkDevicesApi.HackathonDeviceIdPrefix); } var device = new ThingsDeviceModel { AppId = ThingsNetworkDevicesApi.app_id, Description = Description, DeviceId = DeviceID.Trim().ToLower(), Device = new ThingsDeviceLorawan { DeviceId = DeviceID, AppId = ThingsNetworkDevicesApi.app_id, DeviceEUI = DeviceEUI, AppEUI = AppEUI } }; await ThingsNetworkDevicesApi.AddDevice(device); _onDeviceAdded.OnNext(device); _router.ShowDevices(); } catch (Exception err) { _onError.OnNext(err); } }).DisposeWith(_disposable); DeleteDevice = ReactiveCommand.Create(() => { }); DeleteDevice.Subscribe(async unit => { try { await ThingsNetworkDevicesApi.DeleteDevice(DeviceID); Beep(); _router.ShowDevices(); } catch (Exception err) { Beep(2); _onError.OnNext(err); } }).DisposeWith(_disposable); Clear = ReactiveCommand.Create(() => { }); Clear.Subscribe(unit => { DeviceID = ThingsNetworkDevicesApi.HackathonDeviceIdPrefix; DeviceEUI = Utils.RandomByteString(8); }).DisposeWith(_disposable); Cancel = ReactiveCommand.Create(() => { }); Cancel.Subscribe(_ => _router.ShowDevices()).DisposeWith(_disposable); }