Problem using getDeviceDisplayStateId()

Posted on
Sun Sep 08, 2013 2:09 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Problem using getDeviceDisplayStateId()

I am trying to change the DisplayStateId at the time the Device dialog is closed - this is to allow the user to define the state to be displayed in the State column. I have implemented:

Code: Select all
    def getDeviceDisplayStateId(self, dev):
        if dev.deviceTypeId == "phStandalonePhidget"  and dev.pluginProps['phStandalonePhidgetModel'] == '1054':
            indigo.server.log("old stateId is:%s" % self.devicesTypeDict[dev.deviceTypeId][u'DisplayStateId'], type=self.pluginDisplayName)
            self.devicesTypeDict[dev.deviceTypeId][u'DisplayStateId'] = 'kwh'
            indigo.server.log("new stateId is:%s" % self.devicesTypeDict[dev.deviceTypeId][u'DisplayStateId'], type=self.pluginDisplayName
            return self.devicesTypeDict[dev.deviceTypeId][u'DisplayStateId'])

Unfortunately, this does not work. Here is the log entry...

Opened the device
    Phidgets old stateId is:onOffState
    Phidgets new stateId is:onOffState
Clicked Edit Device Settings..., then clicked Save
    Phidgets old stateId is:onOffState
    Phidgets new stateId is:onOffState
I also tried to delete self.devicesTypeDict[dev.deviceTypeId][u'DisplayStateId'], but it doesn't do it either.

What am I doing wrong/not doing?

Posted on
Sun Sep 08, 2013 10:08 am
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Problem using getDeviceDisplayStateId()

Have you tried calling the stateListOrDisplayStateIdChanged() method?

Image

Posted on
Sun Sep 08, 2013 10:22 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Problem using getDeviceDisplayStateId()

matt (support) wrote:
Have you tried calling the stateListOrDisplayStateIdChanged() method?

Not really... since this is happening on the close of the config dialog, and getDeviceDisplayStateId() is being called anyway, I didn't think it was necessary... also, where would I call it from?

Posted on
Sun Sep 08, 2013 10:37 am
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Problem using getDeviceDisplayStateId()

Ahhh... I bet the problem is this is a relay class device instead of a custom device. For native (non-custom) types of relay, dimmer, thermostat the state shown is hardcoded and no override is possible. Let me think about if we want to allow overriding for native device types as well.

Image

Posted on
Sun Sep 08, 2013 10:47 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Problem using getDeviceDisplayStateId()

'cept...
Code: Select all
<!--Standalone Phidgets                                      -->      
   <Device id="phStandalonePhidget" type="custom">
      <Name>Phidget Standalone Device</Name>

Posted on
Sun Sep 08, 2013 11:18 am
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Problem using getDeviceDisplayStateId()

Okay, I should have looked at your code snippet more closely. This isn't going to work:

Code: Select all
            self.devicesTypeDict[dev.deviceTypeId][u'DisplayStateId'] = 'kwh'

because of a difference in how indigo.Dict and python dicts function. In particular the self.devicesTypeDict[dev.deviceTypeId] expression returns a copy of the indigo.Dict and not a reference, so changing an item in that dict is just changing the copy and not the original.

But in this case you don't really need to change the devicesTypeDict at all -- just return the value you want to use for the display state ID like this:

Code: Select all
        def getDeviceDisplayStateId(self, dev):
            if dev.deviceTypeId == "phStandalonePhidget"  and dev.pluginProps['phStandalonePhidgetModel'] == '1054':
                return 'kwh'
            return self.devicesTypeDict[dev.deviceTypeId][u'DisplayStateId'])

Image

Posted on
Sun Sep 08, 2013 11:24 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Problem using getDeviceDisplayStateId()

Thanks Matt. I had looked for some examples, but couldn't find any. I figured it was something like that.

Posted on
Sun Sep 08, 2013 11:30 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Problem using getDeviceDisplayStateId()

matt (support) wrote:
Code: Select all
...
            return self.devicesTypeDict[dev.deviceTypeId][u'DisplayStateId'])

That worked - wthout the trailing ")" :wink:

Posted on
Sun Sep 08, 2013 11:33 am
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Problem using getDeviceDisplayStateId()

berkinet wrote:
That worked - wthout the trailing ")" :wink:

In fairness, that was a copy/paste from your original code snippet. ;-)

Image

Posted on
Sun Sep 08, 2013 11:37 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Problem using getDeviceDisplayStateId()

:oops:

Posted on
Thu Aug 04, 2016 11:11 am
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: Problem using getDeviceDisplayStateId()

Resurrecting this old thread....

Matt, did you ever create method that allows a change for built-in types? I know getDeviceDisplayStateId() doesn't do it, I'm wondering if you had given this any more thought. It could be done with the same restrictions as other functions (like updateStateOnServer) that require that the plugin own the device, but it would be nice to be able to change the display state for my non custom device types on the fly.

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Thu Aug 04, 2016 1:07 pm
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Problem using getDeviceDisplayStateId()

It is still hard coded for all the non-custom device types. We need to provide better UI control, both from the Mac client and Indigo Touch, from plugin owned devices. I'll add this request to that feature list group (on our request list).

Image

Posted on
Thu Aug 04, 2016 2:46 pm
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: Problem using getDeviceDisplayStateId()

This is the first time that it's really come up for me that I would like to have control over that - but I generally write custom device plugins that I can manipulate easily too.

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Mon Jan 30, 2023 4:45 pm
papamac offline
User avatar
Posts: 131
Joined: Jan 29, 2014

Re: Problem using getDeviceDisplayStateId()

hi Matt,

It's time to revisit this again...

I have a plugin device that controls a digital to analog converter (DAC). It defines what I call an analog on/off device.. if the output voltage exceeds a threshold, it is "on", otherwise "off". The device has both an onOffState and a sensorValue in the states dictionary. Furthermore, it defines a turnOn voltage and a turnOff voltage that are used by the actionControlDevice method to write to the DAC. I need to use a relay device to enable turnOn and turnOff and to use the buttons in the controls section of the home window. The normal relay device display state (onOffState) is fine when the device is being used in this way,

...... but, there are. times when the sensorValue display state would be more appropriate. I could use a custom device to allow me to change the displayStateId, but then I would give up the turnOn/turnOff capability of the relay device.

So... did you ever allow a displayStateId change for native device types? Is this feature still on the "to do" list?

Thanks,

papamac

Posted on
Tue Jan 31, 2023 12:01 pm
papamac offline
User avatar
Posts: 131
Joined: Jan 29, 2014

Re: Problem using getDeviceDisplayStateId()

I found a solution to part of my problem. If I use a sensor device, I can include a "SupportsSensorValue" pluginProp and set it to true. This apparently forces the displayStateId to be sensorValue. If I set it to false, the displayStateId reverts to onOffState. That's great... I can have a single device that displays an onOffState sometimes and a sensorValue other times, selectable by a pluginProp.

Unfortunately, this doesn't work for relay devices, so there is no turnOn/turnOff functionality. There seem to be two possibilities:

1. Allow "SupportsSensorValue" for a relay device, or
2. Allow turnOn/turnOff capability for a custom device.

Are either of these possible?

Thanks,

papamac

Who is online

Users browsing this forum: No registered users and 1 guest

cron