About that "state" column...

Forum rules

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo

Posted on
Fri Sep 16, 2011 12:58 am
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

About that "state" column...

If I happen to give my device a configuration value called "address", its value shows up in the "address" column in the Devices list. This is very handy (and cool).

So how come if I give my device a state called "state", it doesn't show up in the column labeled "state"? That column is practically jumping up and down begging to be filled...

(And yes, pretty much all my devices have a "state" state - offline, online, failed, whatever.)

Pretty please?

Cheers
-- perry

Posted on
Fri Sep 16, 2011 8:33 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: About that "state" column...

Inside the Devices.xml just change or add the UiDisplayStateId node to point to the ID of the state you want:

Code: Select all
<UiDisplayStateId>playStatus</UiDisplayStateId>

If you need to do it dynamically, then you can override:

Code: Select all
def getDeviceDisplayStateId(self, typeId, devId):

Starting in the next beta, it should get called when the plugin dialog closes, right after getDeviceStateList() is called.

Image

Posted on
Fri Sep 16, 2011 8:38 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: About that "state" column...

Rather than use a fixed name (like address) for that, you can specify which state is the display state in the device's xml:

Code: Select all
   <Device type="custom" id="station">
      <Name>Weather Station</Name>
      <ConfigUI>
         <Field id="host" type="textfield" defaultValue="localhost">
            <Label>Enter a host name or IP:</Label>
         </Field>
         <Field id="port" type="textfield" defaultValue="8000">
            <Label>Enter a port number:</Label>
         </Field>
         <Field id="address" type="textfield" hidden="true">
            <Label/>
         </Field>
      </ConfigUI>
      <UiDisplayStateId>temperatureF</UiDisplayStateId>
      <States>
         <State id="temperatureF">
            <ValueType>Number</ValueType>
            <TriggerLabel>Outdoor Temperature °F</TriggerLabel>
            <ControlPageLabel>Outdoor Current Temperature °F</ControlPageLabel>
         </State>
      </States>
   </Device>


Note the <UiDisplayStateId> element.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Sep 18, 2011 1:41 am
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: About that "state" column...

This works great.

Thanks
-- perry

Posted on
Mon Sep 19, 2011 10:23 pm
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: About that "state" column...

Hm... is there by any chance a UiDisplayAddressId element to determine which config field the address column shows, too? Or is that hard-wired to the address field?

Cheers
-- perry

Posted on
Tue Sep 20, 2011 6:43 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: About that "state" column...

Sorry, that one is hardwired to 'address.'

Image

Posted on
Sun Feb 19, 2012 5:28 am
HomeAutomationPlugins.com offline
Posts: 41
Joined: Feb 18, 2012

Re: About that "state" column...

Hi,

I've got a device defined as follows:

Code: Select all
    <Device type="dimmer" id="Dimmer">
        <Name>LightwaveRF Dimmer</Name>
        <ConfigUI>
            <Field id="address" type="textfield" defaultValue="192.168.0.220">
            <Label>Wifilink IP Address:</Label>
         </Field>
            <Field id="room" type="menu" tooltip="Room Number" defaultValue="1">
            <List>
               <Option value="1">1</Option>
               <Option value="2">2</Option>
               <Option value="3">3</Option>
               <Option value="4">4</Option>
            </List>
                <Label>Room Number:</Label>
            </Field>
            <Field id="device" type="menu" tooltip="Device Number" defaultValue="1">
            <List>
               <Option value="1">1</Option>
               <Option value="2">2</Option>
               <Option value="3">3</Option>
               <Option value="4">4</Option>
            </List>
                <Label>Device Number:</Label>
            </Field>
        </ConfigUI>
    </Device>


What I'd really like is to have a string representation of all 3 properties show in the "address" field (at the moment I understand that Indigo is hard coded to read the property with id="address"

So in the above example ideally I'd like the address field to show "192.168.0.220 R1D1" rather than just "192.168.0.220" - with the R1D1 being Room 1 Device 2 from the other two properties.

Is this possible at all?

many thanks,

Posted on
Sun Feb 19, 2012 11:31 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: About that "state" column...

If I understand your question correctly, it sounds like you should:

1) Change your current field ID to something like "rawAddress."

2) Add a new field "address" and give it the attribute hidden="true" so it doesn't show in the configuration sheet.

3) Inside your validateDeviceConfigUi() method build the compound address from the rawAddress value and stuff it into the "address" key.

Image

Posted on
Sun Feb 19, 2012 11:44 am
HomeAutomationPlugins.com offline
Posts: 41
Joined: Feb 18, 2012

Re: About that "state" column...

That's exactly what I want to do!

I'm still getting my head round everything so would you be able to give me a code snippet for (3) above?

Many thanks!

Posted on
Sun Feb 19, 2012 11:53 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: About that "state" column...

Below is a good template. It does more than just #3, but is a good example of how the validate method should be used:

Code: Select all
   def validateDeviceConfigUi(self, valuesDict, typeId, devId):
      errorsDict = indigo.Dict()

      if False:   # check to see if valudesDict["rawAddress"] is good here
         errorsDict["rawAddress"] = u"IP address entered isn't correct"

      if len(errorsDict) > 0:
         # Some UI fields are not valid, return corrected fields and error messages (client
         # will not let the dialog window close).
         return (False, valuesDict, errorsDict)

      # User choices look good, so return True (client will then close the dialog window).
      valuesDict["address"] = valuesDict["rawAddress"] + u" R1D1"
      return (True, valuesDict)

Image

Posted on
Sun Feb 19, 2012 12:03 pm
HomeAutomationPlugins.com offline
Posts: 41
Joined: Feb 18, 2012

Re: About that "state" column...

That's great - thanks!

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest