Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while looking for presence #21

Closed
jackien1 opened this issue Jul 27, 2017 · 8 comments
Closed

Error while looking for presence #21

jackien1 opened this issue Jul 27, 2017 · 8 comments

Comments

@jackien1
Copy link

Traceback (most recent call last):
File "smartthings.py", line 209, in
ds = st.request_devices(options.device_type)
File "smartthings.py", line 119, in request_devices
SmartThings.raise_api_errors(self.deviceds)
File "smartthings.py", line 55, in raise_api_errors
raise Exception(error_type + ": " + error_message)
Exception: java.lang.NullPointerException: An unexpected error occurred.

@TomerFi
Copy link

TomerFi commented May 7, 2018

I have the exact same issue when looking for presence.
When running python smartthings.py --type presence with Python 2.7.14, I get the following error:

Traceback (most recent call last):
  File "smartthings.py", line 209, in <module>
    ds = st.request_devices(options.device_type)
  File "smartthings.py", line 119, in request_devices
    SmartThings.raise_api_errors(self.deviceds)
  File "smartthings.py", line 55, in raise_api_errors
    raise Exception(error_type + ": " + error_message)
Exception: java.lang.NullPointerException: An unexpected error occurred.

I have only one device attached to my smartthings account, my iphone as presence sensor.

@TomerFi
Copy link

TomerFi commented May 7, 2018

I've deleted everything and rebuilt it following the guide and now the error is gone, so I guess it was my bad.

Nevertheless now I always get an empty list each time I'm trying to list my presence devices.

@TomerFi
Copy link

TomerFi commented May 7, 2018

Figured it out (sorry, I'm new to smartthings).
In smartthings.groovy line 359:

def jd = [id: device.id, label: device.label, type: type, value: vd, hub: device.hub.name];

I only have one device connected to my smartthings hub, my phone which is of type Mobile Presence and is not set to any hub, therefore the above code failed.
I've changed it to:

def hub_name = "None"
if (device.hub) {
	hub_name = device.hub.name
}
def jd = [id: device.id, label: device.label, type: type, value: vd, hub: hub_name];

And it seems to be working well.

@dpjanes
Copy link
Owner

dpjanes commented May 8, 2018

Great. It's been a long time since I looked at this code, can't you just do something like this in Groovy

def jd = [id: device.id, label: device.label, type: type, value: vd, hub: device.hub?.name];

@TomerFi
Copy link

TomerFi commented May 8, 2018

@dpjanes Yes, it will. It's my first time playing around with Groovy.

It's also the first time I'm trying my SmartThings hub, Your repository really helped me wrap my head around it.
Thank you!

@dpjanes
Copy link
Owner

dpjanes commented May 8, 2018

This is actually my first and only Groovy code. If you've tested that little code snippet with the ? I'll update the code base.

@TomerFi
Copy link

TomerFi commented May 9, 2018

Yes. I've just tested it.
Works like a charm!
:-)

@dpjanes
Copy link
Owner

dpjanes commented May 9, 2018

Cheers!

@dpjanes dpjanes closed this as completed May 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants