moroen / IKEA-Tradfri-plugin

A Python plugin for Domoticz to controll IKEA Gateway
68 stars 23 forks source link

Unable to iterate devices #46

Closed HansVanEijsden closed 5 years ago

HansVanEijsden commented 5 years ago

First of all, thank you for adding support for the IKEA sockets. Unfortunately, I cannot get it to work.

I updated pytradfri to the latest git version. And pytradfri works when I execute example_socket_async.py, it finds all my devices (also sockets) and commands them. I updated the IKEA-Tradfri plugin (I am still using the development branch, I also use the latest Domoticz beta):

# git pull
remote: Enumerating objects: 16, done.
remote: Counting objects: 100% (16/16), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 16 (delta 8), reused 11 (delta 6), pack-reused 0
Unpacking objects: 100% (16/16), done.
From https://github.com/moroen/IKEA-Tradfri-plugin
   f6f5dc8..309f81b  development -> origin/development
 * [new branch]      outlets     -> origin/outlets
 * [new branch]      pycoap      -> origin/pycoap
Updating f6f5dc8..309f81b
Fast-forward
 README.md   |  19 ++++++++++++++++---
 plugin.py   |  76 ++++++++++++++++++++++++++++++++++++++++++----------------------------------
 tradfri.tac | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
 3 files changed, 181 insertions(+), 49 deletions(-)
root@Ubuntu:/home/domoticz/plugins/IKEA-Tradfri# git checkout development
M   install-coap-client.sh
Already on 'development'
Your branch is up to date with 'origin/development'.

After starting tradfri.tac it displays IKEA-tradfri COAP-adaptor version 0.8 started (command line)! and then it takes some time. This is the complete output:

# python3 tradfri.tac
IKEA-tradfri COAP-adaptor version 0.8 started (command line)!
Connected from IPv4Address(type='TCP', host='127.0.0.1', port=42110)
Data received: b'{"action": "initGateway", "observe": "True", "pollinterval": "10", "groups": "False"}'
Initializing gateway
Adding light with ID: 65541
Unable to iterate devices
Data received: b'{"action": "getLights"}'
{"action": "getLights", "status": "Ok", "result": [{"DeviceID": 65541, "Name": "Muurlicht Rechts", "Type": "Light", "Dimmable": true, "HasWB": true, "HasRGB": false}]}
{'action': 'deviceUpdate', 'status': 'Ok', 'result': [{'DeviceID': 65541, 'Name': 'Muurlicht Rechts', 'State': False, 'Level': 200, 'Hex': 'efd275'}]}

I also tried a new ./configure.py but no difference, still that error. The previous version of the plugin worked fine, with my lights.

I attached a txt file with the pytradfri debug output of all my devices connected to my hub. devices_debug.txt

HansVanEijsden commented 5 years ago

I did a fresh checkout of the pytradfri master branch: https://github.com/ggravlingen/pytradfri - it says version 6.0.1. Here's the install log:

# python3 setup.py install
running install
running bdist_egg
running egg_info
writing pytradfri.egg-info/PKG-INFO
writing dependency_links to pytradfri.egg-info/dependency_links.txt
writing requirements to pytradfri.egg-info/requires.txt
writing top-level names to pytradfri.egg-info/top_level.txt
reading manifest file 'pytradfri.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'pytradfri.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/pytradfri
copying build/lib/pytradfri/__init__.py -> build/bdist.linux-x86_64/egg/pytradfri
copying build/lib/pytradfri/__main__.py -> build/bdist.linux-x86_64/egg/pytradfri
copying build/lib/pytradfri/color.py -> build/bdist.linux-x86_64/egg/pytradfri
copying build/lib/pytradfri/command.py -> build/bdist.linux-x86_64/egg/pytradfri
copying build/lib/pytradfri/const.py -> build/bdist.linux-x86_64/egg/pytradfri
copying build/lib/pytradfri/device.py -> build/bdist.linux-x86_64/egg/pytradfri
copying build/lib/pytradfri/error.py -> build/bdist.linux-x86_64/egg/pytradfri
copying build/lib/pytradfri/gateway.py -> build/bdist.linux-x86_64/egg/pytradfri
copying build/lib/pytradfri/group.py -> build/bdist.linux-x86_64/egg/pytradfri
copying build/lib/pytradfri/mood.py -> build/bdist.linux-x86_64/egg/pytradfri
copying build/lib/pytradfri/resource.py -> build/bdist.linux-x86_64/egg/pytradfri
copying build/lib/pytradfri/smart_task.py -> build/bdist.linux-x86_64/egg/pytradfri
copying build/lib/pytradfri/util.py -> build/bdist.linux-x86_64/egg/pytradfri
creating build/bdist.linux-x86_64/egg/pytradfri/api
copying build/lib/pytradfri/api/__init__.py -> build/bdist.linux-x86_64/egg/pytradfri/api
copying build/lib/pytradfri/api/libcoap_api.py -> build/bdist.linux-x86_64/egg/pytradfri/api
copying build/lib/pytradfri/api/aiocoap_api.py -> build/bdist.linux-x86_64/egg/pytradfri/api
byte-compiling build/bdist.linux-x86_64/egg/pytradfri/__init__.py to __init__.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/pytradfri/__main__.py to __main__.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/pytradfri/color.py to color.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/pytradfri/command.py to command.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/pytradfri/const.py to const.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/pytradfri/device.py to device.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/pytradfri/error.py to error.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/pytradfri/gateway.py to gateway.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/pytradfri/group.py to group.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/pytradfri/mood.py to mood.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/pytradfri/resource.py to resource.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/pytradfri/smart_task.py to smart_task.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/pytradfri/util.py to util.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/pytradfri/api/__init__.py to __init__.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/pytradfri/api/libcoap_api.py to libcoap_api.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/pytradfri/api/aiocoap_api.py to aiocoap_api.cpython-36.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying pytradfri.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pytradfri.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pytradfri.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pytradfri.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pytradfri.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist/pytradfri-6.0.1-py3.6.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing pytradfri-6.0.1-py3.6.egg
Removing /usr/local/lib/python3.6/dist-packages/pytradfri-6.0.1-py3.6.egg
Copying pytradfri-6.0.1-py3.6.egg to /usr/local/lib/python3.6/dist-packages
pytradfri 6.0.1 is already the active version in easy-install.pth

Installed /usr/local/lib/python3.6/dist-packages/pytradfri-6.0.1-py3.6.egg
Processing dependencies for pytradfri==6.0.1
Finished processing dependencies for pytradfri==6.0.1
moroen commented 5 years ago

If you could try to switch to the debug branch and try a dry-run from the command-line:

$ python3 tradfri.tac --dryrun

HansVanEijsden commented 5 years ago

Thanks! Here's the output:

# python3 tradfri.tac --dryrun
IKEA-tradfri COAP-adaptor version 0.7 started (command line)!
Connected from IPv4Address(type='TCP', host='127.0.0.1', port=42643)
Data received: b'{"action": "initGateway", "observe": "True", "pollinterval": "10", "groups": "False"}'
Initializing gateway
Data received: b'{"action": "getLights"}'
{"action": "getLights", "status": "Ok", "result": [{"DeviceID": 65541, "Name": "Muurlicht Rechts", "Type": "Light", "Dimmable": true, "HasWB": true, "HasRGB": false}, {"DeviceID": 65540, "Name": "Plafond", "Type": "Light", "Dimmable": true, "HasWB": true, "HasRGB": false}, {"DeviceID": 65538, "Name": "Stalamp Plafond", "Type": "Light", "Dimmable": true, "HasWB": false, "HasRGB": true}, {"DeviceID": 65542, "Name": "Muurlicht Links", "Type": "Light", "Dimmable": true, "HasWB": true, "HasRGB": false}, {"DeviceID": 65539, "Name": "Tafellicht", "Type": "Light", "Dimmable": true, "HasWB": true, "HasRGB": false}]}
{'action': 'deviceUpdate', 'status': 'Ok', 'result': [{'DeviceID': 65541, 'Name': 'Muurlicht Rechts', 'State': True, 'Level': 25, 'Hex': 'efd275'}]}
{'action': 'deviceUpdate', 'status': 'Ok', 'result': [{'DeviceID': 65540, 'Name': 'Plafond', 'State': False, 'Level': 254, 'Hex': 'f1e0b5'}]}
{'action': 'deviceUpdate', 'status': 'Ok', 'result': [{'DeviceID': 65538, 'Name': 'Stalamp Plafond', 'State': True, 'Level': 63, 'Hex': '0'}]}
{'action': 'deviceUpdate', 'status': 'Ok', 'result': [{'DeviceID': 65542, 'Name': 'Muurlicht Links', 'State': True, 'Level': 25, 'Hex': 'efd275'}]}
{'action': 'deviceUpdate', 'status': 'Ok', 'result': [{'DeviceID': 65539, 'Name': 'Tafellicht', 'State': False, 'Level': 254, 'Hex': 'efd275'}]}

Note: it says COAP-adaptor version 0.7 in stead of 0.8 and doesn't list my 4 sockets, only the lights - but no errors.

moroen commented 5 years ago

You haven't got the latest debug version, it should be version 0.8, and you should disable domoticz while trying a dryrun...

$ git checkout debug $ gif fetch origin $ git pull

$ python3 tradfri.tac --dryrun

HansVanEijsden commented 5 years ago

Thank you again! This worked, to be sure I did a fresh checkout too. Here's the output:

# python3 tradfri.tac --dryrun
IKEA-tradfri COAP-adaptor version 0.8 started (command line)!
Initializing gateway
Adding light with ID: 65541
Traceback (most recent call last):
  File "tradfri.tac", line 561, in <module>
    endpoints.serverFromString(reactor, "tcp:1234").listen(AdaptorFactory()).addErrback(error)
  File "tradfri.tac", line 303, in __init__
    self.initGateway(None, None)
  File "tradfri.tac", line 376, in initGateway
    if dev.has_socket_control:
AttributeError: 'Device' object has no attribute 'has_socket_control'
moroen commented 5 years ago

AttributeError: 'Device' object has no attribute 'has_socket_control' indicates that the version of pytradfri being used, is not a version that supports sockets... Is it possible you have more than one version of the pytradfri library installed?

moroen commented 5 years ago

I would try:

$ pip3 uninstall pytradfri (user version) $ sudo pip3 uninstall pytradfri (system version) $ sudo pip3 install pytradfri (install fresh global version)

HansVanEijsden commented 5 years ago

That's certainly possible and I think I own you a beer! 🍻 After I did a pip3 uninstall pytradfri (it displayed Successfully uninstalled pytradfri-5.5.1!) all works.

# python3 tradfri.tac --dryrun
IKEA-tradfri COAP-adaptor version 0.8 started (command line)!
Initializing gateway
Adding light with ID: 65541
Adding socket with ID: 65548
Adding light with ID: 65540
Adding light with ID: 65538
Adding light with ID: 65542
Adding socket with ID: 65543
Adding socket with ID: 65546
Adding socket with ID: 65547
Adding light with ID: 65539
{"action": "getLights", "status": "Ok", "result": [{"DeviceID": 65541, "Name": "Muurlicht Rechts", "Type": "Light", "Dimmable": true, "HasWB": true, "HasRGB": false}, {"DeviceID": 65540, "Name": "Plafond", "Type": "Light", "Dimmable": true, "HasWB": true, "HasRGB": false}, {"DeviceID": 65538, "Name": "Stalamp Plafond", "Type": "Light", "Dimmable": true, "HasWB": false, "HasRGB": true}, {"DeviceID": 65542, "Name": "Muurlicht Links", "Type": "Light", "Dimmable": true, "HasWB": true, "HasRGB": false}, {"DeviceID": 65539, "Name": "Tafellicht", "Type": "Light", "Dimmable": true, "HasWB": true, "HasRGB": false}, {"DeviceID": 65548, "Name": "Audioset", "Type": "Outlet"}, {"DeviceID": 65543, "Name": "Glazenkast", "Type": "Outlet"}, {"DeviceID": 65546, "Name": "TV-Set", "Type": "Outlet"}, {"DeviceID": 65547, "Name": "Buislamp Hoek", "Type": "Outlet"}]}
{'action': 'deviceUpdate', 'status': 'Ok', 'result': [{'DeviceID': 65541, 'Name': 'Muurlicht Rechts', 'State': True, 'Level': 25, 'Hex': 'efd275'}]}
Error sending light state
{'action': 'deviceUpdate', 'status': 'Ok', 'result': [{'DeviceID': 65540, 'Name': 'Plafond', 'State': False, 'Level': 254, 'Hex': 'f1e0b5'}]}
Error sending light state
{'action': 'deviceUpdate', 'status': 'Ok', 'result': [{'DeviceID': 65538, 'Name': 'Stalamp Plafond', 'State': True, 'Level': 63, 'Hex': '0'}]}
Error sending light state
{'action': 'deviceUpdate', 'status': 'Ok', 'result': [{'DeviceID': 65542, 'Name': 'Muurlicht Links', 'State': True, 'Level': 25, 'Hex': 'efd275'}]}
Error sending light state
{'action': 'deviceUpdate', 'status': 'Ok', 'result': [{'DeviceID': 65539, 'Name': 'Tafellicht', 'State': False, 'Level': 254, 'Hex': 'efd275'}]}
Error sending light state
{'action': 'deviceUpdate', 'status': 'Ok', 'result': [{'DeviceID': 65548, 'Name': 'Audioset', 'State': True}]}
{'action': 'deviceUpdate', 'status': 'Ok', 'result': [{'DeviceID': 65543, 'Name': 'Glazenkast', 'State': False}]}
{'action': 'deviceUpdate', 'status': 'Ok', 'result': [{'DeviceID': 65546, 'Name': 'TV-Set', 'State': False}]}
{'action': 'deviceUpdate', 'status': 'Ok', 'result': [{'DeviceID': 65547, 'Name': 'Buislamp Hoek', 'State': False}]}

I feel a little bit stupid, because normally I try to resolve all the things myself without asking others their precious time.. and now it was my own mistake by having installed two versions of pytradfri. Thanks so much for the help and assistance.. it looks like it works now! 👍🏻 😃

moroen commented 5 years ago

Glad it worked out. One final advice, switch back to the development branch if you haven't already done so, the debug branch is volatile... :)