diff --git a/适配器.md b/适配器.md index e5832b4..e7eb27d 100644 --- a/适配器.md +++ b/适配器.md @@ -1,15 +1,15 @@ -# Guide for adapter developers (javascript/NodeJS) +# 适配器开发人员指南 (javascript/NodeJS) -## Content -- [Data structure - Objects and states](#data-structure---objects-and-states) -- [Directory structure of adapter](#directory-structure-of-adapter) -- [File naming](#file-naming) -- [Structure of io-package.json](#structure-of-io-packagejson) +## 内容 +- [数据结构 - 对象和状态](#data-structure---objects-and-states) +- [适配器的目录结构r](#directory-structure-of-adapter) +- [文件命名](#file-naming) +- [io-package.json 的结构](#structure-of-io-packagejson) - [Common fields](#common-fields) - [Object fields](#object-fields) - [Instance object fields](#instance-object-fields) -- [package.json](#packagejson) -- [Deploying](#deploying) +- [package.json 的结构](#packagejson) +- [部署](#deploying) - [How to create own adapter](#how-to-create-own-adapter) - [Structure of main.js](#structure-of-mainjs) - [Options of adapter](#options-of-adapter) @@ -31,19 +31,25 @@ - [How to create instance](#how-to-create-instance) - [How to debug](#how-to-debug) - [admin.html](#adminhtml) -- [Best practice](#best-practice) +- [最佳实践](#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. +oBroker中的适配器是一个独立的进程,它在中央数据存储中读取和写入对象和状态。数据存储可以表示为数据库(redis / couchDB)或只是文本文件,但连接方式始终相同 - 通过API。这意味着,开发人员不应该关心数据库是什么以及如何在那里存储和交付数据。 + There are two types of data in the storage: +存储中有两种类型的数据: - Objects - States Objects are static descriptions of some data point. States are the dynamic values of data points. So normally for every state there is a object with description. (But not vice versa). +对象是某些数据点的静态描述。状态是数据点的动态值。所以通常对于每个州都有一个描述对象。(但反之亦然) Objects additionally describe: - configuration of hosts @@ -57,12 +63,21 @@ Objects additionally describe: You can explore the objects and the current state values in admin adapter on the "Objects"-tab. +您可以在“对象”选项卡上的管理适配器中浏览对象和当前状态值。 + The name of object consists of different parts. Every part is divided by "." from each other. There is a system objects (name starts with _ or "system.") and adapter objects (name starts with _adapterName_). +对象的名称由不同的部分组成。每个部分除以“。” 彼此。有一个系统对象(名称以_或“system。”开头)和适配器对象(名称以adapterName开头)。 + + **Note:** here and forth **adapterName** is the name of the adapter that a developer wants to create. +注意 adapterName是开发人员想要创建的适配器的名称。 + The states can be grouped in channels and the channels in devices. Here is a example of Homematic groups and channels: +状态可以分组在通道和设备中的通道中。以下是Homematic组和频道的示例: + - hm-rpc.0.IEQ1234567 - device - hm-rpc.0.IEQ1234567.0 - channel @@ -73,32 +88,49 @@ The states can be grouped in channels and the channels in devices. Here is a exa - hm-rpc.0.IEQ1234567.0.BATTERY - state The state ID must always start with channel name and channel name with device name. E.g. in the state name **hm-rpc.0.IEQ1234567.0.INFO** above, the part **hm-rpc.0.IEQ1234567.0** is the channel name and **hm-rpc.0.IEQ1234567** is the device name. +状态ID必须始终以通道名称和通道名称与设备名称开头 It is used to build the coordination of device, channels and states in hierarchy. +它用于在层次结构中建立设备,通道和状态的协调。 + **Note:** If adapter is not so complex, the devices and even channels can be omitted. +注意:如果适配器不是那么复杂,可以省略设备和偶数通道。 + **Adapter** is just the package of files and placed in _node_modules_ directory. For every adapter the description of this adapter can be found in object "_system.adapter.adapterName_". It is just the fields "common" and "native" from the io-package.json file. This entry is created automatically when _iobroker install adapterName_ or _iobroker add adapterName_ called. If the adapter was installed with _npm install iobroker.adapterName_ no entry will be created till first instance creation. But it is not so important. The required for "updates" information will be read from _io-package.json_ directly. Full list of common settings for adapter can be found [here](https://github.com/ioBroker/ioBroker/blob/master/doc/SCHEMA.md#adapter) +Adapter只是文件包,放在node_modules目录中。对于每个适配器,可以在对象“ system.adapter.adapterName ”中找到此适配器的描述。它只是来自io-package.json文件的“common”和“native”字段。当iobroker安装adapterName或iobroker add adapterName被调用时,将自动创建此条目。如果使用npm install iobroker.adapterName安装适配器,则在创建第一个实例之前不会创建任何条目。但它并不那么重要。“更新”信息所需的信息将直接从io-package.json中读取。可以在此处找到适配器的常用设置的完整列表 + + **Instance** is an instance of adapter. Depending on type of adapter more than one instance can be created , but for some adapters there is no use to create more than one instance. E.g. in case of vis or rickshaw only one instance can be created. This behavior is controlled by flags in _io-package.json_. +**Instance** 是适配器的实例。根据适配器的类型,可以创建多个实例,但对于某些适配器,创建多个实例是没有用的。例如,在vis或rickshaw的情况下,只能创建一个实例。此行为由io-package.json中的标志控制。 For each instance the configuration object can be found in the data storage under "_system.adapter.adapterName.X_" ID, where X is the adapter instance number. It contains the settings for this instance of the adapter. Normally it consist of "common" and "native" settings. Common settings are: +对于每个实例,可以在“ system.adapter.adapterName.X ”ID 下的数据存储中找到配置对象,其中X是适配器实例编号。它包含适配器的此实例的设置。通常它由“常见”和“原生”设置组成。常见设置是: + - enabled: true/false; - host: host name where this instance must run; - mode: none, daemon, subscribe, schedule, once; Description can be found [here](https://github.com/ioBroker/ioBroker/blob/master/doc/SCHEMA.md#instance) +描述可以在这里找到 + "Native" settings consist of **specific** configurations for this adapter, e.g.: IP address of device, device settings and so on. +“本机”设置由此适配器的特定配置组成,例如:设备的IP地址,设备设置等。 **Note:** Instances can run on different hosts (in multi-hosts systems) and the adapters can have different version on different hosts. +注意:实例可以在不同的主机上运行(在多主机系统中),并且适配器可以在不同的主机上具有不同的版本。 All adapter instance object IDs starts with _adapterName.X_, where X is number of adapter instance. +所有适配器实例对象ID都以adapterName.X开头,其中X是适配器实例的编号。 Objects have different [types](https://github.com/ioBroker/ioBroker/blob/master/doc/SCHEMA.md#object-types) for different purposes. +对象具有不同类型以用于不同目的。 For every adapter (not the instance) the following objects will be created automatically: