Page 1 of 2

Problem using getDeviceDisplayStateId()

PostPosted: Sun Sep 08, 2013 2:09 am
by berkinet
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?

Re: Problem using getDeviceDisplayStateId()

PostPosted: Sun Sep 08, 2013 10:08 am
by matt (support)
Have you tried calling the stateListOrDisplayStateIdChanged() method?

Re: Problem using getDeviceDisplayStateId()

PostPosted: Sun Sep 08, 2013 10:22 am
by berkinet
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?

Re: Problem using getDeviceDisplayStateId()

PostPosted: Sun Sep 08, 2013 10:37 am
by matt (support)
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.

Re: Problem using getDeviceDisplayStateId()

PostPosted: Sun Sep 08, 2013 10:47 am
by berkinet
'cept...
Code: Select all
<!--Standalone Phidgets                                      -->      
   <Device id="phStandalonePhidget" type="custom">
      <Name>Phidget Standalone Device</Name>

Re: Problem using getDeviceDisplayStateId()

PostPosted: Sun Sep 08, 2013 11:18 am
by matt (support)
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'])

Re: Problem using getDeviceDisplayStateId()

PostPosted: Sun Sep 08, 2013 11:24 am
by berkinet
Thanks Matt. I had looked for some examples, but couldn't find any. I figured it was something like that.

Re: Problem using getDeviceDisplayStateId()

PostPosted: Sun Sep 08, 2013 11:30 am
by berkinet
matt (support) wrote:
Code: Select all
...
            return self.devicesTypeDict[dev.deviceTypeId][u'DisplayStateId'])

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

Re: Problem using getDeviceDisplayStateId()

PostPosted: Sun Sep 08, 2013 11:33 am
by matt (support)
berkinet wrote:
That worked - wthout the trailing ")" :wink:

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

Re: Problem using getDeviceDisplayStateId()

PostPosted: Sun Sep 08, 2013 11:37 am
by berkinet
:oops:

Re: Problem using getDeviceDisplayStateId()

PostPosted: Thu Aug 04, 2016 11:11 am
by Colorado4Wheeler
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.

Re: Problem using getDeviceDisplayStateId()

PostPosted: Thu Aug 04, 2016 1:07 pm
by matt (support)
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).

Re: Problem using getDeviceDisplayStateId()

PostPosted: Thu Aug 04, 2016 2:46 pm
by Colorado4Wheeler
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.

Re: Problem using getDeviceDisplayStateId()

PostPosted: Mon Jan 30, 2023 4:45 pm
by papamac
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

Re: Problem using getDeviceDisplayStateId()

PostPosted: Tue Jan 31, 2023 12:01 pm
by papamac
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