Read Only Properties

HouseBot Plugin Development Discussions.
ScottBot
Site Admin
Posts: 2787
Joined: Thu Feb 13, 2003 6:46 pm
Location: Georgia (USA)
Contact:

Post 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" );
Scott
ericvic
Senior Member
Posts: 144
Joined: Thu Feb 26, 2004 11:06 am
Location: Irondale, AL
Contact:

Post 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
ScottBot
Site Admin
Posts: 2787
Joined: Thu Feb 13, 2003 6:46 pm
Location: Georgia (USA)
Contact:

Post 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.
Scott
ericvic
Senior Member
Posts: 144
Joined: Thu Feb 26, 2004 11:06 am
Location: Irondale, AL
Contact:

Post by ericvic »

Scott,



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



Eric
Post Reply