'NoneType' object has no attribute 'updateStateOnServer' ???

Posted on
Tue Dec 22, 2020 12:09 am
whmoorejr offline
User avatar
Posts: 522
Joined: Jan 15, 2013
Location: Houston, TX

'NoneType' object has no attribute 'updateStateOnServer' ???

I added a couple lines to allow a variable or device state to be used to update a state on my plugin. Most of the fields are working just fine. The last field I updated doesn't play well with others... File "plugin.py", line 47, in setUserLocation
AttributeError: 'NoneType' object has no attribute 'updateStateOnServer'


this is what I have.... but it's basically identical (except for swapping out keys and stuff) to other lines that are working just fine... (Line 47 is the 3rd line down)
Code: Select all
   def setUserLocation(self, pluginAction, dev):
      substitutedTitle = self.substitute(pluginAction.props.get("userLocationField", ""))
      dev.updateStateOnServer(key="userLocation", value=substitutedTitle)
      self.debugLog("Set User Location: " + str(pluginAction.props.get(u"userLocationField")) + " Entered.  State userLocation set to: " + substitutedTitle)
From Devices.xml
Code: Select all
         <State id="userLocation">
            <ValueType>String</ValueType>
            <TriggerLabel>User Location</TriggerLabel>
            <ControlPageLabel>User Location</ControlPageLabel>
         </State>   
And from Actions.xml
Code: Select all
   <Action id="setUserLocation">
      <Name>Set User Location</Name>
      <CallbackMethod>setUserLocation</CallbackMethod>
      <ConfigUI>
         <Field type="textfield" id="userLocationField">
            <Label>User Location:</Label>
         </Field>
      </ConfigUI>
   </Action>   


And this one, for example, works just fine with a string, varID or device state entered.
Code: Select all
def setUserIDNumber(self, pluginAction, dev):            #<- Substitute Test   
      substitutedTitle = self.substitute(pluginAction.props.get("userIDNumberField", ""))
      dev.updateStateOnServer(key="userIDNumber", value=substitutedTitle)
      self.debugLog("Set User ID: " + str(pluginAction.props.get(u"userIDNumberField")) + " Entered.  " + "State userIDNumber set to: " + substitutedTitle)
The "#<- Substitute Test" is just a note to myself to see if I figured it out before copy-pasting to other callbackMethods.

Bill
My Plugin: My People

Posted on
Tue Dec 22, 2020 4:57 am
howartp offline
Posts: 4267
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: 'NoneType' object has no attribute 'updateStateOnServer'

HI Bill

I've never tried this, but I suspect that you haven't defined a "deviceFilter" on the setUserLocation action in Actions.xml whereas you have on setUserIDNumber.

My actions all have a deviceFilter because I want them to, so i've never tried what happens if you don't give any filter, but I suspect it does what you've found - passes a NoneType device, ie no device, to the callback.

Peter

Posted on
Tue Dec 22, 2020 5:54 am
DaveL17 offline
User avatar
Posts: 5909
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: 'NoneType' object has no attribute 'updateStateOnServer'

I don't always use a deviceFilter, but I always include an XML attribute for one. So when no filter is used...

Code: Select all
    <Action id="refresh_csv_source" deviceFilter="" uiPath="DeviceActions">
While Peter's take may be absolutely right, I have another thought to try as well. This may be an instance where you've changed your device definition while you develop and that's causing intermediate problems. Over time, I've have had many instances where I've done things like add a new state to a device definition without making sure to add it to existing plugin devices I've already created in the Indigo UI. If Peter's suggestion doesn't work, try opening the config dialogs of every device you've created of this type and then hit save. This will update the device with the latest states list. If you search the forums, there's tons of questions where the answer is "open the device configurations and hit save". Several of these questions are probably about my plugins....

(Even if it's not the source of your problem, it's a good idea to have this safety net in your code to make sure you add states to existing devices--especially if you plan to make your plugin available to others. Take a look at dev.stateListOrDisplayStateIdChanged())

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Dec 22, 2020 9:30 am
jay (support) offline
Site Admin
User avatar
Posts: 16815
Joined: Mar 19, 2008
Location: Austin, Texas

Re: 'NoneType' object has no attribute 'updateStateOnServer'

whmoorejr wrote:
File "plugin.py", line 47, in setUserLocation
AttributeError: 'NoneType' object has no attribute 'updateStateOnServer'

Code: Select all
   def setUserLocation(self, pluginAction, dev):
      substitutedTitle = self.substitute(pluginAction.props.get("userLocationField", ""))
      dev.updateStateOnServer(key="userLocation", value=substitutedTitle)
      self.debugLog("Set User Location: " + str(pluginAction.props.get(u"userLocationField")) + " Entered.  State userLocation set to: " + substitutedTitle)


That means that the dev parameter passed to your action is None - so wherever the action was configured doesn't have a device selected. Maybe it did but you deleted the device in the meantime and now it no longer exists?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Dec 22, 2020 10:08 am
whmoorejr offline
User avatar
Posts: 522
Joined: Jan 15, 2013
Location: Houston, TX

Re: 'NoneType' object has no attribute 'updateStateOnServer'

Indigodomo forum to the rescue!

I think it was a combination of me adding and deleting devices while testing and somehow I brain farted and my Actions.xml for that action was missing the filter.... Changed the line to:
<Action id="setUserLocation" deviceFilter="self">
and now it works like a charm. Thank you all!

Bill
My Plugin: My People

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest