LarsMichelsen / pmatic

Python API for Homematic. Easy to use.
https://larsmichelsen.github.io/pmatic/
GNU General Public License v2.0
34 stars 23 forks source link

pmatic initialization on CCU #4

Closed MFlasskamp closed 8 years ago

MFlasskamp commented 8 years ago

According to the examples I tried this on the CCU2:

python
>>> import pmatic
>>> ccu = pmatic.CCU()

So no address and no credentials as I'm running it on the CCU locally. That fails with:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/etc/config/addons/pmatic/python/lib/python2.7/pmatic/ccu.py", line 67, in __init__
    self.api = pmatic.api.init(**kwargs)
  File "/usr/local/etc/config/addons/pmatic/python/lib/python2.7/pmatic/api.py", line 94, in init
    "to access your CCU (%s)." % e)
pmatic.exceptions.PMException: You need to provide at least the address and credentials to access your CCU (__init__() takes at least 3 arguments (1 given)).
LarsMichelsen commented 8 years ago

pmatic ships with a code that is meant to detect whether or not the pmatic script is being executed on the CCU or another system. In case it is executed on the CCU, it should simply ignore the provided address and login credentials and simply connect to the local CCU APIs.

I realized it this way to make it possible to execute remotely developed pmatic scripts on the CCU without removing the credentials etc.

So in theory, and on my CCU2,

ccu = pmatic.CCU()

equals to

ccu = pmatic.CCU(address="http://192.168.1.26", credentials=("Admin", "EPIC-SECRET-PW"))

when executed on the CCU.

The CCU detection is based on the uname output of the system. Could you please send me the output of this command executed on your CCU:

python -c 'import os ; print(os.uname())'

I could not imagine that it would be different for the CCUs. Maybe the detection needs to be adapted a bit.

MFlasskamp commented 8 years ago

Maybe because of the new firmware 2.17.4?

# python -c 'import os ; print(os.uname())'
('Linux', 'ccu2', '3.4.11.ccu2', '#1 PREEMPT Wed Dec 16 09:23:30 CET 2015', 'armv5tejl')

(related: os.uname() does not work with Windows. An alternative would be platform.uname() but requires the platform module)

LarsMichelsen commented 8 years ago

Oh, got it. My fault. I thought the 2nd element was a generic name, but it is the local hostname, which is ccu2 for your device and ccu for mine. So the detection failed. Changed it now to use the suffix of the 3rd field.

Related to the Windows thing: I am currently unsure if I want to support pmatic on Windows. It seems to be a reasonable target to support it, but I have no experience yet with supporting Python code like on Windows and Linux.