Beispiel #1
0
 public void DispatchSetMember(PremiseObject obj, string propertyName, string value) {
     if (CoreApplication.MainView.CoreWindow.Dispatcher.HasThreadAccess)
         obj.SetMember(propertyName, value, false);
     else   
         CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
         CoreDispatcherPriority.Normal, () => obj.SetMember(propertyName, value, false));
 }
Beispiel #2
0
 private void AddLight(string location) {
     var o = new PremiseObject(location);
     o.AddPropertyAsync("Name", PremiseProperty.PremiseType.TypeText);
     o.AddPropertyAsync("Description",  PremiseProperty.PremiseType.TypeText);
     o.AddPropertyAsync("Mute", PremiseProperty.PremiseType.TypeBoolean, true);
     o.AddPropertyAsync("Volume", PremiseProperty.PremiseType.TypePercent, true);
     AudioZones.Add(o);
 }
Beispiel #3
0
 private void AddLight(string location) {
     var o = new PremiseObject(location);
     o.AddPropertyAsync("Name", PremiseProperty.PremiseType.TypeText);
     o.AddPropertyAsync("Description",  PremiseProperty.PremiseType.TypeText);
     o.AddPropertyAsync("PowerState", PremiseProperty.PremiseType.TypeBoolean, true);
     if (!location.Contains("Fluorescent") && !location.Contains("Flourescent") && !location.Contains("Fan"))
         o.AddPropertyAsync("Brightness", PremiseProperty.PremiseType.TypePercent, true);
     Lights.Add(o);
 }
Beispiel #4
0
 public MainViewModel() {
     Server.PropertyChanged += (sender, args) => {
         if (args.PropertyName == "Connected") {
             Debug.WriteLine("Connected: {0}", Server.Connected);
             if (PremiseServer.Instance.Connected) {
                 Home = new PremiseObject("sys://Home");
                 Home.AddPropertyAsync("DisplayName", PremiseProperty.PremiseType.TypeText, true);
             }
             else {
                 
             }
         }
         Connected = PremiseServer.Instance.Connected;
     };
     this.Items = new ObservableCollection<PremiseObject>();
 }
Beispiel #5
0
        /// <summary>
        /// Creates and adds a few ItemViewModel objects into the Items collection.
        /// </summary>
        public async void LoadData() {
            if (PremiseServer.Instance.Connected && GDOItems.Count > 0) return;

            IsDataLoaded = false;
            GDOItems.Clear();
            await PremiseServer.Instance.StartSubscriptionsAsync(new StreamSocketPremiseSocket());
            var o = new PremiseObject("sys://Home/Upstairs/Garage/East Garage Door");
            o.AddPropertyAsync("Description", "Lower East Garage", PremiseProperty.PremiseType.TypeText);
            o.AddPropertyAsync("GarageDoorOpened", PremiseProperty.PremiseType.TypeBoolean, true);
            o.AddPropertyAsync("Trigger", PremiseProperty.PremiseType.TypeBoolean);
            GDOItems.Add(o);

            o = new PremiseObject("sys://Home/Upstairs/Garage/West Garage Door");
            o.AddPropertyAsync("Description", "Lower West Garage", PremiseProperty.PremiseType.TypeText);
            o.AddPropertyAsync("GarageDoorOpened", PremiseProperty.PremiseType.TypeBoolean, true);
            o.AddPropertyAsync("Trigger", PremiseProperty.PremiseType.TypeBoolean);
            GDOItems.Add(o);

            o = new PremiseObject("sys://Home/Upper Garage/East Garage Door");
            o.AddPropertyAsync("Description", "Upper East Garage", PremiseProperty.PremiseType.TypeText);
            o.AddPropertyAsync("GarageDoorOpened", PremiseProperty.PremiseType.TypeBoolean, true);
            o.AddPropertyAsync("Trigger", PremiseProperty.PremiseType.TypeBoolean);
            GDOItems.Add(o);

            o = new PremiseObject("sys://Home/Upper Garage/Center Garage Door");
            o.AddPropertyAsync("Description", "Upper Center Garage", PremiseProperty.PremiseType.TypeText);
            o.AddPropertyAsync("GarageDoorOpened", PremiseProperty.PremiseType.TypeBoolean, true);
            o.AddPropertyAsync("Trigger", PremiseProperty.PremiseType.TypeBoolean);
            GDOItems.Add(o);

            o = new PremiseObject("sys://Home/Upper Garage/West Garage Door");
            o.AddPropertyAsync("Description", "Upper West Garage", PremiseProperty.PremiseType.TypeText);
            o.AddPropertyAsync("GarageDoorOpened", PremiseProperty.PremiseType.TypeBoolean, true);
            o.AddPropertyAsync("Trigger", PremiseProperty.PremiseType.TypeBoolean);
            GDOItems.Add(o);

            LightsOff = new PremiseObject("sys://Home/Admin/All House Scenes/Upper Garage Off");
            LightsOff.AddPropertyAsync("DisplayName", "Upper Garage Lights Off", PremiseProperty.PremiseType.TypeText, true);
            LightsOff.AddPropertyAsync("Status", PremiseProperty.PremiseType.TypeBoolean, true);
            LightsOff.AddPropertyAsync("Trigger", PremiseProperty.PremiseType.TypeBoolean);

            GDOPower = new PremiseObject("sys://Home/Admin/Garage Door Power");
            GDOPower.AddPropertyAsync("DisplayName", "GDO Power", PremiseProperty.PremiseType.TypeText, true); 
            GDOPower.AddPropertyAsync("State", PremiseProperty.PremiseType.TypeBoolean, true);

            IsDataLoaded = true;
        }
