private async void OnButtonClicked(object sender, EventArgs e) { var action = string.Empty; var newState = DoorState.opening; if (doorState == DoorState.open) { action = Constants.ActionClose; newState = DoorState.closing; } else if (doorState == DoorState.closed) { action = Constants.ActionOpen; newState = DoorState.opening; } else { Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { Toast.DisplayText("Couldn't set"); }); return; } var set = await api.SetDoorState(garageDoor.SerialNumber, action); if (set) { Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { UpdateUi(newState); }); } }
static void Main(string[] args) { var api = new MyQApi(); var result = api.Login(Constants.Email, Constants.Password).Result; var garageDoor = api.GetDevices().Result.Where(x => x.DeviceFamily == "garagedoor").FirstOrDefault(); var doorstate = api.GetDoorState(garageDoor.SerialNumber).Result; var setting = api.SetDoorState(garageDoor.SerialNumber, Constants.ActionClose).Result; }