piekstra / tplink-cloud-api

A Python library to remotely control TP-Link smart home devices using their cloud service - no need to be on the same network as your devices
GNU General Public License v3.0
41 stars 11 forks source link

AttributeError: 'NoneType' object has no attribute 'get' #18

Closed andrewmarklloyd closed 3 years ago

andrewmarklloyd commented 3 years ago

I get the error AttributeError: 'NoneType' object has no attribute 'get' when trying to toggle an HS105 device.

Here's the contents of main.py:

from tplinkcloud import TPLinkDeviceManager
import os

tplinkUser = os.environ.get('TPLINKUSER')
tplinkPass = os.environ.get('TPLINKPASS')

device_manager = TPLinkDeviceManager(tplinkUser, tplinkPass)

device_name = "Speaker"
device = device_manager.find_device(device_name)
if device:
  print(f'Found {device.model_type.name} device: {device.get_alias()}')
  device.toggle()
else:  
  print(f'Could not find {device_name}')

Output:

$ pip3 install tplink-cloud-api
$ python3 main.py
Found HS105 device: Speaker
Traceback (most recent call last):
  File "main.py", line 13, in <module>
    device.toggle()
  File "/Library/Python/3.8/site-packages/tplinkcloud/device.py", line 57, in toggle
    if self.is_on():
  File "/Library/Python/3.8/site-packages/tplinkcloud/device.py", line 71, in is_on
    device_sys_info = self.get_sys_info()
  File "/Library/Python/3.8/site-packages/tplinkcloud/hs105.py", line 47, in get_sys_info
    return HS105SysInfo(sys_info)
  File "/Library/Python/3.8/site-packages/tplinkcloud/hs105.py", line 14, in __init__
    self.sw_ver = sys_info.get('sw_ver')
AttributeError: 'NoneType' object has no attribute 'get'
$ python3 --version
Python 3.8.2
piekstra commented 3 years ago

@andrewmarklloyd thanks for bringing this to my attention! I will be investigating this today. Very comprehensive explanation of the issue; I appreciate it! That will help me get started.

piekstra commented 3 years ago

@andrewmarklloyd so from what I can tell, the request to toggle the device failed, possibly due to a timeout trying to make the request to toggle it. I'm going to create a pull request that will provide an error response that is slightly more helpful than the stack trace. I had an HS105 available locally so I was able to verify the toggle functionality is working on the latest release.

piekstra commented 3 years ago

Here is the mentioned pull request: https://github.com/piekstra/tplink-cloud-api/pull/19

I am closing the issue but please reopen if the failure continues for some reason.

andrewmarklloyd commented 3 years ago

Thanks for addressing this so quickly @piekstra. Also thanks for having a great open source project with tests and strict semver releases. This is a great library and a model for open source project management!