Update 适配器.md
This commit is contained in:
parent
9fddd73c90
commit
f8b86fc630
38
适配器.md
38
适配器.md
@ -19,7 +19,7 @@
|
||||
- [实例配置](#instance-configuration)
|
||||
- [如何读取状态](#how-to-read-state)
|
||||
- [Commands and Statuses](#commands-and-statuses)
|
||||
- [How to write state](#how-to-write-state)
|
||||
- [如何写状态](#如何写状态)
|
||||
- [Structure of state](#structure-of-state)
|
||||
- [Running modes of adapter](#running-modes-of-adapter)
|
||||
- [How to read object](#how-to-read-object)
|
||||
@ -644,8 +644,7 @@ Date format will be available under ```adapter.dateFormat```.
|
||||
可以使用```getForeignObject```功能手动读取所有其他配置。
|
||||
|
||||
|
||||
#### How to read state
|
||||
#### 如何读取状态
|
||||
#### 如何读状态
|
||||
|
||||
在ioBroker适配器中有两种读取状态的模式:
|
||||
- event subscription 活动订阅(推荐)
|
||||
@ -688,7 +687,6 @@ Pay attention, that result will be returned asynchronous.
|
||||
|
||||
要读取其他适配器的状态,您应该使用```adapter.getForeignState```函数。不支持通配符。
|
||||
|
||||
#### Commands and Statuses
|
||||
#### 命令和状态
|
||||
我们应该区分命令和状态。
|
||||
|
||||
@ -719,10 +717,9 @@ This change will not be executed by _hm-rpc_ adapter, because **ack** is _true_.
|
||||
hm-rpc适配器不会执行此更改,因为ack为true。这是来自物理设备的确认。
|
||||
|
||||
|
||||
#### How to write state
|
||||
#### 如何写状态
|
||||
|
||||
States can be written as commands or as statuses. For that ```adapter.setState``` and ```adapter.setForeignState``` must be used:
|
||||
状态可以写为命令或状态,States can be written as commands or as statuses. For that ```adapter.setState``` and ```adapter.setForeignState``` must be used:
|
||||
|
||||
```
|
||||
adapter.setForeignState('otherAdapter.X.someState', 1); // Control other adapter (there is no need to control own state, we can do it directly)
|
||||
@ -735,37 +732,44 @@ adapter.setState('myState', 1, true, function (err) {
|
||||
});
|
||||
```
|
||||
|
||||
**Note**: Following commands are identical
|
||||
**注意**:以下命令是相同的
|
||||
|
||||
|
||||
```
|
||||
adapter.setState('myState', 1, false);
|
||||
adapter.setState('myState', 1);
|
||||
```
|
||||
|
||||
#### Structure of state
|
||||
#### state 结构
|
||||
|
||||
State is a javascript object with following attributes:
|
||||
- **val**: Value of state (desired value or actual value)
|
||||
- **ack**: direction flag. **false** for desired value and **true** for actual value. Default: false (command)
|
||||
- **ts**: time stamp as the number of milliseconds between midnight of January 1, 1970 and the specified date. Result of method getTime() of Javascript object Date. Default: actual time.
|
||||
- **lc**: last change time stamp. Same format as **ts**, but the time stamp of value change. It can be so that the value will be updated, but the value will stay the same. In this case **lc** will not be changed.
|
||||
- **from**: name of the adapter instance, that set the value, e.g. "system.adapter.web.0" (In case of vis)
|
||||
- **expire**: (optional) there is a possibility to set the expire timeout in seconds. After this period of time the variable will be set to "null". It will be used e.g. by "active" states of the adapter instances. If adapter instance will not trigger "active" state in 30 seconds it will be marked as **down**. To set state with expiration use following code ```setState('variable', {val: true, expire: 30})```
|
||||
- **ts**: 时间戳记为1970年1月1日午夜到指定日期之间的毫秒数。Javascript对象Date的方法getTime()的结果。默认值:实际时间。
|
||||
- **lc**: 最后更改时间戳。 Same format as **ts**, but the time stamp of value change. It can be so that the value will be updated, but the value will stay the same. In this case **lc** will not be changed.
|
||||
- **from**: 适配器实例的名称, that set the value, e.g. "system.adapter.web.0" (In case of vis)
|
||||
- **expire**: (optional) 以秒为单位设置过期超时。在这段时间之后,变量将被设置为“null”。它将用于例如适配器实例的“活动”状态。如果适配器实例在30秒内不会触发“活动”状态,则它将被标记为关闭。there is a possibility to set the expire timeout in seconds. After this period of time the variable will be set to "null". It will be used e.g. by "active" states of the adapter instances. If adapter instance will not trigger "active" state in 30 seconds it will be marked as **down**. To set state with expiration use following code ```setState('variable', {val: true, expire: 30})```
|
||||
- **q**: (optional) Quality. See [here](https://github.com/ioBroker/ioBroker/blob/master/doc/SCHEMA.md#states) the description
|
||||
|
||||
#### Running modes of adapter
|
||||
Adapter can run in different [modes](https://github.com/ioBroker/ioBroker/blob/master/doc/SCHEMA.md#adapterinstance-commonmode). The mode for adapter can me defined over ```common.mode``` attribute.
|
||||
#### 适配器的运行模式
|
||||
|
||||
- **none** - this adapter will not be started.
|
||||
- **daemon** - always running process (will be restarted if process exits)
|
||||
Adapter can run in different [modes](https://github.com/ioBroker/ioBroker/blob/master/doc/SCHEMA.md#adapterinstance-commonmode). The mode for adapter can me defined over ```common.mode``` attribute.
|
||||
适配器可以以不同的模式运行。适配器的模式可以在common.mode属性上定义。
|
||||
|
||||
- **none** - 不会启动此适配器.
|
||||
- **daemon** - 始终运行进程(如果进程退出,将重新启动)
|
||||
- **subscribe** - is started when state system.adapter.<adapter-name>.<instance-number>.alive changes to true. Is killed when .alive changes to false and sets .alive to false if process exits (will not be restarted when process exits)
|
||||
- **schedule** - is started by schedule found in system.adapter.<adapter-name>.<instance-number>.common.schedule - reacts on changes of .schedule by rescheduling with new state
|
||||
- **once** - this adapter will be started every time the system.adapter.<adapter-name>.<instance-number> object changed. **It will not be restarted after termination.**
|
||||
|
||||
Normally adapters should use mode **daemon**.
|
||||
通常,适配器应使用模式守护程序。
|
||||
|
||||
|
||||
If adapter just checks something every X minutes it should use mode "schedule" and define cron schedule in common.schedule (e.g. "1 * * * *" - every hour)
|
||||
|
||||
#### How to read object
|
||||
#### 读取对象
|
||||
|
||||
Objects can be read with getObject or getForeignObject command:
|
||||
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user