Page 2 of 2

Posted: Mon Mar 01, 2004 8:19 pm
by ScottBot
ericvic wrote:how to I add what the valid values are for a property? i.e. I'm going to have a fan property that should have 'on' and 'auto'.
First, you don't *have* to assign valid values to a Property. You can leave it open to accept any value. To help the user you should/could give the Property a list of valid values. These values still don't restrict the user from entering other values, but it helps in picking values in the UI.



Also, if you are going to add values, you shouldn't use a stock Property (as I described in a previous message). When you add the valid values to a Property, it effects all Devices that use that Property. Therefore you should create your own Property as I described before.



pHB_CreateDevicePropertyValue(...) is what you are looking for. It will add a valid value to a Property. You have to call it once for each value.


Code: Select all

m_CallBackInfo.pHB_CreateDevicePropertyValue( "Fan", "On" );
m_CallBackInfo.pHB_CreateDevicePropertyValue( "Fan", "Auto" );

Posted: Mon Mar 01, 2004 8:49 pm
by ericvic
Scott,



Do I have to call pHB_CreateDevicePropertyValue each time I register the property or only when I create the property?



Also would I use ptAlphaList or ptAlpha as the ePropertyType in the create call?



Eric

Posted: Tue Mar 02, 2004 8:11 am
by ScottBot
ericvic wrote:Do I have to call pHB_CreateDevicePropertyValue each time I register the property or only when I create the property?
It doesn't matter. If the value already exists, the function will still return TRUE and do nothing.

The way I usually do it when creating my own Properties is to do something like:

Code: Select all

if (!m_CallBackInfo.pHB_RegisterDeviceProperty(...))
{
   if(!m_CallBackInfo.pHB_CreateDeviceProperty(...))
      return( FALSE );

   if(!m_CallBackInfo.pHB_RegisterDeviceProperty(...))
      return( FALSE );

   if(!if (!m_CallBackInfo.pHB_CreateDevicePropertyValue(...))
      return( FALSE );
}
return( TRUE );
This will create everything only if the first registration fails. It would fail because this is the first time the plugin has run and can then do all of the one-time setup.
Also would I use ptAlphaList or ptAlpha as the ePropertyType in the create call?
Use ptAlpha.

Posted: Tue Mar 02, 2004 9:36 am
by ericvic
Scott,



That is what I figured and so I had already coded it that way.



Eric