Custom devices states not appearing...

Posted on
Mon Jul 06, 2020 12:38 pm
jheddings offline
User avatar
Posts: 149
Joined: Dec 01, 2013
Location: Denver, CO

Custom devices states not appearing...

I've stared at this for too long and for the life of me cannot figure out what's wrong...

I'm trying to declare some custom states for a device, but always end up with a the following errors:
Code: Select all
   Error                           device "Expected Rainfall" state key status not defined (ignoring update request)
   Error                           device "Expected Rainfall" state key lastReportedAt not defined (ignoring update request)


"Expected Rainfall" is a 'gauge' device. I've deleted it, added it back, disabled / enabled plugin, etc. The Custom States are not showing in the UI below the Device Details, either.

plugin.py, during a device update request:
Code: Select all
        dev.updateStateOnServer('status', value=status_value)
        dev.updateStateOnServer('lastReportedAt', value=time.strftime('%c'))


Devices.xml:
Code: Select all
  <Device type="custom" id="gauge">
    <Name>Gauge</Name>

    <ConfigUI>
      <Field id="device_id" type="menu" defaultValue="">
        <Label>Device:</Label>
        <List class="self" filter="" method="getDeviceList" dynamicReload="true" />
        <CallbackMethod>updateConfigUI</CallbackMethod>
      </Field>

      <Field id="state_id" type="menu" defaultValue="">
        <Label>Device State:</Label>
        <List class="self" filter="" method="getDeviceStateList" dynamicReload="true" />
      </Field>

      <Field id="user_info" type="textfield" defaultValue="">
        <Label>User Info:</Label>
      </Field>
      <Field id="user_info_help" type="label" fontSize="mini" alignWithControl="true">
        <Label>(optional) reported in 'user_info' label - supports Indigo substitutions</Label>
      </Field>

      <Field id="address" type="textfield" hidden="yes" />
    </ConfigUI>

    <States>
      <State id="status">
        <ValueType>String</ValueType>
        <TriggerLabel>Metric Value</TriggerLabel>
        <ControlPageLabel>Metric Value</ControlPageLabel>
      </State>

      <State id="lastReportedAt">
        <ValueType>String</ValueType>
        <TriggerLabel>Last Reported</TriggerLabel>
        <ControlPageLabel>Last Reported</ControlPageLabel>
      </State>
    </States>

    <UiDisplayStateId>status</UiDisplayStateId>
  </Device>

Posted on
Mon Jul 06, 2020 1:55 pm
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Custom devices states not appearing...

The XML looks correct to me. So after editing/creating that XML file you tried creating a new "Gauge" device in Indigo? Did the Config UI dialog then show, and after it was dismissed you still don't have those 2 custom states added?

Any other errors of funniness shown in the Event Log around when you create the Device?

Image

Posted on
Mon Jul 06, 2020 3:05 pm
jheddings offline
User avatar
Posts: 149
Joined: Dec 01, 2013
Location: Denver, CO

Re: Custom devices states not appearing...

Correct... The config UI showed as expected, but after configuring it does not show the 2 new states. The device itself appears to be working properly and reports as configured when doing an update.

I also added a debug line to print the keys of `device.states` in `deviceStartComm` but the map is empty. I also tried on a clean database, just in case something was stuck there. Even tried on my "production" Indigo system in addition to my development box.

I'm not sure if it matters, but the initial version of my plugin did not include a Devices.xml file. I've added that since and wondered if that somehow confused Indigo?

Nothing else I can see in the log at the time of creation or update.

Here's the current plugin someone if interested in running code: https://github.com/jheddings/indigo-prometheus/releases/tag/v0.1.2

Posted on
Mon Jul 06, 2020 5:03 pm
FlyingDiver offline
User avatar
Posts: 7210
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Custom devices states not appearing...

Existing device? Or did you create a new device? Old devices won't get updated to changes in the Devices.xml unless you do a specific API all. Which I can't remember off the top of my head.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Jul 06, 2020 5:05 pm
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Custom devices states not appearing...

Alright after a bit more searching that I'd like to admit, it looks like you need to rename your getDeviceStateList UI callback method to myGetDeviceStateList (inside the .py and .xml files). Indigo internally calls a method defined in its base plugin instance with the getDeviceStateList name to fetch the states the device has defined. :?

As the parameter signatures weren't the same I'll be looking into why Indigo didn't at least log an error in this case which would have been very helpful to track down the problem. :twisted:

Image

Posted on
Mon Jul 06, 2020 5:09 pm
jheddings offline
User avatar
Posts: 149
Joined: Dec 01, 2013
Location: Denver, CO

Re: Custom devices states not appearing...

That did it! Thanks for digging into that, Matt! I never would have thought to follow that thread...

Posted on
Sun Jul 26, 2020 11:18 am
bap offline
Posts: 33
Joined: Sep 25, 2012

Re: Custom devices states not appearing...

FlyingDiver wrote:
Existing device? Or did you create a new device? Old devices won't get updated to changes in the Devices.xml unless you do a specific API all. Which I can't remember off the top of my head.


I actually just ran into this exact same issue with a plug-in of my own. Any chance you could dig up the appropriate API call?

-Bruce

Posted on
Sun Jul 26, 2020 12:28 pm
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Custom devices states not appearing...

Call this on the device instance(s) that have changed:

dev.stateListOrDisplayStateIdChanged()

Image

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests