spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.38k stars 1.62k forks source link

Error in the variable explorer when inspecting variables generated by the Phue library #10703

Open JohnCanty opened 5 years ago

JohnCanty commented 5 years ago

Description

What steps will reproduce the problem?

Using Phue library installed in the working directory. perfrom a successful connect to the Hue lighting hub. Stored the lights in a dictionary using the ID as the Key.

lights = b.get_light_objects(mode='id')

Using the variable explorer I opened the entry that was associated with a lamp that is not RGB controllable.

Traceback

  File "/Users/johncanty/hue/phue.py", line 843, in get_light
    return state['state'][parameter]
KeyError: 'colormode'

Traceback (most recent call last):
  File "/Users/johncanty/opt/anaconda3/lib/python3.7/site-packages/spyder/widgets/variableexplorer/collectionseditor.py", line 550, in createEditor
    readonly=readonly)
  File "/Users/johncanty/opt/anaconda3/lib/python3.7/site-packages/spyder/widgets/variableexplorer/collectionseditor.py", line 1390, in setup
    remote=remote)
  File "/Users/johncanty/opt/anaconda3/lib/python3.7/site-packages/spyder/widgets/variableexplorer/collectionseditor.py", line 1330, in __init__
    title)
  File "/Users/johncanty/opt/anaconda3/lib/python3.7/site-packages/spyder/widgets/variableexplorer/collectionseditor.py", line 1207, in __init__
    minmax=minmax)
  File "/Users/johncanty/opt/anaconda3/lib/python3.7/site-packages/spyder/widgets/variableexplorer/collectionseditor.py", line 135, in __init__
    self.set_data(data)
  File "/Users/johncanty/opt/anaconda3/lib/python3.7/site-packages/spyder/widgets/variableexplorer/collectionseditor.py", line 183, in set_data
    self.set_size_and_type()
  File "/Users/johncanty/opt/anaconda3/lib/python3.7/site-packages/spyder/widgets/variableexplorer/collectionseditor.py", line 209, in set_size_and_type
    for index in range(start, stop)]
  File "/Users/johncanty/opt/anaconda3/lib/python3.7/site-packages/spyder/widgets/variableexplorer/collectionseditor.py", line 209, in <listcomp>
    for index in range(start, stop)]
  File "/Users/johncanty/opt/anaconda3/lib/python3.7/site-packages/spyder/widgets/variableexplorer/collectionseditor.py", line 92, in __getitem__
    attribute_toreturn = getattr(self.__obj__, key)
  File "/Users/johncanty/hue/phue.py", line 185, in colormode
    self._colormode = self._get('colormode')
  File "/Users/johncanty/hue/phue.py", line 117, in _get
    return self.bridge.get_light(self.light_id, *args, **kwargs)
  File "/Users/johncanty/hue/phue.py", line 847, in get_light
    % (parameter, light_id))
KeyError: 'Not a valid key, parameter colormode is not associated with light 6)'

Versions

Dependencies

pyflakes >=0.6.0  :  2.1.1 (OK)
pycodestyle >=2.3 :  2.5.0 (OK)
pygments >=2.0    :  2.4.2 (OK)
sphinx >=0.6.6    :  2.2.0 (OK)
rope >=0.9.4      :  0.14.0 (OK)
jedi >=0.9.0      :  0.15.1 (OK)
psutil >=0.3      :  5.6.3 (OK)
nbconvert >=4.0   :  5.6.0 (OK)
pandas >=0.13.1   :  0.25.1 (OK)
numpy >=1.7       :  1.17.2 (OK)
sympy >=0.7.3     :  1.4 (OK)
cython >=0.21     :  0.29.13 (OK)
qtconsole >=4.2.0 :  4.5.5 (OK)
IPython >=4.0     :  7.8.0 (OK)
matplotlib >=2.0.0:  3.1.1 (OK)
pylint >=0.25     :  2.4.2 (OK)
JohnCanty commented 5 years ago

switched mode to list, and a similar problem happens. I can create a separate bug for that is need be. Reproducible every time.

ccordoba12 commented 5 years ago

Please post a simple code sample that generates the problem above.

JohnCanty commented 5 years ago
from phue import Bridge
Brightness = 254

b = Bridge('10.10.11.2', 'APIKEY')

# If the app is not registered and the button is not pressed, press the button and call connect() (this only needs to be run a single time)
b.connect()

# Get the bridge state (This returns the full dictionary that you can explore)
b.get_api()

# Get the light information from the bridge and store it in a dictionary based on ID as the key.
lights = b.get_light_objects(mode='id')

for lightid,attribute in lights.items():
    print(lightid)
    print(attribute.on)
    print(attribute.brightness)
    if attribute.brightness >= 0:
        if attribute.on == False:
            b.set_light(lightid, 'on',  value=True)
            b.set_light(lightid, 'bri',  value=Brightness)
            b.set_light(lightid, 'on',  value=False)
        else:
            b.set_light(lightid, 'bri',  value=Brightness)
JohnCanty commented 5 years ago

This executes fine. But if I use the variable explorer to check out the dictionary that is created called 'lights'. The non-color changing lights in the dictionary cause this error.

ccordoba12 commented 5 years ago

Thanks for the code @JohnCanty! We'll try to fix this after we release Spyder 4.