예제 #1
0
 internal void modules_RefreshPrograms()
 {
     lock (systemModules.LockObject)
     try
     {
         //
         // ProgramEngine programs (modules)
         //
         if (masterControlProgram != null)
         {
             lock (masterControlProgram.Programs.LockObject)
             foreach (var program in masterControlProgram.Programs)
             {
                 Module module = systemModules.Find(o => o.Domain == Domains.HomeAutomation_HomeGenie_Automation && o.Address == program.Address.ToString());
                 if (module != null && program.Type.ToLower() == "wizard" && !program.IsEnabled && module.RoutingNode == "")
                 {
                     systemModules.Remove(module);
                     continue;
                 }
                 else if (/*program.Type.ToLower() != "wizard" &&*/ !program.IsEnabled)
                 {
                     continue;
                 }
                 // add new module
                 if (module == null)
                 {
                     module = new Module();
                     module.Domain = Domains.HomeAutomation_HomeGenie_Automation;
                     if (program.Type.ToLower() == "wizard")
                     {
                         Utility.ModuleParameterSet(
                             module,
                             Properties.WidgetDisplayModule,
                             "homegenie/generic/program"
                         );
                     }
                     systemModules.Add(module);
                 }
                 //
                 module.Name = program.Name;
                 module.Address = program.Address.ToString();
                 module.DeviceType = MIG.ModuleTypes.Program;
                 //module.Description = "Wizard Script";
             }
             // Add "Scheduler" virtual module
             //Module scheduler = systemModules.Find(o=> o.Domain == Domains.HomeAutomation_HomeGenie && o.Address == SourceModule.Scheduler);
             //if (scheduler == null) {
             //    scheduler = new Module(){ Domain = Domains.HomeAutomation_HomeGenie, Address = SourceModule.Scheduler };
             //    systemModules.Add(scheduler);
             //}
         }
     }
     catch (Exception ex)
     {
         LogError(
             Domains.HomeAutomation_HomeGenie,
             "modules_RefreshPrograms()",
             ex.Message,
             "Exception.StackTrace",
             ex.StackTrace
         );
     }
 }
예제 #2
0
        public void SignalModulePropertyChange(
            object sender,
            Module module,
            InterfacePropertyChangedAction propertyChangedAction
        )
        {

            // update module parameter value
            ModuleParameter parameter = null;
            try
            {
                parameter = Utility.ModuleParameterGet(module, propertyChangedAction.Path);
                if (parameter == null)
                {
                    module.Properties.Add(new ModuleParameter() {
                        Name = propertyChangedAction.Path,
                        Value = propertyChangedAction.Value.ToString()
                    });
                }
                else
                {
                    parameter.Value = propertyChangedAction.Value.ToString();
                }
            }
            catch
            {
                //                HomeGenieService.LogEvent(Domains.HomeAutomation_HomeGenie, "SignalModulePropertyChange(...)", ex.Message, "Exception.StackTrace", ex.StackTrace);
            }
            //
            LogBroadcastEvent(
                propertyChangedAction.Domain,
                propertyChangedAction.SourceId,
                propertyChangedAction.SourceType,
                propertyChangedAction.Path,
                JsonConvert.SerializeObject(propertyChangedAction.Value)
            );
            //
            ///// ROUTE EVENT TO LISTENING AutomationPrograms
            if (masterControlProgram != null)
            {
                RoutedEvent eventData = new RoutedEvent() {
                    Sender = sender,
                    Module = module,
                    Parameter = parameter
                };
                ThreadPool.QueueUserWorkItem(new WaitCallback(RouteParameterChangedEvent), eventData);
            }
        }
예제 #3
0
 internal void modules_RefreshPrograms()
 {
     lock (systemModules.LockObject)
     try
     {
         // Refresh ProgramEngine program modules
         if (masterControlProgram != null)
         {
             lock (masterControlProgram.Programs.LockObject)
             foreach (var program in masterControlProgram.Programs)
             {
                 Module module = systemModules.Find(o => o.Domain == Domains.HomeAutomation_HomeGenie_Automation && o.Address == program.Address.ToString());
                 if (module != null && program.Type.ToLower() == "wizard" && !program.IsEnabled && module.RoutingNode == "")
                 {
                     // we don't remove non-wizard programs to keep configuration options
                     // TODO: ?? should use modulesGarbage in order to allow correct removing/restoring of all program types ??
                     // TODO: ?? (but it will loose config options when hg is restarted because modulesGarbage it's not saved) ??
                     systemModules.Remove(module);
                     continue;
                 }
                 else if (module == null && !program.IsEnabled)
                 {
                     continue;
                 }
                 else if (module == null)
                 {
                     // add module for the program
                     module = new Module();
                     module.Domain = Domains.HomeAutomation_HomeGenie_Automation;
                     if (program.Type.ToLower() == "wizard")
                     {
                         Utility.ModuleParameterSet(
                             module,
                             Properties.WidgetDisplayModule,
                             "homegenie/generic/program"
                         );
                     }
                     systemModules.Add(module);
                 }
                 module.Name = program.Name;
                 module.Address = program.Address.ToString();
                 module.DeviceType = MIG.ModuleTypes.Program;
                 //module.Description = "Wizard Script";
             }
             // Add "Scheduler" virtual module
             //Module scheduler = systemModules.Find(o=> o.Domain == Domains.HomeAutomation_HomeGenie && o.Address == SourceModule.Scheduler);
             //if (scheduler == null) {
             //    scheduler = new Module(){ Domain = Domains.HomeAutomation_HomeGenie, Address = SourceModule.Scheduler };
             //    systemModules.Add(scheduler);
             //}
         }
     }
     catch (Exception ex)
     {
         LogError(
             Domains.HomeAutomation_HomeGenie,
             "modules_RefreshPrograms()",
             ex.Message,
             "Exception.StackTrace",
             ex.StackTrace
         );
     }
 }
예제 #4
0
        internal void modules_RefreshVirtualModules()
        {
            lock (systemModules.LockObject) lock (virtualModules.LockObject) try
                {
                    //
                    // Virtual Modules
                    //
                    foreach (var virtualModule in virtualModules)
                    {
                        ProgramBlock program = masterControlProgram.Programs.Find(p => p.Address.ToString() == virtualModule.ParentId);
                        if (program == null) continue;
                        //
                        var virtualModuleWidget = Utility.ModuleParameterGet(
                                                      virtualModule,
                                                      Properties.WIDGET_DISPLAYMODULE
                                                  );
                        //
                        Module module = Modules.Find(o => o.Domain == virtualModule.Domain && o.Address == virtualModule.Address);

                        if (!program.IsEnabled)
                        {
                            if (module != null && module.RoutingNode == "" && virtualModule.ParentId != module.Address)
                            {
                                // copy instance module properties to virtualmodules before removing
                                virtualModule.Name = module.Name;
                                virtualModule.DeviceType = module.DeviceType;
                                virtualModule.Properties.Clear();
                                foreach (var p in module.Properties)
                                {
                                    virtualModule.Properties.Add(p);
                                }
                                systemModules.Remove(module);
                            }
                            continue;
                        }

                        if (module == null)
                        {
                            // add new module
                            module = new Module();
                            systemModules.Add(module);
                            // copy properties from virtualmodules
                            foreach (var p in virtualModule.Properties)
                            {
                                module.Properties.Add(p);
                            }
                        }

                        // module inherits props from associated virtual module
                        module.Domain = virtualModule.Domain;
                        module.Address = virtualModule.Address;
                        if (module.DeviceType == Module.DeviceTypes.Generic)
                        {
                            module.DeviceType = virtualModule.DeviceType;
                        }
                        // associated module's name of an automation program cannot be changed
                        if (module.Name == "" || (module.DeviceType == Module.DeviceTypes.Program && virtualModule.Name != ""))
                        {
                            module.Name = virtualModule.Name;
                        }
                        module.Description = virtualModule.Description;
                        //
                        Utility.ModuleParameterSet(
                            module,
                            Properties.VIRTUALMODULE_PARENTID,
                            virtualModule.ParentId
                        );
                        var moduleWidget = Utility.ModuleParameterGet(module, Properties.WIDGET_DISPLAYMODULE);
                        // if a widget is specified on virtual module then we force module to display using this
                        if ((virtualModuleWidget != null && (virtualModuleWidget.Value != "" || moduleWidget == null)) && (moduleWidget == null || (moduleWidget.Value != virtualModuleWidget.Value)))
                        {
                            Utility.ModuleParameterSet(
                                module,
                                Properties.WIDGET_DISPLAYMODULE,
                                virtualModuleWidget.Value
                            );
                        }
                    }
                }
                catch (Exception ex)
                {
                    HomeGenieService.LogEvent(
                        Domains.HomeAutomation_HomeGenie,
                        "modules_RefreshVirtualModules()",
                        ex.Message,
                        "Exception.StackTrace",
                        ex.StackTrace
                    );
                }
        }
예제 #5
0
 public ModuleHelper FromInstance(Module module)
 {
     return new ModuleHelper(homegenie, module);
 }
예제 #6
0
 private void RelocateProgramModule()
 {
     // force automation modules regeneration
     homegenie.modules_RefreshPrograms();
     //
     try
     {
         programModule = homegenie.Modules.Find(rm => rm.Domain == myProgramDomain && rm.Address == myProgramId.ToString());
     }
     catch (Exception ex)
     {
         HomeGenieService.LogError(
             myProgramDomain,
             myProgramId.ToString(),
             ex.Message,
             "Exception.StackTrace",
             ex.StackTrace
         );
     }
 }
예제 #7
0
 public ModuleHelper(HomeGenieService hg, Module module)
     : base(hg)
 {
     this.module = module;
 }
예제 #8
0
        public void SignalModulePropertyChange(object sender, Module module, InterfacePropertyChangedAction propertyChangedAction)
        {
            // ROUTE THE EVENT TO AUTOMATION PROGRAMS, BEFORE COMMITTING THE CHANGE
            if (masterControlProgram != null)
            {
                ModuleParameter tempParam = new ModuleParameter() {
                    Name = propertyChangedAction.Path,
                    Value = propertyChangedAction.Value.ToString()
                };
                RoutedEvent eventData = new RoutedEvent() {
                    Sender = sender,
                    Module = module,
                    Parameter = tempParam
                };
                RouteParameterBeforeChangeEvent(eventData);
                // If the value has been manipulated by an automation program
                // so the event has to be updated as well
                if (tempParam.Value != propertyChangedAction.Value.ToString())
                {
                    HomeGenieService.LogEvent(Domains.HomeAutomation_HomeGenie, "ModuleParameterIsChanging(...)", "Parameter value manipulated by automation program", tempParam.Name, propertyChangedAction.Value.ToString() + " => " + tempParam.Value);
                    propertyChangedAction.Value = tempParam.Value;
                }
            }

            ModuleParameter parameter = null;
            try
            {
                // Lookup for the existing module parameter
                parameter = Utility.ModuleParameterGet(module, propertyChangedAction.Path);
                if (parameter == null)
                {
                    module.Properties.Add(new ModuleParameter() {
                        Name = propertyChangedAction.Path,
                        Value = propertyChangedAction.Value.ToString()
                    });
                    parameter = Utility.ModuleParameterGet(module, propertyChangedAction.Path);
                }
                else
                {
                    parameter.Value = propertyChangedAction.Value.ToString();
                }
            }
            catch (Exception ex)
            {
                //HomeGenieService.LogEvent(Domains.HomeAutomation_HomeGenie, "SignalModulePropertyChange(...)", ex.Message, "Exception.StackTrace", ex.StackTrace);
            }

            string eventValue = (propertyChangedAction.Value.GetType() == typeof(String) ? propertyChangedAction.Value.ToString() : JsonConvert.SerializeObject(propertyChangedAction.Value));
            LogBroadcastEvent(
                propertyChangedAction.Domain,
                propertyChangedAction.SourceId,
                propertyChangedAction.SourceType,
                propertyChangedAction.Path,
                eventValue
            );

            // ROUTE EVENT TO LISTENING AutomationPrograms
            if (masterControlProgram != null)
            {
                RoutedEvent eventData = new RoutedEvent() {
                    Sender = sender,
                    Module = module,
                    Parameter = parameter
                };
                //RouteParameterChangedEvent(eventData);
                ThreadPool.QueueUserWorkItem(new WaitCallback(RouteParameterChangedEvent), eventData);
            }
        }
