Update 适配器.md

master
钟进 6 years ago
parent 4d0c8c8ad0
commit 47ac0d40fd

@ -1,4 +1,4 @@
# 适配器开发人员指南 (javascript/NodeJS)
# 适配器开发人员指南 (javascript/NodeJS)
## 内容
- [数据结构 - 对象和状态](#data-structure---objects-and-states)
@ -647,27 +647,29 @@ Date format will be available under ```adapter.dateFormat```.
#### How to read state
#### 如何读取状态
There are two modes to read states in ioBroker adapter:
- event subscription (suggested)
- polling
在ioBroker适配器中有两种读取状态的模式
- event subscription 活动订阅(推荐)
- polling 轮询
要订阅 **subscribe** 事件,必须调用以下命令:
To **subscribe** on own events the following command must be called:
```
adapter.subscribeStates('*'); // subscribe on all variables of this adapter instance with pattern "adapterName.X.*"
adapter.subscribeStates('memory*'); // subscribe on all variables of this adapter instance with pattern "adapterName.X.memory*"
```
To subscribe on other events:
订阅其他活动:
```
adapter.subscribeForeignStates('yr.*.forecast.html'); // subscribe on variable "forecast.html" of all adapter instances "yr".
```
Wildcard "*" can be used in both functions.
通配符 “*” 可用于两种功能。
之后,您将获得事件 ["stateChange"](#most-important-events) 并可以使用此值执行某些操作。
订阅后,您将无法获得实际状态,因为事件只会在变化时出现。要获得初始状态,您应该在开始时执行“轮询”一次(通常在 "ready" event
After that you will get the event ["stateChange"](#most-important-events) and can do something with this value.
After subscription you will not get the actual state, because events will come only on change. To get the initial state you should perform "poll" one time at start (normally in "ready" event).
**轮询**
要在开始时读取自己的状态或使用间隔使用功能读取值 ```adapter.getState``` ,如下所示:
**Polling**
To read own states at start or to read the values with interval use function ```adapter.getState```, like here:
```
adapter.getState('myState', function (err, state) {
@ -682,10 +684,13 @@ adapter.getState('myState', function (err, state) {
});
```
Pay attention, that result will be returned asynchronous.
注意,结果将异步返回。
To read states of other adapters you should use ```adapter.getForeignState``` function. No wildcards are supported.
要读取其他适配器的状态,您应该使用```adapter.getForeignState```函数。不支持通配符。
#### Commands and Statuses
#### 命令和状态
We should distinguish between commands and statuses, when we are talking about states.
"Command" has **ack** flag as _false_ and will be sent by user (over vis, javascript-adapter, admin) to control the devices or specific adapter. Normally adapters (e.g. homematic) are subscribed on all own changes and if some state changes with _ack=false_, they will try to execute this command (e.g. light on).

Loading…
Cancel
Save