-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC REST-API v2 #1
Comments
Love where this is going! My initial thoughts below.
Agreed. Probably provide
Agreed. This does mean no more compatibility with the Hue API, making it hard(er) for clients to support both the deCONZ gateway and the Hue bridge. I'll probably create a separate homebridge-deconz plugin for the v2 API.
I particularly like the "without much hassle" part. I'm not sure adding a dependency to yet another package qualifies as that. There seems to be a NodeJS implementation, or at least a wrapper, of
I haven't yet given that much thought, but I'm not sure I would agree. Looking at the next and previous points, it might actually be better to start a new deCONZ REST API v2 plugin from scratch, rather than gradually changing the current plugin.
I couldn't agree more. I think a key ingredient would be a proper class hierarchy with subclasses to handle exceptions instead of lengthy methods with dozens of
For me capabilities are needed at two levels:
I like the idea of a layered architecture, where the "raw" low-level v2 API would be RESTifying the ZCL commands and attributes (cf. the level of the GUI interface and the CLI plugin), on top of which which the high-level v2 API would provide the "cooked" home automation features (caching values, rules, ...). We might even consider developing these layers as two separate repositories. On the long run, the high-level API v2 might be used with implementations of the low-level API v2, e.g. using the RaspBee/ConBee serial interface to the radio device, or using other hardware (e.g. XBee). And the Hue-compatible v1 API might eventually be based on the same low-level v2 API.
What about the "without much hassle" part? Afaik, MQTT requires an additional server component where web sockets do not. |
I‘m not able to contribute anything useful due to a lack of knowledge of the inner workings of deConz/ZCL (I‘m merely an API user). But I suggest taking a look at the Z-Way (Devices) API which I‘m using to control some ZWave powered devices on my RPi, such as blinds and outlets. |
I strongly recommend not rolling a new transport security protocol. That's a huge amount of implementation work, and making something new implies a bunch of work for all clients (TLS is available everywhere, your custom protocol will not be) and almost certain security vulnerabilities. I think for this application, bearer tokens are sufficient for authorization and authentication. Transport security should definitely be TLS, you could use |
Oh, and I should note that this isn't just a drive-by suggestion 😄 I'm a happy deConz user, and I'm quite happy to help you through any questions and issues around implementing TLS and bearer tokens properly. |
Hi all, thanks a lot for sharing the first ideas. I've been researching the topic of software architecture since a while now and found some stuff in the Internet which might be useful to proceed with the REST-API v2. Albeit this GH issue is quite young there are already a lot ideas and comments on ideas. Perhaps it's time to get these "on paper", before they get lost in the growing comment stream, see (2) below. As a side note and small update, the Phoscon internal software developer team (we are 6 now) is cooking various new features and refactoring parts of the system, there is a notable a rush to get more thought in the craft of solid, maintainable code, compared to the past we're using way more paper and white-boards now :) Back to the architecture topic, I think the basic idea of the following might be useful:
What do you think, should we bring the first ideas in the wiki and would you consider something like ADRs to be useful? As alternative we could write aspects into own sections, but I'm afraid this might get too cluttered over time and thoughts which were part of decisions easily get lost. Perhaps there are better alternatives? |
I like the idea of using ADRs, but I think it'd be good if they went through Pull Requests into either this repo or separate one. That way comments and additions could be discussed around each ADR on PRs. I don't think putting them in the wiki would facilitate discussions well. |
First of all, I think this is a great initiative. At this point some more general comments are probably most useful. These are of course my personal opinions so feel free to ignore them, but:
Hope this helps. |
+1 for ADRs. I don't have any particular preference how to implement them (Wiki or PR). I think using C4 or something similar would be beneficial, especially when starting with an overview of the various containers:
Preferably a with separate GitHub repository for each container. Now we get a lot of end-user support issues for Phoscon in the REST API repository, were none of the REST API contributors can do anything, as Phoscon isn't open source. |
I don't see a reason to go away from web sockets. If anything we should allow all communication to go over web sockets when not emulating the hue api. I think the main thing to improve is how to model the data, right now there are lights, sensors, groups and config endpoints. With all the different device types supported maybe there should be one endpoint for all physical devices and then other endpoints that are purely virtual. One thing Im missing is to know what attributes of a device are optional and what are always available. Things like that should be documented. All events should be signalled to api users, creation, update, removal When you start developing the full api it would be nice if you could share a micro server emulating a full deconz server with all different devices available |
https://github.com/dresden-elektronik/deconz-rest-plugin/issues/1688#issuecomment-519979187
I like that, the current issues and topics are pretty broad and slightly chaotic. Organising them should clarify and help users and contributors. Here's a rough sketch of a proposal:
As for topics like Websockets, MQTT and HTTPS or other crypto mechanisms, I think we are not restricted :) There can be multiple providers which just implement a certain high level interface and just forward events and actions to and from the desired format with encryption on top. The lower level code doesn't need to know about REST, JSON or crypto it only cares about commands with parameters and fires events with related data, therefore the API on this level is basically just C++ data structures passed between methods and implemented interfaces (which are registered and activated, like Websockets). |
One suggestion that I have is that it would be great if deCONZ core exposed an API to the higher layers which does not use Qt. The reason being that this would make it much easier to do independent development on top of it (which is nice, you'll sell even more hardware) and do experimentation. I really wanted for example to build a proof-of-concept implementation of more-or-less the same REST API as the one existing now but using Rust instead. What I wanted to experiment with is trying to refactor the existing device-specific logic from being all over the place to an encapsulated quirks "database". The reason I don't do that today is because my knowledge of C++ is very rusty (from 2 decades ago, a different time) and I'm not used to Qt and Qt does not have too many bindings. If I could demonstrate the idea as a proof-of-concept, even if the code itself does not end up being used it's more useful to have working code reimplemented in C++ than a high-level description. Regarding the new API, if the core API was not Qt-based but had pure C bindings then anybody with wild ideas would be able to sit down and implement an alternative REST layer with their stack of choice, which would be useful at the very least to exchange ideas for V2. P.S.: I may not have been clear enough above, so I'm not suggesting that the core should not be implemented in Qt (this is not realistic, it would require a rewrite). Just that it would be nice if there was an exported API that did not use Qt, in order to make it easier to build something on top of the core in a different programming language than C++. |
I'd also like to add my 2 cents. First of all, I'd suggest to treat every end device as what it is: a device or thing. That would mean wrapping it in such a meta class and read its endpoints, profiles, attributes and what not generically. I guess this is not far from what the core currently does and presents in the GUI. While having that, a device whould be extensible with device or vendor specific clusters, command or what is required to have it fully functional. It's pretty much what zigbee2mqtt does with zigbee-herdsman. You do not have to touch the core functionality but can write an own extension for a (new) device. Really love this approach. Another thing really great to have would be a revised debugging. For me, it would be of help to be able to see e.g. raw hex values in requests and responses (as well as relevant parts of the packet structure) when I'm after something. In that sense, wireshark often helped me to better understand what might have gone right or wrong if you know what I mean. Lastly, as a sort of premium feature, it would be awesome to have the capability to send customized packets to force certain (or vendor specific) commands for example. Probably nothing for the API but maybe for a layer below. I'm also fully with the other suggestions. Especially, I strongly support the HTTPS intruduction. Security should play an important role here, even if it's just inside ones personal network. As of now, I don't see such a difficulty using openssl. I'd generate a self signed cert during installation for basic security. However, it should be possible to also exchange them by your own (PKI-based) certs. This would knid of eliminate the necessity of using a reverse proxy. |
Is there already a beta version of the REST-API v2? |
I also think that the API should be rewritten and improved. Adding new devices is really a pain compared to zigbee2mqtt. |
BTW, there is some news about this API V2 ? |
up ! any news for us @manup ? |
A mqtt api would be a nice add! |
Any news? |
I'd like to expand on my previous comment. I think there should be a list of all devices on a high level giving attributes such as name (there is no need to allow each endpoint to be named separately), model, serial, manufacturer etc... and then all endpoints fitting to be presented separately from that device should have its own entry as well. Another important thing is that everything should have events over web socket. Right now it seems about 50% coverage :)
|
As per announcement on Discord, this Friday there will be a dev meeting again. Please share anything related. Concerns, wishes, feedback: All is welcome. |
First of all, I'm a huge fan and user of deconz, so please take this all constructively! It would be great to have a parameter available for each device where I could add some application state/data related to each device. Since I use the API continually, this feature would be convenient and simplify the design of browser applications. Regarding websockets, please consider a way to configure which fields are included in event messages. If that's not possible, please at least include the: Finally, please consider adding more explanations and E X A M P L E S. It took a long time to figure out how to pair devices using the api. I'm still not sure how "reachable" is determined. Regarding "Creating" sensors, is this for when we have unknown hardware? |
But with the type and the id, it's easy to find the name and the model ? |
A slightly larger data size doesn't bother me since it's a websocket link (not a Zigbee RF link where data size is critical to preserving battery). Without those fields, I need to maintain a local data model for 80 devices in my app, make an API request every time a websocket event comes in, error-handle it, and when successful, merge with the local data model. It's just a suggestion which I hope the Friday meeting can consider. If no one sees the value of this, the first part of my websocket suggestion is to let the developer configure which fields are included in event messages. Thanks for your consideration. :-) |
On my side I m making like you "maintain a local data model", But I don't need "make an API request every time a websocket event comes in", I just update the local data. Some device like power mesurement plug can be realy talkative with websocket ^^. |
@Digital-Thor IIRC you can actually configure the web socket to send all data, so that should already be supported. Just like @Smanar Im doing a web request to deconz on start up and then I just add the changes to that data when changes are sent over web socket. |
For tonights discussion I'd like to point out since the improvements are gonna be incremental I propose that we focus on the device level API forward |
Why
I think it's time that we need to figure out a proper v2 REST-API to support a wider range of devices which are available today or might arrive in the future. I'm increasingly unhappy about the /lights hack which is currently used in some places to add devices which don't fit in the provided categories.
A first humble attempt to address more complex devices was the /devices endpoint which allows querying all sub-devices behind one physical device referenced by its MAC address. dresden-elektronik/deconz-rest-plugin@96daf83
Request For Comments
To proceed I invite everyone to share ideas and wishes how a new interface may look like.
Beside this GH issue the RFC REST-API v2 wiki page should be used to develop the new API.
Initial thoughts
Resource
andResourceItem
C++ classes are a good common ground to build a generic API on top. These are already used in many places and simplify the implementation of the rules engine. For v2 they are likely to be extended to be more versatile.The text was updated successfully, but these errors were encountered: