Check me on this - device definition questions

Posted on
Thu Oct 25, 2018 7:40 pm
FlyingDiver offline
User avatar
Posts: 7221
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Check me on this - device definition questions

If I have a single Indigo device with multiple sub-models, the only way to have different state items depending on the sub-model is by using getDeviceStateList and adding the new states to the base list obtained from self.devicesTypeDict[typeId][u'States'].

As best I can tell, there's no way to have a device type( <Device type="custom" id="HiddenDevice">) that I can create devices on the fly but will NOT show up in the "Model:" popup in the device creation dialog.

Am I correct on both?

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

Posted on
Fri Oct 26, 2018 8:07 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Check me on this - device definition questions

FlyingDiver wrote:
If I have a single Indigo device with multiple sub-models, the only way to have different state items depending on the sub-model is by using getDeviceStateList and adding the new states to the base list obtained from self.devicesTypeDict[typeId][u'States'].

Yes, but you also need to call stateListOrDisplayStateIdChanged. Not sure if you've seen it, but this thread has details about dynamically specifying states for device instances. Note that getDeviceStateList gets called by Indigo when showing UI that has states (Triggers, Conditionals, Control Page controls) so your plugin has to have the smarts to always return the states you want for any given instance. That is, although the states themselves are saved off into the database the UI information about the states are not and thus getDeviceStateList gets called more often than just on device creation.

FlyingDiver wrote:
As best I can tell, there's no way to have a device type( <Device type="custom" id="HiddenDevice">) that I can create devices on the fly but will NOT show up in the "Model:" popup in the device creation dialog.

Correct, no way to do that currently. Factory devices can do this but they totally do away with the model popup being user editable. It sounds like you might be looking for a hybrid where there still is a device model popup but it doesn't show all of the devices. You might see if you can convert over to using the factory technique. There is an SDK plugin example. You still define all the device types and their states in the XML, but you dynamically determine which devices are created inside the factory UI dialog. This is what the Z-Wave plugin does.

Image

Posted on
Fri Oct 26, 2018 9:35 am
FlyingDiver offline
User avatar
Posts: 7221
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Check me on this - device definition questions

matt (support) wrote:
Yes, but you also need to call stateListOrDisplayStateIdChanged. Not sure if you've seen it, but this thread has details about dynamically specifying states for device instances. Note that getDeviceStateList gets called by Indigo when showing UI that has states (Triggers, Conditionals, Control Page controls) so your plugin has to have the smarts to always return the states you want for any given instance. That is, although the states themselves are saved off into the database the UI information about the states are not and thus getDeviceStateList gets called more often than just on device creation.


I think I've got this part working the way I need. Thanks.

matt (support) wrote:
Correct, no way to do that currently. Factory devices can do this but they totally do away with the model popup being user editable. It sounds like you might be looking for a hybrid where there still is a device model popup but it doesn't show all of the devices. You might see if you can convert over to using the factory technique. There is an SDK plugin example. You still define all the device types and their states in the XML, but you dynamically determine which devices are created inside the factory UI dialog. This is what the Z-Wave plugin does.


I'm trying to make this work. Already one problem. With this factory definition:

Code: Select all
   <DeviceFactory>
      <Name>Create Ecobee 2 Device</Name>
      <ButtonTitle>Create</ButtonTitle>
      <ConfigUI>
           <Field type="menu" id="typePopUpButton" defaultValue="">
                <Label>Device Type:</Label>
                <List>
                    <Option value="EcobeeAccount">Ecobee Account</Option>
                    <Option value="EcobeeThermostat">Ecobee Thermostat</Option>
                </List>
            </Field>
      </ConfigUI>
   </DeviceFactory>


I get this popup. What the heck? What am I doing wrong?
Attachments
Screen Shot 2018-10-26 at 11.32.26 AM.png
Screen Shot 2018-10-26 at 11.32.26 AM.png (230.36 KiB) Viewed 1380 times

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

Posted on
Fri Oct 26, 2018 9:38 am
FlyingDiver offline
User avatar
Posts: 7221
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Check me on this - device definition questions

Hmm. Changing the definition to specify a default works.

Code: Select all
   <DeviceFactory>
      <Name>Create Ecobee 2 Device</Name>
      <ButtonTitle>Create</ButtonTitle>
      <ConfigUI>
           <Field type="menu" id="typePopUpButton" defaultValue="EcobeeAccount">
                <Label>Device Type:</Label>
                <List>
                    <Option value="EcobeeAccount">Ecobee Account</Option>
                    <Option value="EcobeeThermostat">Ecobee Thermostat</Option>
                </List>
            </Field>
      </ConfigUI>
   </DeviceFactory>


But the wiki says this about menus: "API v1.9: If you specify a default value of “” (empty string) and there is no matching option, then the first menu item will be selected when the dialog is first run. This way you can avoid the user seeing “- no selection -” at the bottom of the menu."

So consider this a bug report. ;)
Last edited by FlyingDiver on Fri Oct 26, 2018 1:04 pm, edited 1 time in total.

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

Posted on
Fri Oct 26, 2018 1:04 pm
FlyingDiver offline
User avatar
Posts: 7221
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Check me on this - device definition questions

Now I'm running into something that's really got me confused. Using this DeviceFactory definition (Slightly simplified):
Code: Select all
    <DeviceFactory>
        <Name>Create Ecobee 2 Device</Name>
        <ButtonTitle>Create</ButtonTitle>
        <ConfigUI>
           <Field type="menu" id="deviceType" defaultValue="EcobeeAccount">
                <Label>Device Type:</Label>
                <List>
                    <Option value="EcobeeAccount">Ecobee Account</Option>
                    <Option value="EcobeeThermostat">Ecobee Thermostat</Option>
                </List>
            </Field>
             <Field id="separator1" type="separator"/>

            <Field id="account" type="menu" visibleBindingId="deviceType" visibleBindingValue="EcobeeThermostat">
                <Label>Ecobee Account:</Label>
                <List class="self" method="get_account_list" dynamicReload="true"/>
                <CallbackMethod>menuChanged</CallbackMethod>
            </Field>
            <Field id="address" type="menu" visibleBindingId="deviceType" visibleBindingValue="EcobeeThermostat">
                <Label>Thermostat:</Label>
                <List class="self" method="get_thermostat_list" dynamicReload="true"/>
                <CallbackMethod>menuChanged</CallbackMethod>
            </Field>

        </ConfigUI>
   </DeviceFactory>


As expected, when I select EcobeeThermostat for the device type, I get the two popups to pick the account and device. See first pic. Here's the code that handles closing the dialog box:

Code: Select all
    def closedDeviceFactoryUi(self, valuesDict, userCancelled, devIdList):
        self.logger.debug("closedDeviceFactoryUi, userCancelled = {}, valuesDict = {}, devIdList = {}".format(userCancelled, valuesDict, devIdList))
       
        if userCancelled:
            return
           
        if valuesDict["deviceType"] == "EcobeeThermostat":
       
            newdev = indigo.device.create(indigo.kProtocol.Plugin, deviceTypeId="EcobeeThermostat")
            newdev.model = "Ecobee Thermostat"
            newdev.replaceOnServer()

            newProps = newdev.pluginProps
            newProps["address"] = valuesDict["address"]
            newProps["account"] = valuesDict["account"]
            newdev.replacePluginPropsOnServer(newProps)               

        return


This is getting executed, and the device is created as expected, but the pluginProps are not getting updated.

Here's a device dump:

Code: Select all
address : 315658196345
batteryLevel : None
buttonGroupCount : 0
configured : True
coolIsOn : False
coolSetpoint : 0.0
dehumidifierIsOn : False
description :
deviceTypeId : EcobeeThermostat
displayStateId : temperatureInputsAll
displayStateImageSel : HvacOff
displayStateValRaw :
displayStateValUi :
enabled : True
energyAccumBaseTime : None
energyAccumTimeDelta : None
energyAccumTotal : None
energyCurLevel : None
errorState :
fanIsOn : False
fanMode : Auto
folderId : 0
globalProps : MetaProps : (dict)
     com.flyingdiver.indigoplugin.ecobee : (dict)
          account : 926476031 (string)
          address : 315658196345 (string)
