Property readonly

HouseBot Plugin Development Discussions.
Post Reply
DsA
Member
Posts: 7
Joined: Sun Nov 16, 2008 3:47 am

Property readonly

Post by DsA »

How to prohibit editing of property by the user in Device Plugin?
ScottBot
Site Admin
Posts: 2786
Joined: Thu Feb 13, 2003 6:46 pm
Location: Georgia (USA)
Contact:

Re: Property readonly

Post by ScottBot »

If you are creating your own Device using the SDK, set the 'eIOType ioType' parameter of the 'pHB_RegisterDeviceProperty' call to 'ioInputOnly'.
Scott
DsA
Member
Posts: 7
Joined: Sun Nov 16, 2008 3:47 am

Re: Property readonly

Post by DsA »

Thanks. Still a question. How to set restriction of entered values, for example from 0 to 100?
ScottBot
Site Admin
Posts: 2786
Joined: Thu Feb 13, 2003 6:46 pm
Location: Georgia (USA)
Contact:

Re: Property readonly

Post by ScottBot »

If you have derived a class from the CHardwareInterface class, you just need to call

Code: Select all

CHardwareInstance::SetPropertyLimits( const char* szPropertyName, int nLowLimit, int nHighLimit )
or pHB_SetPropertyLimits if not using CHardwareInterface. Call it right after you register the Property (RegisterHardwareModuleProperty).
Scott
DsA
Member
Posts: 7
Joined: Sun Nov 16, 2008 3:47 am

Re: Property readonly

Post by DsA »

It in Hardware Interface Plugin. I have not found the same function in Device Plugin?
ScottBot
Site Admin
Posts: 2786
Joined: Thu Feb 13, 2003 6:46 pm
Location: Georgia (USA)
Contact:

Re: Property readonly

Post by ScottBot »

DsA wrote:It in Hardware Interface Plugin. I have not found the same function in Device Plugin?
You're right. Sorry I was confused.

You can't restrict what a user will enter for a Property Value. The best you can do is to offer suggestions by associating Property Values to a Property by calling pHB_CreateDevicePropertyValue() when registering a new Property for the first time.

You can still generate an error or just refuse to change the Device Property in the plugin if the user tries to change the Property to an invalid value.
Scott
DsA
Member
Posts: 7
Joined: Sun Nov 16, 2008 3:47 am

Re: Property readonly

Post by DsA »

I create properties calling pHB_CreateDevicePropertyValue () but how thus to set values of properties? It is possible a code example?
ScottBot
Site Admin
Posts: 2786
Joined: Thu Feb 13, 2003 6:46 pm
Location: Georgia (USA)
Contact:

Re: Property readonly

Post by ScottBot »

Here's a snippet from the ::RegisterProperties() method of a Device plugin.

Code: Select all

// First attempt to register the Property (wizard version of registration that has prompt)
if (!m_CallBackInfo.pHB_RegisterDevicePropertyUsingWizard( m_CallBackInfo.m_hModuleHandle, 
                                                           nDeviceNumber, 
                                                           "Insteon Group", 
                                                           "Group", FALSE, 
                                                           "1", 
                                                           ioInputAndOutput, 
                                                           TRUE, 
                                                           TRUE, 
                                                           FALSE, 
                                                           FALSE, 
                                                           "Enter the group number" ))
{
   // The registration failed.  This is probably because this is the first time the property is being registered.
   // Attempt to create the new "Insteon Group" Property.
   if (!m_CallBackInfo.pHB_CreateDeviceProperty( "Insteon Group", "Group", ptNumeric ))
      return( FALSE );

   // The Property created successfully.  We can optionally add values to the Property.
   // This example creates numeric values from 1 to 256
   m_CallBackInfo.pHB_CreateDevicePropertyValue( "Insteon Group", "[1 - 256]" );

   // If not adding a sequential numeric range like above, call pHB_CreateDevicePropertyValue() for
   // each value to be added to the Property.
//   m_CallBackInfo.pHB_CreateDevicePropertyValue( "Insteon Group", "1" );
//   m_CallBackInfo.pHB_CreateDevicePropertyValue( "Insteon Group", "2" );
//   m_CallBackInfo.pHB_CreateDevicePropertyValue( "Insteon Group", "3" );
                                             
   // Now that the Property has been created, we can try and register it again (same call as at the top)          
   if (!m_CallBackInfo.pHB_RegisterDevicePropertyUsingWizard( m_CallBackInfo.m_hModuleHandle, 
                                                              nDeviceNumber, 
                                                              "Insteon Group", 
                                                              "Group", 
                                                              FALSE, 
                                                              "1", 
                                                              ioInputAndOutput, 
                                                              TRUE, 
                                                              TRUE, 
                                                              FALSE, 
                                                              FALSE, 
                                                              "Enter the group number" ))
      return( FALSE );
}
Scott
DsA
Member
Posts: 7
Joined: Sun Nov 16, 2008 3:47 am

Re: Property readonly

Post by DsA »

I thank, all works =)
vc1234
Member
Posts: 10
Joined: Thu Jan 08, 2009 10:19 am

Re: Property readonly

Post by vc1234 »

I've attached a dll with the read-only Temperature property (ioInputOnly). I believe the device has to be recreated for ioInputOnly (should it not be rather called ioOutputOnly ?) to take effect.
Attachments
TemperPlugin.rar
(13.24 KiB) Downloaded 422 times
EdInNY
Member
Posts: 2
Joined: Sun Jun 14, 2009 8:11 am
Location: Endicott, NY

Re: Property readonly

Post by EdInNY »

Scott,

Just an FYI;
The comments in DeviceAPI.h say "ioType - Not currently used, but can/should be set correctly."

- Ed
ScottBot
Site Admin
Posts: 2786
Joined: Thu Feb 13, 2003 6:46 pm
Location: Georgia (USA)
Contact:

Re: Property readonly

Post by ScottBot »

Thanks. I'll update the comments, since that argument is now used.
Scott
Post Reply