Howdy.
I was excited when my RaZberry module arrived in the mail. Tossing my Aeon stick aside and plugging my RaZberry in, I quickly started reading up on all of the APIs that are available. With the Aeon stick I was writing my own serial IO interface, discovering the network, trying to frame the bits properly, write job control logic, etc. What a pain!
All of this was being written in Python, and there are specific reasons for using Python, namely use of the Twisted framework and the manner in which I could handle web requests as well as interface with the serial device. Now I'm looking at taking the existing Python code and working with the Z-Way API. I get that there is a mechanism for interating via JSON as well as POSTing Javascript code, but my application is server-side and running alongside the Z-Way server on my RaspberryPi, so what I want to do is, in my Python code, talk directly to Z-Way through... what? That's where I'm confused.
There's a C library, but there are also a lot of examples using straight up Javascript. But how does one interface with that Javascript, particularly if I'm embedding that Javascript into a runtime interpreter through Python (PyExecJS). Or, to make it even simpler, let's say I have node (as in node.js) on my Pi, and I'm sitting at the console. How do I interact with Z-Way through that?
Using Server-side Javascript
Re: Using Server-side Javascript
PyExecJS won't help you here, because even if it supported raw v8 as execution engine, it is still stateless.
Z-Way, on the other hand, require state to be preserved between calls.
Leaving aside C library, Z-Way offers you two automation interfaces: server-side JS and REST API.
Server-side JS is a preferred way for automation, if Z-Way is a master part. You write a JS module and put it into modules folder, so it can run as a part of a system. Here you can run external programs (with system() call) or interact with other servers.
In case Z-Way is a slave and expects commands from master, REST API comes in play. Since Z-Way is running as a service, you can't just exec it, you should pass your request via some RPC protocol. We decided it would be HTTP.
So in your case, you need to use local HTTP request from Python, like OpenRemote does.
The other option is to build a Python wrapper around C library. In this case you'll lose web UI and JS/automation features, but get full control over your program.
Z-Way, on the other hand, require state to be preserved between calls.
Leaving aside C library, Z-Way offers you two automation interfaces: server-side JS and REST API.
Server-side JS is a preferred way for automation, if Z-Way is a master part. You write a JS module and put it into modules folder, so it can run as a part of a system. Here you can run external programs (with system() call) or interact with other servers.
In case Z-Way is a slave and expects commands from master, REST API comes in play. Since Z-Way is running as a service, you can't just exec it, you should pass your request via some RPC protocol. We decided it would be HTTP.
So in your case, you need to use local HTTP request from Python, like OpenRemote does.
The other option is to build a Python wrapper around C library. In this case you'll lose web UI and JS/automation features, but get full control over your program.