예제 #9
0
        private bool VerifyCondition(ProgramCondition c)
        {
            bool   returnValue     = false;
            string comparisonValue = c.ComparisonValue;

            //
            if (c.Domain == Domains.HomeAutomation_HomeGenie && c.Target == "Automation" && (c.Property == "Scheduler.TimeEvent" || c.Property == "Scheduler.CronEvent"))
            {
                return(homegenie.ProgramManager.SchedulerService.IsScheduling(c.ComparisonValue));
            }
            //
            // if the comparison value starts with ":", then the value is read from another module property
            // eg: ":HomeAutomation.X10/B3/Level"
            if (comparisonValue.StartsWith(":"))
            {
                string[] propertyPath = comparisonValue.Substring(1).Split('/');
                comparisonValue = "";
                if (propertyPath.Length >= 3)
                {
                    string domain       = propertyPath[0];
                    string address      = propertyPath[1];
                    string propertyName = propertyPath[2];
                    var    targetModule = homegenie.Modules.Find(m => m.Domain == domain && m.Address == address);
                    if (targetModule == null)
                    {
                        // abbreviated path, eg: ":X10/B3/Level"
                        targetModule = homegenie.Modules.Find(m => m.Domain.EndsWith("." + domain) && m.Address == address);
                    }
                    //
                    if (targetModule != null)
                    {
                        var mprop = Utility.ModuleParameterGet(targetModule, propertyName);
                        if (mprop != null)
                        {
                            comparisonValue = mprop.Value;
                        }
                    }
                }
            }
            //
            // the following Programs.* parameters are deprecated, just left for compatibility with HG < r340
            //
            ModuleParameter parameter = null;

            if (c.Domain == Domains.HomeAutomation_HomeGenie && c.Target == "Automation")
            {
                parameter      = new ModuleParameter();
                parameter.Name = c.Property;
                switch (parameter.Name)
                {
                case "Programs.DateDay":
                case "Scheduler.DateDay":
                    parameter.Value = DateTime.Now.Day.ToString();
                    break;

                case "Programs.DateMonth":
                case "Scheduler.DateMonth":
                    parameter.Value = DateTime.Now.Month.ToString();
                    break;

                case "Programs.DateDayOfWeek":
                case "Scheduler.DateDayOfWeek":
                    parameter.Value = ((int)DateTime.Now.DayOfWeek).ToString();
                    break;

                case "Programs.DateYear":
                case "Scheduler.DateYear":
                    parameter.Value = DateTime.Now.Year.ToString();
                    break;

                case "Programs.DateHour":
                case "Scheduler.DateHour":
                    parameter.Value = DateTime.Now.Hour.ToString();
                    break;

                case "Programs.DateMinute":
                case "Scheduler.DateMinute":
                    parameter.Value = DateTime.Now.Minute.ToString();
                    break;

                case "Programs.Date":
                case "Scheduler.Date":
                    parameter.Value = DateTime.Now.ToString("YY-MM-dd");
                    break;

                case "Programs.Time":
                case "Scheduler.Time":
                    parameter.Value = DateTime.Now.ToString("HH:mm:ss");
                    break;

                case "Programs.DateTime":
                case "Scheduler.DateTime":
                    parameter.Value = DateTime.Now.ToString("YY-MM-dd HH:mm:ss");
                    break;
                }
            }
            else
            {
                HomeGenie.Data.Module module = homegenie.Modules.Find(m => m.Address == c.Target && m.Domain == c.Domain);
                parameter = module.Properties.Find(delegate(ModuleParameter mp)
                {
                    return(mp.Name == c.Property);
                });
            }
            //
            if (parameter != null)
            {
                IComparable lvalue = parameter.Value;
                IComparable rvalue = comparisonValue;
                //
                double   dval  = 0;
                DateTime dtval = new DateTime();
                //
                if (double.TryParse(parameter.Value.Replace(",", "."), NumberStyles.Float | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out dval))
                {
                    lvalue = dval;
                    rvalue = double.Parse(comparisonValue.Replace(",", "."), NumberStyles.Float | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
                }
                else if (DateTime.TryParse(parameter.Value, out dtval))
                {
                    lvalue = dtval;
                    rvalue = DateTime.Parse(comparisonValue);
                }
                //
                int comparisonresult = lvalue.CompareTo(rvalue);
                if (c.ComparisonOperator == ComparisonOperator.LessThan && comparisonresult < 0)
                {
                    returnValue = true;
                }
                else if (c.ComparisonOperator == ComparisonOperator.Equals && comparisonresult == 0)
                {
                    returnValue = true;
                }
                else if (c.ComparisonOperator == ComparisonOperator.GreaterThan && comparisonresult > 0)
                {
                    returnValue = true;
                }
            }
            return(returnValue);
        }
예제 #10
0
 private object InterfaceControl(Module module, MigInterfaceCommand migCommand)
 {
     object response = null;
     migCommand.Domain = module.Domain;
     migCommand.Address = module.Address;
     try
     {
         response = homegenie.InterfaceControl(migCommand);
     }
     catch(Exception e)
     {
         // TODO: should report the error?
     }
     return response;
 }
예제 #11
0
 private void UpdateZWaveNodeDeviceHandler(byte nodeId, Module module)
 {
     var handler = Utility.ModuleParameterGet(module, Properties.ZWAVENODE_DEVICEHANDLER);
     var node = zwaveController.Devices.Find(zn => zn.NodeId == nodeId);
     if (node != null && node.DeviceHandler != null && (handler == null || handler.Value.Contains(".Generic.")))
     {
         Utility.ModuleParameterSet(
             module,
             Properties.ZWAVENODE_DEVICEHANDLER,
             node.DeviceHandler.GetType().FullName
         );
     }
     else if (handler != null && !handler.Value.Contains(".Generic."))
     {
         // set to last known handler
         node.SetDeviceHandlerFromName(handler.Value);
     }
 }
예제 #12
0
        internal void modules_RefreshZwave()
        {
            lock (systemModules.LockObject) try
                {
                    //
                    // Z-Wave nodes
                    //
                    if (systemConfiguration.GetInterface(Domains.HomeAutomation_ZWave).IsEnabled && zwaveController != null)
                    {
                        foreach (var node in zwaveController.Devices)
                        {
                            if (node.NodeId == 0x01) // zwave controller id
                                continue;
                            //
                            Module module = null;
                            try
                            {
                                module = Modules.Find(delegate(Module o)
                                {
                                    return o.Domain == Domains.HomeAutomation_ZWave && o.Address == node.NodeId.ToString();
                                });
                            }
                            catch
                            {
                            }
                            // add new module
                            if (module == null)
                            {
                                module = new Module();
                                module.Domain = Domains.HomeAutomation_ZWave;
                                module.DeviceType = Module.DeviceTypes.Generic;
                                systemModules.Add(module);
                            }
                            //
                            if (module.DeviceType == Module.DeviceTypes.Generic && node.GenericClass != 0x00)
                            {
                                switch (node.GenericClass)
                                {
                                case 0x10: // BINARY SWITCH
                                    module.Description = "ZWave Switch";
                                    module.DeviceType = Module.DeviceTypes.Switch;
                                    break;

                                case 0x11: // MULTILEVEL SWITCH (DIMMER)
                                    module.Description = "ZWave Multilevel Switch";
                                    module.DeviceType = Module.DeviceTypes.Dimmer;
                                    break;

                                case 0x08: // THERMOSTAT
                                    module.Description = "ZWave Thermostat";
                                    module.DeviceType = Module.DeviceTypes.Thermostat;
                                    break;

                                case 0x20: // BINARY SENSOR
                                    module.Description = "ZWave Sensor";
                                    module.DeviceType = Module.DeviceTypes.Sensor;
                                    break;

                                case 0x21: // MULTI-LEVEL SENSOR
                                    module.Description = "ZWave Multilevel Sensor";
                                    module.DeviceType = Module.DeviceTypes.Sensor;
                                    break;

                                case 0x31: // METER
                                    module.Description = "ZWave Meter";
                                    module.DeviceType = Module.DeviceTypes.Sensor;
                                    break;
                                }
                            }
                            //
                            module.Address = node.NodeId.ToString();
                            if (module.Description == null || module.Description == "")
                            {
                                module.Description = "ZWave Node";
                            }
                            //
                            UpdateZWaveNodeDeviceHandler(node.NodeId, module);
                        }
                        // remove modules if not present in the controller ad if not virtual modules ( Address containing dot '.' instance separator )
                        if (zwaveController.Devices.Count > 0)
                        {
                            systemModules.RemoveAll(m => (m.Domain == Domains.HomeAutomation_ZWave && zwaveController.Devices.FindIndex(n => n.NodeId.ToString() == m.Address) < 0 && m.Address.IndexOf('.') < 0));
                        }
                    }
                    else if (!systemConfiguration.GetInterface(Domains.HomeAutomation_ZWave).IsEnabled)
                    {
                        systemModules.RemoveAll(m => m.Domain == Domains.HomeAutomation_ZWave && m.RoutingNode == "");
                    }
                }
                catch (Exception ex)
                {
                    HomeGenieService.LogEvent(
                        Domains.HomeAutomation_HomeGenie,
                        "modules_RefreshZwave()",
                        ex.Message,
                        "Exception.StackTrace",
                        ex.StackTrace
                    );
                }
        }
예제 #13
0
 internal void modules_RefreshX10()
 {
     lock (systemModules.LockObject) try
         {
             //
             // X10 Units
             //
             if (systemConfiguration.GetInterface(Domains.HomeAutomation_X10).IsEnabled && x10Controller != null)
             {
                 // CM-15 RF receiver
                 // TODO: this shouldn't be created for CM-11
                 var module = systemModules.Find(delegate(Module o)
                 {
                     return o.Domain == Domains.HomeAutomation_X10 && o.Address == "RF";
                 });
                 if (module == null)
                 {
                     module = new Module() {
                         Domain = Domains.HomeAutomation_X10,
                         Address = "RF",
                         DeviceType = Module.DeviceTypes.Sensor
                     };
                     systemModules.Add(module);
                 }
                 //
                 foreach (var kv in x10Controller.ModulesStatus)
                 {
                     module = new Module();
                     try
                     {
                         module = Modules.Find(delegate(Module o)
                         {
                             return o.Domain == Domains.HomeAutomation_X10 && o.Address == kv.Value.Code;
                         });
                     }
                     catch
                     {
                     }
                     // add new module
                     if (module == null)
                     {
                         module = new Module();
                         module.Domain = Domains.HomeAutomation_X10;
                         module.DeviceType = Module.DeviceTypes.Generic;
                         systemModules.Add(module);
                     }
                     //
                     var parameter = module.Properties.Find(mpar => mpar.Name == ModuleParameters.MODPAR_STATUS_LEVEL);
                     if (parameter == null)
                     {
                         module.Properties.Add(new ModuleParameter() {
                             Name = ModuleParameters.MODPAR_STATUS_LEVEL,
                             Value = ((double)kv.Value.Level).ToString()
                         });
                     }
                     else if (parameter.Value != ((double)kv.Value.Level).ToString())
                     {
                         parameter.Value = ((double)kv.Value.Level).ToString();
                     }
                     module.Address = kv.Value.Code;
                     if (module.Description == null || module.Description == "")
                     {
                         module.Description = "X10 Module";
                     }
                 }
             }
             else if (!systemConfiguration.GetInterface(Domains.HomeAutomation_X10).IsEnabled)
             {
                 systemModules.RemoveAll(m => m.Domain == Domains.HomeAutomation_X10 && m.RoutingNode == "");
             }
         }
         catch (Exception ex)
         {
             HomeGenieService.LogEvent(
                 Domains.HomeAutomation_HomeGenie,
                 "modules_RefreshX10()",
                 ex.Message,
                 "Exception.StackTrace",
                 ex.StackTrace
             );
         }
 }
예제 #14
0
        public void SignalPropertyChange(object sender, Module module, MigEvent eventData)
        {
            // ROUTE THE EVENT TO AUTOMATION PROGRAMS, BEFORE COMMITTING THE CHANGE
            var tempParam = new ModuleParameter() {
                Name = eventData.Property,
                Value = eventData.Value.ToString()
            };
            var routedEvent = new RoutedEvent() {
                Sender = sender,
                Module = module,
                Parameter = tempParam
            };

            // Route event to Programs->ModuleIsChangingHandler
            RoutePropertyBeforeChangeEvent(routedEvent);

            // If the value has been manipulated by an automation program
            // so the event has to be updated as well
            if (tempParam.Value != eventData.Value.ToString())
            {
                MigService.Log.Debug("Parameter value manipulated by automation program (Name={0}, OldValue={1}, NewValue={2})", tempParam.Name, eventData.Value.ToString(), tempParam.Value);
                // Update the event value to the new value
                eventData.Value = tempParam.Value;
            }

            // Route event to Programs->ModuleIsChangingHandler
            ThreadPool.QueueUserWorkItem(new WaitCallback(RoutePropertyChangedEvent), routedEvent);
        }
예제 #15
0
 private void InterfaceControl(Module module, MIGInterfaceCommand migCommand)
 {
     migCommand.Domain = module.Domain;
     migCommand.NodeId = module.Address;
     homegenie.InterfaceControl(migCommand);
 }
예제 #16
0
 private void modules_RefreshInterface(MIGInterface iface)
 {
     // TODO: read IsEnabled instead of IsConnected
     if (migService.Configuration.GetInterface(iface.Domain).IsEnabled)
     {
         var interfaceModules = iface.GetModules();
         if (interfaceModules.Count > 0)
         {
             // delete removed modules
             var deleted = systemModules.FindAll(m => m.Domain == iface.Domain && (interfaceModules.Find(m1 => m1.Address == m.Address && m1.Domain == m.Domain) == null));
             foreach (var mod in deleted)
             {
                 var virtualParam = Utility.ModuleParameterGet(mod, Properties.VIRTUALMODULE_PARENTID);
                 if (virtualParam == null || virtualParam.DecimalValue == 0)
                 {
                     Module garbaged = modulesGarbage.Find(m => m.Domain == mod.Domain && m.Address == mod.Address);
                     if (garbaged != null) modulesGarbage.Remove(garbaged);
                     modulesGarbage.Add(mod);
                     systemModules.Remove(mod);
                 }
             }
             //
             foreach (var migModule in interfaceModules)
             {
                 Module module = systemModules.Find(o => o.Domain == migModule.Domain && o.Address == migModule.Address);
                 if (module == null)
                 {
                     // try restoring from garbage
                     module = modulesGarbage.Find(o => o.Domain == migModule.Domain && o.Address == migModule.Address);
                     if (module != null)
                     {
                         systemModules.Add(module);
                     }
                     else
                     {
                         module = new Module();
                         module.Domain = migModule.Domain;
                         module.Address = migModule.Address;
                         systemModules.Add(module);
                     }
                 }
                 //
                 if (String.IsNullOrEmpty(module.Description))
                 {
                     module.Description = migModule.Description;
                 }
                 if (module.DeviceType == ModuleTypes.Generic)
                 {
                     module.DeviceType = migModule.ModuleType;
                 }
             }
         }
     }
     else
     {
         var deleted = systemModules.FindAll(m => m.Domain == iface.Domain);
         foreach (var mod in deleted)
         {
             var virtualParam = Utility.ModuleParameterGet(mod, Properties.VIRTUALMODULE_PARENTID);
             if (virtualParam == null || virtualParam.DecimalValue == 0)
             {
                 Module garbaged = modulesGarbage.Find(m => m.Domain == mod.Domain && m.Address == mod.Address);
                 if (garbaged != null) modulesGarbage.Remove(garbaged);
                 modulesGarbage.Add(mod);
                 systemModules.Remove(mod);
             }
         }
     }
 }
예제 #17
0
 public ModuleEvent(Module module, ModuleParameter parameter)
 {
     this.Module = module;
     this.Parameter = parameter;
 }
예제 #18
0
 internal void modules_RefreshPrograms()
 {
     lock (systemModules.LockObject)
     try
     {
         //
         // ProgramEngine programs (modules)
         //
         if (masterControlProgram != null)
         {
             lock (masterControlProgram.Programs.LockObject)
             foreach (var program in masterControlProgram.Programs)
             {
                 Module module = null;
                 try
                 {
                     module = systemModules.Find(delegate(Module o)
                     {
                         return o.Domain == Domains.HomeAutomation_HomeGenie_Automation && o.Address == program.Address.ToString();
                     });
                 }
                 catch
                 {
                 }
                 //
                 if (module != null && program.Type.ToLower() == "wizard" && !program.IsEnabled && module.RoutingNode == "")
                 {
                     systemModules.Remove(module);
                     continue;
                 }
                 else if (/*program.Type.ToLower() != "wizard" &&*/ !program.IsEnabled)
                 {
                     continue;
                 }
                 //
                 // add new module
                 if (module == null)
                 {
                     module = new Module();
                     module.Domain = Domains.HomeAutomation_HomeGenie_Automation;
                     if (program.Type.ToLower() == "wizard")
                     {
                         Utility.ModuleParameterSet(
                             module,
                             Properties.WIDGET_DISPLAYMODULE,
                             "homegenie/generic/program"
                         );
                     }
                     systemModules.Add(module);
                 }
                 //
                 module.Name = program.Name;
                 module.Address = program.Address.ToString();
                 module.DeviceType = MIG.ModuleTypes.Program;
                 //module.Description = "Wizard Script";
             }
         }
     }
     catch (Exception ex)
     {
         LogError(
             Domains.HomeAutomation_HomeGenie,
             "modules_RefreshPrograms()",
             ex.Message,
             "Exception.StackTrace",
             ex.StackTrace
         );
     }
 }
예제 #19
0
        public void SignalPropertyChange(object sender, Module module, MigEvent eventData)
        {
            ModuleParameter parameter = null;
            try
            {
                // Lookup for the existing module parameter
                parameter = Utility.ModuleParameterGet(module, eventData.Property);
                if (parameter == null)
                {
                    parameter = new ModuleParameter() {
                        Name = eventData.Property,
                        Value = eventData.Value.ToString()
                    };
                    module.Properties.Add(parameter);
                }
                else
                {
                    parameter.Value = eventData.Value.ToString();
                }
            }
            catch (Exception ex)
            {
                HomeGenieService.LogError(ex);
            }

            var routedEvent = new RoutedEvent() {
                Sender = sender,
                Module = module,
                Parameter = parameter
            };

            // Route event to Programs->ModuleIsChangingHandler
            if (RoutePropertyBeforeChangeEvent(routedEvent))
            {
                // Route event to Programs->ModuleChangedHandler
                ThreadPool.QueueUserWorkItem(new WaitCallback(RoutePropertyChangedEvent), routedEvent);
            }
        }
예제 #20
0
 private object InterfaceControl(Module module, MIGInterfaceCommand migCommand)
 {
     migCommand.Domain = module.Domain;
     migCommand.NodeId = module.Address;
     return homegenie.InterfaceControl(migCommand);
 }
예제 #21
0
        public void SignalPropertyChange(object sender, Module module, MigEvent eventData)
        {
            ModuleParameter parameter = Utility.ModuleParameterGet(module, eventData.Property);

            var routedEvent = new RoutedEvent() {
                Sender = sender,
                Module = module,
                Parameter = parameter
            };

            // Route event to Programs->ModuleIsChangingHandler
            if (RoutePropertyBeforeChangeEvent(routedEvent))
            {
                // Route event to Programs->ModuleChangedHandler
                ThreadPool.QueueUserWorkItem(new WaitCallback(RoutePropertyChangedEvent), routedEvent);
            }
        }
예제 #22
0
 private void modules_RefreshInterface(MigInterface iface)
 {
     if (migService.Configuration.GetInterface(iface.GetDomain()).IsEnabled)
     {
         var interfaceModules = iface.GetModules();
         if (interfaceModules.Count > 0)
         {
             // delete removed modules
             var deleted = systemModules.FindAll(m => m.Domain == iface.GetDomain() && (interfaceModules.Find(m1 => m1.Address == m.Address && m1.Domain == m.Domain) == null));
             foreach (var mod in deleted)
             {
                 // only "real" modules defined by mig interfaces are considered
                 var virtualParam = Utility.ModuleParameterGet(mod, Properties.VirtualModuleParentId);
                 if (virtualParam == null || virtualParam.DecimalValue == 0)
                 {
                     Module garbaged = modulesGarbage.Find(m => m.Domain == mod.Domain && m.Address == mod.Address);
                     if (garbaged != null) modulesGarbage.Remove(garbaged);
                     modulesGarbage.Add(mod);
                     systemModules.Remove(mod);
                 }
             }
             //
             foreach (var migModule in interfaceModules)
             {
                 Module module = systemModules.Find(o => o.Domain == migModule.Domain && o.Address == migModule.Address);
                 if (module == null)
                 {
                     // try restoring from garbage
                     module = modulesGarbage.Find(o => o.Domain == migModule.Domain && o.Address == migModule.Address);
                     if (module != null)
                     {
                         systemModules.Add(module);
                     }
                     else
                     {
                         module = new Module();
                         module.Domain = migModule.Domain;
                         module.Address = migModule.Address;
                         systemModules.Add(module);
                     }
                 }
                 if (String.IsNullOrEmpty(module.Description))
                 {
                     module.Description = migModule.Description;
                 }
                 if (module.DeviceType == ModuleTypes.Generic)
                 {
                     module.DeviceType = migModule.ModuleType;
                 }
             }
         }
     }
     else
     {
         var deleted = systemModules.FindAll(m => m.Domain == iface.GetDomain());
         foreach (var mod in deleted)
         {
             var virtualParam = Utility.ModuleParameterGet(mod, Properties.VirtualModuleParentId);
             if (virtualParam == null || virtualParam.DecimalValue == 0)
             {
                 Module garbaged = modulesGarbage.Find(m => m.Domain == mod.Domain && m.Address == mod.Address);
                 if (garbaged != null) modulesGarbage.Remove(garbaged);
                 modulesGarbage.Add(mod);
                 systemModules.Remove(mod);
             }
         }
     }
 }
예제 #23
0
 public ModuleHelper(HomeGenieService hg, Module module)
     : base(hg)
 {
     this.module = module;
 }
예제 #24
0
        internal void modules_RefreshVirtualModules()
        {
            lock (systemModules.LockObject)
            lock (virtualModules.LockObject)
            try
            {
                //
                // Virtual Modules
                //
                foreach (var virtualModule in virtualModules)
                {
                    ProgramBlock program = masterControlProgram.Programs.Find(p => p.Address.ToString() == virtualModule.ParentId);
                    if (program == null) continue;
                    //
                    var virtualModuleWidget = Utility.ModuleParameterGet(virtualModule, Properties.WidgetDisplayModule);
                    //
                    Module module = Modules.Find(o => {
                        // main program module...
                        bool found = (o.Domain == virtualModule.Domain && o.Address == virtualModule.Address && o.Address == virtualModule.ParentId);
                        // ...or virtual module
                        if (!found && o.Domain == virtualModule.Domain && o.Address == virtualModule.Address && o.Address != virtualModule.ParentId)
                        {
                            var prop = Utility.ModuleParameterGet(o, Properties.VirtualModuleParentId);
                            if (prop != null && prop.Value == virtualModule.ParentId) found = true;
                        }
                        return found;
                    });

                    if (!program.IsEnabled)
                    {
                        if (module != null && module.RoutingNode == "" && virtualModule.ParentId != module.Address)
                        {
                            // copy instance module properties to virtualmodules before removing
                            virtualModule.Name = module.Name;
                            virtualModule.DeviceType = module.DeviceType;
                            virtualModule.Properties.Clear();
                            foreach (var p in module.Properties)
                            {
                                virtualModule.Properties.Add(p);
                            }
                            systemModules.Remove(module);
                        }
                        continue;
                    }
                    //else if (virtualModule.ParentId == virtualModule.Address)
                    //{
                    //    continue;
                    //}

                    if (module == null)
                    {
                        // add new module
                        module = new Module();
                        systemModules.Add(module);
                        // copy properties from virtualmodules
                        foreach (var p in virtualModule.Properties)
                        {
                            module.Properties.Add(p);
                        }
                    }

                    // module inherits props from associated virtual module
                    module.Domain = virtualModule.Domain;
                    module.Address = virtualModule.Address;
                    if (module.DeviceType == MIG.ModuleTypes.Generic && virtualModule.DeviceType != ModuleTypes.Generic)
                    {
                        module.DeviceType = virtualModule.DeviceType;
                    }
                    // associated module's name of an automation program cannot be changed
                    if (module.Name == "" || (module.DeviceType == MIG.ModuleTypes.Program && virtualModule.Name != ""))
                    {
                        module.Name = virtualModule.Name;
                    }
                    module.Description = virtualModule.Description;
                    //
                    if (virtualModule.ParentId != virtualModule.Address)
                    {
                        Utility.ModuleParameterSet(
                            module,
                            Properties.VirtualModuleParentId,
                            virtualModule.ParentId
                        );
                    }
                    var moduleWidget = Utility.ModuleParameterGet(module, Properties.WidgetDisplayModule);
                    // if a widget is specified on virtual module then we force module to display using this
                    if ((virtualModuleWidget != null && (virtualModuleWidget.Value != "" || moduleWidget == null)) && (moduleWidget == null || (moduleWidget.Value != virtualModuleWidget.Value)))
                    {
                        Utility.ModuleParameterSet(
                            module,
                            Properties.WidgetDisplayModule,
                            virtualModuleWidget.Value
                        );
                    }
                }
            }
            catch (Exception ex)
            {
                LogError(
                    Domains.HomeAutomation_HomeGenie,
                    "modules_RefreshVirtualModules()",
                    ex.Message,
                    "Exception.StackTrace",
                    ex.StackTrace
                );
            }
        }
예제 #25
0
        internal void modules_RefreshMisc()
        {
            // TODO: create method MIGInterface.GetModules() and abstract this draft code
            string currentDomain = "";
            lock (systemModules.LockObject) try
                {
                    //
                    // UPnP devices
                    //
                    currentDomain = Domains.Protocols_UPnP;
                    if (systemConfiguration.GetInterface(currentDomain) != null && systemConfiguration.GetInterface(currentDomain).IsEnabled && ((MIG.Interfaces.Protocols.UPnP)migService.Interfaces[ currentDomain ]).IsConnected)
                    {
                        var upnpInterface = ((MIG.Interfaces.Protocols.UPnP)migService.Interfaces[ currentDomain ]);
                        for (int d = 0; d < upnpInterface.UpnpControlPoint.DeviceTable.Count; d++)
                        {
                            var device = (UPnPDevice)(upnpInterface.UpnpControlPoint.DeviceTable[ d ]);
                            Module module = null;
                            try
                            {
                                module = Modules.Find(delegate(Module o)
                                {
                                    return o.Domain == currentDomain && o.Address == device.UniqueDeviceName;
                                });
                            }
                            catch
                            {
                            }
                            // add new module
                            if (module == null)
                            {
                                module = new Module();
                                module.Domain = currentDomain;
                                module.DeviceType = Module.DeviceTypes.MediaTransmitter;
                                if (device.StandardDeviceType == "MediaRenderer")
                                {
                                    module.DeviceType = Module.DeviceTypes.MediaReceiver;
                                    Utility.ModuleParameterSet(
                                        module,
                                        Properties.WIDGET_DISPLAYMODULE,
                                        "homegenie/generic/mediareceiver"
                                    );
                                }
                                else if (device.StandardDeviceType == "MediaServer")
                                {
                                    Utility.ModuleParameterSet(
                                        module,
                                        Properties.WIDGET_DISPLAYMODULE,
                                        "homegenie/generic/mediaserver"
                                    );
                                }
                                else if (device.StandardDeviceType == "SwitchPower")
                                {
                                    module.DeviceType = Module.DeviceTypes.Switch;
                                }
                                else if (device.StandardDeviceType == "BinaryLight")
                                {
                                    module.DeviceType = Module.DeviceTypes.Light;
                                }
                                else if (device.StandardDeviceType == "DimmableLight")
                                {
                                    module.DeviceType = Module.DeviceTypes.Dimmer;
                                }
                                else if (device.HasPresentation)
                                {
                                    Utility.ModuleParameterSet(
                                        module,
                                        Properties.WIDGET_DISPLAYMODULE,
                                        "homegenie/generic/link"
                                    );
                                    Utility.ModuleParameterSet(module, "FavouritesLink.Url", device.PresentationURL);
                                }
                                Utility.ModuleParameterSet(module, "UPnP.DeviceURN", device.DeviceURN);
                                Utility.ModuleParameterSet(module, "UPnP.DeviceURN_Prefix", device.DeviceURN_Prefix);
                                Utility.ModuleParameterSet(module, "UPnP.FriendlyName", device.FriendlyName);
                                Utility.ModuleParameterSet(module, "UPnP.LocationURL", device.LocationURL);
                                Utility.ModuleParameterSet(module, "UPnP.Version", device.Major + "." + device.Minor);
                                Utility.ModuleParameterSet(module, "UPnP.ModelName", device.ModelName);
                                Utility.ModuleParameterSet(module, "UPnP.ModelNumber", device.ModelNumber);
                                Utility.ModuleParameterSet(module, "UPnP.ModelDescription", device.ModelDescription);
                                if (device.ModelURL != null)
                                {
                                    Utility.ModuleParameterSet(module, "UPnP.ModelURL", device.ModelURL.ToString());
                                }
                                Utility.ModuleParameterSet(module, "UPnP.Manufacturer", device.Manufacturer);
                                Utility.ModuleParameterSet(module, "UPnP.ManufacturerURL", device.ManufacturerURL);
                                Utility.ModuleParameterSet(module, "UPnP.PresentationURL", device.PresentationURL);
                                Utility.ModuleParameterSet(module, "UPnP.UniqueDeviceName", device.UniqueDeviceName);
                                Utility.ModuleParameterSet(module, "UPnP.SerialNumber", device.SerialNumber);
                                Utility.ModuleParameterSet(
                                    module,
                                    "UPnP.StandardDeviceType",
                                    device.StandardDeviceType
                                );
                                systemModules.Add(module);
                            }
                            //
                            module.Address = device.UniqueDeviceName;
                            module.Description = device.FriendlyName + " (" + device.ModelName + ")";
                        }
                    }
                    else
                    {
                        systemModules.RemoveAll(m => m.Domain == currentDomain && m.RoutingNode == "");
                    }
                    //
                    // Raspberry Pi GPIO
                    //
                    currentDomain = Domains.EmbeddedSystems_RaspiGPIO;
                    if (systemConfiguration.GetInterface(currentDomain) != null && systemConfiguration.GetInterface(currentDomain).IsEnabled && ((MIG.Interfaces.EmbeddedSystems.RaspiGPIO)migService.Interfaces[ currentDomain ]).IsConnected)
                    {
                        foreach (var rv in ((MIG.Interfaces.EmbeddedSystems.RaspiGPIO)migService.Interfaces[currentDomain]).GpioPins)
                        {
                            Module module = null;
                            try
                            {
                                module = Modules.Find(delegate(Module o)
                                {
                                    return o.Domain == currentDomain && o.Address == rv.Key;
                                });
                            }
                            catch
                            {
                            }
                            // add new module
                            if (module == null)
                            {
                                module = new Module();
                                module.Domain = currentDomain;
                                module.DeviceType = Module.DeviceTypes.Switch;
                                systemModules.Add(module);
                            }
                            //
                            module.Address = rv.Key;
                            module.Description = "Raspberry Pi GPIO";
                            //
                            Utility.ModuleParameterSet(
                                module,
                                ModuleParameters.MODPAR_STATUS_LEVEL,
                                (((bool)rv.Value) ? "1" : "0")
                            );
                        }
                    }
                    else
                    {
                        systemModules.RemoveAll(m => m.Domain == currentDomain && m.RoutingNode == "");
                    }
                    //
                    // Weecoboard-4m GPIO
                    //
                    currentDomain = Domains.EmbeddedSystems_Weeco4mGPIO;
                    if (systemConfiguration.GetInterface(currentDomain) != null && systemConfiguration.GetInterface(currentDomain).IsEnabled && ((MIG.Interfaces.EmbeddedSystems.Weeco4mGPIO)migService.Interfaces[ currentDomain ]).IsConnected)
                    {
                        foreach (var rv in ((MIG.Interfaces.EmbeddedSystems.Weeco4mGPIO)migService.Interfaces[currentDomain]).RegPins)
                        {
                            Module module = null;
                            try
                            {
                                module = Modules.Find(delegate(Module o)
                                {
                                    return o.Domain == currentDomain && o.Address == rv.Key;
                                });
                            }
                            catch
                            {
                            }
                            // add new module
                            if (module == null)
                            {
                                module = new Module();
                                module.Domain = currentDomain;
                                module.Description = "Weecoboard Register";
                                module.DeviceType = Module.DeviceTypes.Sensor;
                                systemModules.Add(module);
                            }
                            //
                            module.Address = rv.Key;
                            module.Description = "Weeco-4M Register";
                            //
                            Utility.ModuleParameterSet(module, ModuleParameters.MODPAR_STATUS_LEVEL, rv.Value);
                        }

                        // digital in/out
                        foreach (var rv in ((MIG.Interfaces.EmbeddedSystems.Weeco4mGPIO)migService.Interfaces[currentDomain]).GpioPins)
                        {
                            Module module = null;
                            try
                            {
                                module = Modules.Find(delegate(Module o)
                                {
                                    return o.Domain == currentDomain && o.Address == rv.Key;
                                });
                            }
                            catch
                            {
                            }
                            // add new module
                            if (module == null)
                            {
                                module = new Module();
                                module.Domain = currentDomain;
                                module.Description = "Weecoboard GPIO";
                                module.DeviceType = Module.DeviceTypes.Switch;
                                systemModules.Add(module);
                            }
                            //
                            module.Address = rv.Key;
                            module.Description = "Weeco-4M GPIO";
                            //
                            Utility.ModuleParameterSet(
                                module,
                                ModuleParameters.MODPAR_STATUS_LEVEL,
                                (((bool)rv.Value) ? "1" : "0")
                            );
                        }
                    }
                    else
                    {
                        systemModules.RemoveAll(m => m.Domain == currentDomain && m.RoutingNode == "");
                    }
                    //
                    //
                    currentDomain = Domains.Media_CameraInput;
                    if (systemConfiguration.GetInterface(currentDomain) != null && systemConfiguration.GetInterface(currentDomain).IsEnabled && ((MIG.Interfaces.Media.CameraInput)migService.Interfaces[ currentDomain ]).IsConnected)
                    {
                        Module module = null;
                        try
                        {
                            module = Modules.Find(delegate(Module o)
                            {
                                return o.Domain == currentDomain && o.Address == "AV0";
                            });
                        }
                        catch
                        {
                        }
                        // add new module
                        if (module == null)
                        {
                            module = new Module();
                            module.Domain = currentDomain;
                            module.DeviceType = Module.DeviceTypes.Sensor;
                            Utility.ModuleParameterSet(
                                module,
                                Properties.WIDGET_DISPLAYMODULE,
                                "homegenie/generic/camerainput"
                            );
                            systemModules.Add(module);
                        }
                        //
                        module.Address = "AV0";
                        module.Description = "Video 4 Linux Video Input";
                    }
                    else
                    {
                        systemModules.RemoveAll(m => m.Domain == currentDomain && m.RoutingNode == "");
                    }
                    //
                    //
                    currentDomain = Domains.HomeAutomation_W800RF;
                    if (systemConfiguration.GetInterface(currentDomain) != null && systemConfiguration.GetInterface(currentDomain).IsEnabled)
                    {
                        var w800rf = systemModules.Find(delegate(Module o)
                        {
                            return o.Domain == Domains.HomeAutomation_W800RF && o.Address == "RF";
                        });
                        if (w800rf == null)
                        {
                            w800rf = new Module() {
                                Domain = Domains.HomeAutomation_W800RF,
                                Address = "RF",
                                DeviceType = Module.DeviceTypes.Sensor
                            };
                            systemModules.Add(w800rf);
                        }
                    }
                    else
                    {
                        systemModules.RemoveAll(m => m.Domain == currentDomain && m.RoutingNode == "");
                    }
                    //
                    //
                    currentDomain = Domains.Controllers_LircRemote;
                    if (systemConfiguration.GetInterface(currentDomain) != null && systemConfiguration.GetInterface(currentDomain).IsEnabled)
                    {
                        var lirc = systemModules.Find(delegate(Module o)
                        {
                            return o.Domain == Domains.Controllers_LircRemote && o.Address == "IR";
                        });
                        if (lirc == null)
                        {
                            lirc = new Module() {
                                Domain = Domains.Controllers_LircRemote,
                                Address = "IR",
                                DeviceType = Module.DeviceTypes.Sensor
                            };
                            systemModules.Add(lirc);
                        }
                    }
                    else
                    {
                        systemModules.RemoveAll(m => m.Domain == currentDomain && m.RoutingNode == "");
                    }

                }
                catch (Exception ex)
                {
                    HomeGenieService.LogEvent(
                        Domains.HomeAutomation_HomeGenie,
                        "modules_RefreshMisc()",
                        ex.Message,
                        "Exception.StackTrace",
                        ex.StackTrace
                    );
                }
        }