private async Task Connect() { PremiseServer.Instance.Notifier = new WinRTIPremiseNotify(); PremiseServer.Instance.Host = "home"; PremiseServer.Instance.Port = 86; PremiseServer.Instance.Username = "******"; PremiseServer.Instance.Password = "******"; PremiseServer.Instance.PropertyChanged += async (sender, args) => { if (args.PropertyName == "Connected" && PremiseServer.Instance.Connected == true) { Debug.WriteLine("Yo! Connected!!"); } if (args.PropertyName == "Connected" && PremiseServer.Instance.Connected == false) Debug.WriteLine("Disconnected!"); }; if (IsInDesignMode) { KeypadButtons = new ObservableCollection<PremiseObject>(); var o = new PremiseObject("test"); o["Description"] = "Button 1"; o["Status"] = false; o["Trigger"] = false; KeypadButtons.Add(o); o["Description"] = "Button 2"; o["Status"] = true; o["Trigger"] = false; KeypadButtons.Add(o); return; } PremiseServer.Instance.FastMode = false; await PremiseServer.Instance.StartSubscriptionsAsync(new StreamSocketPremiseSocket()); PremiseObject o1 = new PremiseObject("sys://Home/Downstairs/Office/Office At Entry Door/Button_Desk"); await o1.AddPropertyAsync("Description", PremiseProperty.PremiseType.TypeText); await o1.AddPropertyAsync("Status", PremiseProperty.PremiseType.TypeBoolean, true); await o1.AddPropertyAsync("Trigger", PremiseProperty.PremiseType.TypeBoolean); PremiseObject o2 = new PremiseObject("sys://Home/Downstairs/Office/Office At Entry Door/Button_Workshop"); await o2.AddPropertyAsync("Description", PremiseProperty.PremiseType.TypeText); await o2.AddPropertyAsync("Status", PremiseProperty.PremiseType.TypeBoolean, true); await o2.AddPropertyAsync("Trigger", PremiseProperty.PremiseType.TypeBoolean); KeypadButtons = new ObservableCollection<PremiseObject> { (PremiseObject) o1, (PremiseObject) o2 }; foreach (PremiseObject l in KeypadButtons) { l.PropertyChanged += (s, a) => Debug.WriteLine("MVM: {0}: {1} = {2}", ((PremiseObject)s).Location, PremiseProperty.NameFromItem(a.PropertyName), ((PremiseObject)s)[PremiseProperty.NameFromItem(a.PropertyName)]); } }
public void DispatchSetMember(PremiseObject obj, string propertyName, string value) { RunOnUiThread(() => obj.SetMember(propertyName, value, false)); }
private async void AddGDO(string location, TextView textDesc, TextView textStatus, Button button){ try { button.Enabled = false; PremiseObject ob = new PremiseObject(location); ob.PropertyChanged += (sender, args) => { button.Enabled = true; var propName = PremiseProperty.NameFromItem(args.PropertyName); var val = ((PremiseObject)sender)[propName]; Console.WriteLine("{0}: {1} = {2}", ((PremiseObject)sender).Location, propName, val); switch (propName){ case "GarageDoorStatus": textStatus.Text = val.ToString(); break; case "Description": textDesc.Text = val.ToString(); break; case "GarageDoorOpened": button.Text = (bool)val == true ? "Close" : "Open"; break; } }; await ob.AddPropertyAsync("Description"); await ob.AddPropertyAsync("Trigger", PremiseProperty.PremiseType.TypeBoolean, false); await ob.AddPropertyAsync("GarageDoorOpened", PremiseProperty.PremiseType.TypeBoolean, true); await ob.AddPropertyAsync("GarageDoorStatus", PremiseProperty.PremiseType.TypeText, true); button.Click += (sender, e) => { ((dynamic)ob["TriggerCommand"]).Execute(null); }; } catch (Exception ex) { throw ex; } }