benknight / hue-alfred-workflow

An Alfred workflow for controlling Philips Hue lights.
367 stars 34 forks source link

Script filter with parameter does not work #53

Open fns opened 3 years ago

fns commented 3 years ago

I'd like to add a keyword to be able to search lights by their name directly, without using the lights: prefix. I have created a script filter:

/usr/bin/python -m logic.filters "lights:{query}"

 It takes me to the light list immediately and as I start typing the name of the light the list filters properly, but after I press enter on a certain light I will get the following error:  

18:42:12.352] Philips Hue Controller[Script Filter] Queuing argument 'lights:7:'
[18:42:12.663] Philips Hue Controller[Script Filter] Script with argv '(null)' finished
[18:42:12.664] ERROR: Philips Hue Controller[Script Filter] Code 1: .
18:42:12 workflow.py:2061 DEBUG    ---------- Philips Hue Controller (3.0.3) ----------
18:42:12 workflow.py:1468 DEBUG    reading settings from /Users/fns/Library/Application Support/Alfred/Workflow Data/hue-alfred-workflow/settings.json
18:42:12 workflow.py:2343 DEBUG    update check not due
18:42:12 workflow.py:1695 DEBUG    loading cached data: /Users/fns/Library/Caches/com.runningwithcrayons.Alfred/Workflow Data/hue-alfred-workflow/__workflow_latest_version.cpickle
18:42:12 workflow.py:1585 DEBUG    data `full_state` stored as `cpickle`
18:42:12 workflow.py:1600 DEBUG    stored data loaded: /Users/fns/Library/Application Support/Alfred/Workflow Data/hue-alfred-workflow/full_state.cpickle
18:42:12 workflow.py:1585 DEBUG    data `full_state` stored as `cpickle`
18:42:12 workflow.py:1600 DEBUG    stored data loaded: /Users/fns/Library/Application Support/Alfred/Workflow Data/hue-alfred-workflow/full_state.cpickle
18:42:12 workflow.py:2080 ERROR    'NoneType' object has no attribute '__getitem__'
Traceback (most recent call last):
  File "logic/packages/workflow/workflow.py", line 2073, in run
    func(self)
  File "/Users/fns/Documents/Alfred/Alfred.alfredpreferences/workflows/user.workflow.1E0966F7-5BA7-4C4C-BF3F-2F575C1AAE0E/logic/filters.py", line 458, in main
    items = hue_index_filter.get_items()
  File "/Users/fns/Documents/Alfred/Alfred.alfredpreferences/workflows/user.workflow.1E0966F7-5BA7-4C4C-BF3F-2F575C1AAE0E/logic/filters.py", line 91, in get_items
    resource=lights.get(rid, None) if query.startswith('lights') else groups.get(rid, None))
  File "/Users/fns/Documents/Alfred/Alfred.alfredpreferences/workflows/user.workflow.1E0966F7-5BA7-4C4C-BF3F-2F575C1AAE0E/logic/filters.py", line 224, in get_items
    is_on = (type == self.LIGHT_TYPE and resource['state']['on'])
TypeError: 'NoneType' object has no attribute '__getitem__'
18:42:12 workflow.py:2103 DEBUG    ---------- finished in 0.054s ----------
[18:42:12.680] Philips Hue Controller[Script Filter] {
  "items": [
    {
      "valid": false,
      "subtitle": "'NoneType' object has no attribute '__getitem__'",
      "icon": {
        "path": "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns"
      },
      "title": "Error in workflow 'Philips Hue Controller'"
    }
  ]
}

Any idea what is wrong here? ​

benknight commented 3 years ago

It looks like there is no cached light data for the light with ID "7". At this point in the workflow logic, lights data is being loaded from the cache because its assumed you got there from following previous steps which load the light data from the bridge API. If you're calling this directly, probably there's no cached data for your light ID. You could try changing https://github.com/benknight/hue-alfred-workflow/blob/master/logic/filters.py#L83 as follows:

- lights = utils.get_lights(from_cache=True)
+ lights = utils.get_lights()

Try that and let me know if it fixes your issue.

fns commented 3 years ago

It looks like there is no cached light data for the light with ID "7". At this point in the workflow logic, lights data is being loaded from the cache because its assumed you got there from following previous steps which load the light data from the bridge API. If you're calling this directly, probably there's no cached data for your light ID. You could try changing https://github.com/benknight/hue-alfred-workflow/blob/master/logic/filters.py#L83 as follows:

- lights = utils.get_lights(from_cache=True)
+ lights = utils.get_lights()

Try that and let me know if it fixes your issue.

No, it still does not work, same error.

benknight commented 3 years ago

Okay, feel free to troubleshoot on your own and if you find a logic bug submit a pull request or report back here on the issue.