Update 适配器.md

This commit is contained in:
钟进 2018-09-23 20:07:38 +08:00
parent 7b0ef48560
commit 2102b91c25

View File

@ -34,8 +34,7 @@
- [最佳实践](#best-practice)
## Data structure - Objects and states
数据结构 - 对象和状态
## 数据结构 - 对象和状态
An adapter in ioBroker is an independent process, that reads and writes objects and states in a central data storage.
Data storage can be represented as database (redis/couchDB) or just text file, but the connection way is always the same - via API. That means, the developer should not care about what the database it is and how the data will be stored and delivered there.
@ -167,8 +166,7 @@ Explanation of memory states can be found [here](http://stackoverflow.com/questi
If adapter has mode 'none' or 'once', then alive, uptime, ... objects will not be created.
## Directory structure of adapter
适配器的目录结构
## 适配器的目录结构
Adapter package must have some mandatory directories and files:
@ -191,7 +189,7 @@ Adapter package must have some mandatory directories and files:
## File naming
文件命名
## 文件命名
Adapter must must follow some naming convention to be accepted and started by ioBroker controller.
@ -204,6 +202,7 @@ Adapter must must follow some naming convention to be accepted and started by io
4. Name of adapter must be unique, lowercase, with no special characters and without spaces. "-", "_" are allowed in the name of adapter.
## Structure of io-package.json
## io-package.json结构
io-package.json is used by js-controller to show information about adapter and to know how to treat it.
Complete description of all fields in common part can be found [here](https://github.com/ioBroker/ioBroker/blob/master/doc/SCHEMA.md#adapter)
@ -218,7 +217,7 @@ io-package.json将被“admin”读取以找出适配器的在线版本。
### Common fields
### 公共字段
Most important fields in **common** are:
@ -263,14 +262,19 @@ E.g. "http://%ip%:%port%" will be shown as "http://192.168.0.1:8080", where "192
### Object fields
### 对象字段
objects - static objects for all instances of adapter (xxx.object)
By installation of adapter (not the instance creation) some predefined objects (normally that describe something) can be created automatically. These objects must not depend on some specific instance and are common for all instances of this adapter. For example [hm-rpc](https://github.com/ioBroker/ioBroker.hm-rpc/blob/master/io-package.json) adapter has the structure description of all HomeMatic devices.
Additionally the new views can be defined. In SQL they are called ["stored procedure"](http://en.wikipedia.org/wiki/Stored_procedure) and in couchDB - [views](http://guide.couchdb.org/editions/1/en/views.html).
objects - 适配器的所有实例的静态对象xxx.object通过安装适配器而不是实例创建可以自动创建一些预定义对象通常描述某些内容。这些对象不能依赖于某些特定实例并且对于此适配器的所有实例都是通用的。例如hm-rpc适配器具有所有HomeMatic设备的结构描述。
此外可以定义新视图。在SQL中它们被称为“存储过程”在couchDB中也称为视图。
**Note**: do not mix with "vis" views.
注意不要与“vis”视图混合使用。
For view definitions the javascript language is used. Here is the sample:
```
{
@ -289,8 +293,12 @@ For view definitions the javascript language is used. Here is the sample:
Here are two views defined for hm-rpc adapter: "listDevices" and "paramsetDescription". They returns the set of filtered by view condition objects from data store. It can effective (if CouchDB used) request the specified list of objects.
是为hm-rpc适配器定义的两个视图“listDevices”和“paramsetDescription”。它们从数据存储中返回由视图条件对象过滤的集合。它可以有效如果使用CouchDB请求指定的对象列表。
To use view:
要使用视图:
```
adapter.objects.getObjectView('hm-rpc', 'listDevices',
{startkey: 'hm-rpc.' + adapter.instance + '.', endkey: 'hm-rpc.' + adapter.instance + '.\u9999'},
@ -312,7 +320,12 @@ Usage of _startkey_ and _endkey_ can be found on the [same page](http://guide.co
**Note:** usage of views is optional and demands from developer basic knowledge level about CouchDB.
注意视图的使用是可选的并且需要开发人员关于CouchDB的基本知识水平。
### Instance object fields
### 实例对象字段
Some specific objects or objects with type states can be defined in _instanceObjects_ of io-package.json.
For every created instance all entries from _instanceObjects_ field will be created.