Device事件集合
Example
import {DeviceEvent} from 'miot'
...
class MyPage extends React.Component{
componentWillMount(){
this.subscription = DeviceEvent.deviceReceivedMessages.addListener((device, messages)=>{
if(!this.props.navigation.isFocused()){
return;
}
...
})
}
...
componentWillUnmount(){
...
this.subscription.remove()
}
...
}
...
Events
deviceNameChanged
设备名称变更事件
Parameters:
Name | Type | Description |
---|---|---|
device |
IDevice | 发生变更的设备 |
- Since:
- 1.0.0
deviceReceivedMessages
设备消息
Parameters:
Name | Type | Description |
---|---|---|
device |
IDevice | |
messages |
Map.<string, object> | 接收到的数据 |
originData |
array | 接收到的数据, [{key,time,value}] |
Example
import {Device, DeviceEvent} from 'miot'
let msgSubscription = null;
Device.getDeviceWifi().subscribeMessages("prop.power", "event.something").then(subcription=>{
msgSubscription = subcription;
});
...
const subscription = DeviceEvent.deviceReceivedMessages.addListener(
(device, messages)=>{
if(messages.has('prop.power')){
const power = messages.get('prop.power');
...
}
...
})
...
msgSubscription&&msgSubscription.remove();
deviceStatusChanged
设备状态变更事件
Parameters:
Name | Type | Description |
---|---|---|
device |
IDevice | 发生变更的设备 |
deviceTimeZoneChanged
设备时区变更事件
Parameters:
Name | Type | Description |
---|---|---|
device |
IDevice | 发生变更的设备 |
- Since:
- 1.0.0