heatIsOn : False
heatSetpoint : 0.0
humidifierIsOn : False
humidities : []
humiditySensorCount : 0
hvacMode : Off
id : 1665534392
lastChanged : 2000-01-01 00:00:00
lastSuccessfulComm : 2000-01-01 00:00:00
model : Ecobee Thermostat
name : new device
ownerProps : com.flyingdiver.indigoplugin.ecobee : (dict)
     account : 926476031 (string)
     address : 315658196345 (string)
pluginId : com.flyingdiver.indigoplugin.ecobee
pluginProps : emptyDict : (dict)
protocol : Plugin
remoteDisplay : True
states : States : (dict)
     hvacFanMode : 0 (integer)
     hvacFanModeIsAlwaysOn : false (bool)
     hvacFanModeIsAuto : false (bool)
     hvacOperationMode : 0 (integer)
     hvacOperationModeIsAuto : false (bool)
     hvacOperationModeIsCool : false (bool)
     hvacOperationModeIsHeat : false (bool)
     hvacOperationModeIsOff : false (bool)
     hvacOperationModeIsProgramAuto : false (bool)
     hvacOperationModeIsProgramCool : false (bool)
     hvacOperationModeIsProgramHeat : false (bool)
     setpointCool : 0 (integer)
     setpointHeat : 0 (integer)
     temperatureInput1 : 0 (integer)
     temperatureInputsAll :  (string)
subModel :
supportsAllLightsOnOff : False
supportsAllOff : False
supportsCoolSetpoint : True
supportsHeatSetpoint : True
supportsHvacFanMode : True
supportsHvacOperationMode : True
supportsStatusRequest : True
temperatureSensorCount : 1
temperatures : [0.0]
version : None


The values are in ownerProps and globalProps, but not pluginProps. If I try to access ownerProps like:

Code: Select all
    def __init__(self, dev):
        self.logger = logging.getLogger('Plugin.ecobee_devices')
        self.logger.debug(u"{}: EcobeeBase __init__".format(dev.name))       
        self.logger.debug(u"{}: ownerProps = {}".format(dev.ownerProps))

I get this:
Code: Select all
   Ecobee 2 Debug                  new device: EcobeeBase __init__
   Ecobee 2 Error                  Error in plugin execution ServerReplacedElem:

Traceback (most recent call last):
  File "/Library/Application Support/Perceptive Automation/Indigo 7.2/IndigoPluginHost.app/Contents/Resources/PlugIns/plugin_base.py", line 1179, in deviceUpdated
  File "plugin.py", line 383, in deviceStartComm
  File "/Library/Application Support/Perceptive Automation/Indigo 7.2/Plugins/Ecobee 2.indigoPlugin/Contents/Server Plugin/ecobee.py", line 250, in __init__
IndexError: tuple index out of range


Any ideas?

joe
Attachments
Screen Shot 2018-10-26 at 2.57.08 PM.png
Screen Shot 2018-10-26 at 2.57.08 PM.png (90.92 KiB) Viewed 1354 times

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

Posted on
Sat Oct 27, 2018 10:11 am
FlyingDiver offline
User avatar
Posts: 7221
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Check me on this - device definition questions

Ignore that last. I'm not sure exactly what code change caused it, but the error has gone away in my current code.

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

Posted on
Sat Oct 27, 2018 11:58 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Check me on this - device definition questions

Gotcha, but we still need to look into the "empty string default value not selecting first item" problem, right?

Image

Posted on
Sat Oct 27, 2018 11:58 am
FlyingDiver offline
User avatar
Posts: 7221
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Check me on this - device definition questions

matt (support) wrote:
Gotcha, but we still need to look into the "empty string default value not selecting first item" problem, right?


Yes please.

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

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests