more G-Labs products

Author Topic: Fibaro Motion Sensor and Device Handler.  (Read 1720 times)

January 08, 2015, 12:56:20 PM
Read 1720 times

j10n

  • *
  • Information
  • Newbie
  • Posts: 2
Hi,
first of all i want to say thank you for this awesome piece of software...
I noticed probably a bug in the association of the Device Handler for battery zwave sensor...
I have a FIbaro Motion Sensor , the first time that I try to configure it , the sensor is awake, so HomeGenie is able to detect the type and manufacturer and save his DeviceHandler ( also in files ) and everything seems to work well .
But if i reboot HG , program does not restore the module property "Device Handler" , so i have to manually wake all my sensors and get the product info by HG to fix it...

I've done a dirty solution by changing code by myself in order to restore the property from the module configuration and pass it to the ZWave Node at the start of HG...
I don't know if it can be useful for you, but i post my code here...

I create a new fake command REFRESH_DEVICE_HANDLER and i pass the property of the module.
In function modules_RefreshInterface of class HomeGenieService  just before lines:
Code: [Select]
if (String.IsNullOrEmpty(module.Description))
                        {
                            module.Description = migModule.Description;
                        }
                        if (module.DeviceType == ModuleTypes.Generic)
                        {
                            module.DeviceType = migModule.ModuleType;
                        }

i added those lines...
 
Code: [Select]
                        if (iface.Domain.CompareTo("HomeAutomation.ZWave") == 0)
                        {
                            Console.WriteLine("CERCO IL PARAMETRO ");
                            var handle=module.Properties.Find(x => x.Name == "ZWaveNode.DeviceHandler");
                         
                            if(handle!=null)
                            {
                                Console.WriteLine("TROVATO PARAMETRO ");
                                var nodo = interfaceModules.Find(m1 => m1.Address == module.Address && m1.Domain == module.Domain);
                                if (nodo != null)
                                {
                                    Console.WriteLine("PRESO IL NODO ");
                                    iface.InterfaceControl(new MIGInterfaceCommand(module.Domain + "/" + nodo.Address + "/" + ZWave.Command.REFRESH_DEVICE_HANDLER + "/" + handle.Value));
                                }
                            }
                        }


and in the ZWave's Interface Control i added

Code: [Select]
else if( command == Command.REFRESH_DEVICE_HANDLER)
                {
                    var node = controller.GetDevice((byte)int.Parse(nodeId));
                    node.SetDeviceHandlerFromName(request.GetOption(0));
                }



I know it's a kinda dirty, but it was the first solution that comes in my mind... maybe in the next release is possibile a better fix?

Hi,
Pinocchio

January 11, 2015, 01:23:30 PM
Reply #1

Bounz

  • ***
  • Information
  • Full Member
  • Posts: 94
Interesting solution, but what if ZWave MIG interface does not have time to find (discover) the nodes at the time of execution of the modules_RefreshInterface function? As I see in HomeGenieService.cs interfaces are starting after loading modules:

Code: (c#) [Select]
public void LoadConfiguration()
        {
            LoadSystemConfig();
            //
            // load modules data
            //
            LoadModules();
            //
           
            .....

            //
            // start MIG Interfaces
            //
            try
            {
                migService.StartInterfaces();
            }
            catch
            {
                //TODO: log error
            }
            // force re-generation of Modules list
            //_jsonSerializedModules(false);
            modules_RefreshAll();
            //
            // enable automation programs engine
            //
            masterControlProgram.Enabled = true;
        }


I assume in such situation controller.GetDevice() might return null.
« Last Edit: January 11, 2015, 01:45:40 PM by Bounz »

January 12, 2015, 10:54:42 AM
Reply #2

j10n

  • *
  • Information
  • Newbie
  • Posts: 2
Good point... as i said it was only a temporary solution...

I think it would be great if we can have a way to pass module's properties to respectives interface nodes...