Beispiel #6
0
 public void AddLight(string name) {
     var o = new PremiseObject(name);
     o["Name"] = name;
     o["Description"] = name + " descripton";
     o["PowerState"] = false;
     o["Brightness"] = 0.75;
     Lights.Add(o);
 }
Beispiel #7
0
        public SampleGarageDoors() {
            ApplicationTitle = "Kindel Residence";
            PageName = "Garage Doors";
            IsDataLoaded = true;
            GDOPower = new PremiseObject("gdopower");
            GDOPower["DisplayName"] = "GDO Power!";
            GDOPower["State"] = true;

            GDOItems = new ObservableCollection<PremiseObject>();
            var o = new PremiseObject("lge");
            o["Description"] = "Lower Garage East";
            o["GarageDoorOpened"] = false;
            GDOItems.Add(o);
            o = new PremiseObject("lgw");
            o["Description"] = "Lower Garage West";
            o["GarageDoorOpened"] = true;
            GDOItems.Add(o);
            o = new PremiseObject("uge");
            o["Description"] = "Upper Garage East";
            o["GarageDoorOpened"] = true;
            GDOItems.Add(o);
            o = new PremiseObject("ugc");
            o["Description"] = "Upper Garage Center";
            o["GarageDoorOpened"] = true;
            GDOItems.Add(o);
            o = new PremiseObject("ugw");
            o["Description"] = "Upper Garage West";
            o["GarageDoorOpened"] = true;
            GDOItems.Add(o);

            LightsOff = new PremiseObject("lightsoff");
            LightsOff["DisplayName"] = "Upper Garage Off";
            LightsOff["Status"] = true;
        }
Beispiel #8
0
 public void DispatchSetMember(PremiseObject obj, string propertyName, string value) {
     if (Deployment.Current.Dispatcher.CheckAccess())
         obj.SetMember(propertyName, value, false);
     else
         Deployment.Current.Dispatcher.BeginInvoke(() => obj.SetMember(propertyName, value, false));
 }
Beispiel #9
0
 public PremiseCommand(PremiseObject holdingObject, string propertyName) {
     _holdingObject = holdingObject;
     _propertyName = propertyName;
 }
Beispiel #10
0
 // Default implementation of method to set an object property's value
 // Assumes same thread.
 public void DispatchSetMember(PremiseObject obj, string propertyName, string value) {
     obj.SetMember(propertyName, value, false);
 }
Beispiel #11
0
 public void AddLight(string name) {
     var o = new PremiseObject(name);
     o["Name"] = name;
     o["Description"] = name + " descripton";
     o["Mute"] = false;
     o["Volume"] = 0.75;
     AudioZones.Add(o);
 }
Beispiel #12
0
        /// <summary>
        /// Send an unsubscribe request to the server.
        /// </summary>
        /// <param name="po"></param>
        /// <param name="propertyName"></param>
        public async Task Unsubscribe(PremiseObject po, string propertyName) {
            try {
                _readCts.Token.ThrowIfCancellationRequested();

                if (_subscriptionClient == null) return;
                // Find subscription 
                foreach (var subscription in _subscriptions) {
                    if (subscription.Value.PropertyName == propertyName &&
                        subscription.Value.Object.Location == po.Location) {
                        _subscriptions.Remove(subscription.Key);
                        string command = "?c?" + subscription.Key;
                        if (FastMode)
                            await SendRequestFastMode(command);
                        else {
                            await SendRequest(command);
                        }
                        return;
                    }
                }
            }
            catch (Exception ex) {
                Debug.WriteLine("Subscribe: " + ex.ToString());
                Error = true;
                LastError = ex.GetType().ToString();
                LastErrorContent = ex.Message;
                Dispose();
                throw ex;
            }
        }
Beispiel #13
0
        /// <summary>
        /// Send a subscription request to the server.
        /// </summary>
        /// <param name="po">The object with the property to subscribe.</param>
        /// <param name="propertyName">Name of the property to subscribe.</param>
        public async Task Subscribe(PremiseObject po, string propertyName) {
            try {
                _readCts.Token.ThrowIfCancellationRequested();
                // Ignore multiple subscripitons
                if (_subscriptions.Any(subscription => subscription.Value.PropertyName == propertyName &&
                                                       subscription.Value.Object.Location == po.Location)) {
                    return;
                }

                var sub = new Subscription {Object = po, PropertyName = propertyName};
                _subscriptions.Add(sub.GetHashCode(), sub);
                await SendSubscriptionRequest(sub);

            }
            catch (Exception ex) {
                Debug.WriteLine("Subscribe: " + ex.ToString());
                Error = true;
                LastError = ex.GetType().ToString();
                LastErrorContent = ex.Message;
                Dispose();
                throw ex;
            }
        }