数据模型
## 数据模型
#### 1. 用户集合 | users
- /users/<user_id>
|字段|类型|说明|
|-|-|-|
|ezivz_account|Obj|对应萤石用户体系的accountName|
|tuya_account|Obj|对应涂鸦用户体系的username|
|wulian_account|Obj|对应物联用户体系的openid|
|devices|Collections|用户的设备集合,该子集已经移动到houses子集下面|
|scenes|Collections|用户的场景集合,该子集已经移动到houses子集下面|
|houses|Collections|用户的房子集合|
|joinHouses|Collections|用户加入的房子集合|
|issues|Collections|用户的问题反馈集合|
|currentHouse|Obj|用户当前选择的房子,{house_id:..., house_name:...}|
|is_delete|boolean|用户是否已经被删除|
<b>ezviz_account</b>
|字段|类型|说明|
|-|-|-|
|user_id|String|对应萤石用户体系的accountId|
|user_name|String|对应萤石用户体系的accountName|
|passwrod|String|对应萤石用户体系的password, md5加密|
<b>tuya_account</b>
|字段|类型|说明|
|-|-|-|
|user_id|String|对应涂鸦用户体系的uid|
|user_name|String|对应涂鸦用户体系的username|
|passwrod|String|对应涂鸦用户体系的password|
<b>wulian_account</b>
|字段|类型|说明|
|-|-|-|
|user_id|String|对应物联用户体系的open_id|
#### 2. 设备集合 | devices
- /users/<user_id>/devices/<device_id>
|字段|类型|说明|
|-|-|-|
|id|String|设备ID编号|
|category|String|设备类型,安防检测/环境检测/电器开关/摄像头|
|type|String|设备具体产品类型(SKU)|
|googleType|String|对应到google平台的产品类型|
|name|Obj|设备名称,包括defaultName, name, nicknames|
|deviceInfo|Obj|设备厂家信息,包括manufacturer, model, hwVersion, swVersion|
|error|String|设备出现错误,错误信息|
|willReportState|boolean|是否上报设备状态变化,给APP端使用|
|attributes|Obj|设备属性定义,不同设备内容也不同|
|states|Obj|设备当前状态|
|traits|Obj|设备支持的状态|
|room|Obj|设备所属的房间{id:, name:, floor:, rank_id:}|
|roomHint|String|设备所属的房间 <room_name>_<floor>F|
|otherDeviceIds|List|其他设备ID编码,对应三方的设备ID|
|gatewayDeviceId|String|设备归属的网关ID|
|customData|String|其他设备信息,对应三方的其他字段,(可选)|
涂鸦设备ID
vdevo159784190519746
4834120498f4abfcc35a
萤石设备ID
E62784233
物联设备ID
25EFF70F004B1200
ME01122084D
SPS 设备ID = <三方编号> + <三方设备原有的ID>
- name
|字段|类型|说明|
|-|-|-|
|defaultName|List<String>|默认名称,即产品名称,用户侧不可更改|
|name|String|设备名称|
|nicknames|List<String>|设备昵称|
- deviceInfo
|字段|类型|说明|
|-|-|-|
|manufacturer|String|厂商名称|
|model|String|设备型号|
|hwVersion|String|设备硬件版本|
|swVersion|String|设备软件版本|
#### 设备操作日志集合
- /users/<user_id>/deviceOperationLogs/<_id>
|字段|类型|说明|
|-|-|-|
|id|String|日志id|
|time|int|timestamp时间戳|
|deviceId|String|用户操作设备对象的ID|
|operation|String|用户操作的类型,arm/disarm/switch_open/switch_close/switch_delay_open/switch_delay_close/normal_warn/fire_warn/cancel_warn|
|extraData|String|用户操作设备对象的ID|
#### 设备历史状态数据
只维持最近7天的数据
- /users/<user_id>/deviceHistoryDatas/<_id>
|字段|类型|说明|
|-|-|-|
|id|String|数据id|
|time|int|timestamp时间戳|
|deviceId|String|设备ID|
|states|Object|设备状态数据|
#### 设备历史告警数据
只维持最近7天的数据
- /users/<user_id>/deviceHistoryAlarms/<_id>
|字段|类型|说明|
|-|-|-|
|id|String|数据id|
|time|int|timestamp时间戳|
|deviceId|String|设备ID|
|event|String|告警事件|
告警事件:
- online
- offline
- arm (设备切换到设防状态)
- disarm (设备切换到撤防状态)
- detect_open (门窗磁感应器 检测到被打开)
- detect_close(门窗磁感应器 检测到被关闭)
- detect_pass (PIR检测器 检测到有人)
- detect_pass_cancel (PIR检测器 检测到有人 取消告警)
- detect_gas (GAS检测器 检测有易燃气体)
- detect_water_leak (水漏检测器 检测漏水)
- detect_water_leak_cancel (水漏检测器 检测漏水 取消告警)
#### 3. 场景集合 | scenes
/users/<user_id>/scenes/<scene_id>
|字段|类型|说明|
|-|-|-|
|name|String|场景的名称|
|icon|String|场景的图标地址|
|enable|boolean|是否启用场景,manual场景默认启动|
|effectPeriod|list|场景生效时段,列表第一个表示开始时刻,第二个表示结束时刻|
|type|int|场景类型,0 表示manualy,1 表示auto|
|schedule|list|场景的review schedule,{'minute':, 'hour':, 'date':, 'month':, 'week':}|
|conditions|Object|场景的条件,manualy场景,该字段为Null|
|actions|list|场景的执行任务|
```
effectPeriod: [{'hour':9,'minute':0}, {'hour':15,'minute':0}]
```
```
conditions: {
'rule_op': 'AND/OR',
'rules': [
{
"type": "scene.rules.types.DEVICE",
"data": {
"device_id": <device_id-pir-detector-1>,
"state_event": {
"name": "human pass detected",
"condition": [
{
"field_name": "states.currentSensorStateData.humanPassDetectState",
"logic_op": "$eq",
"op_value": "human_pass_detected"
}
],
"parameters": None,
"description": "human pass detected",
"subscribe_state": "states.currentSensorStateData.humanPassDetectState",
"has_state_delay_update": False
}
}
},
{
"type": "scene.rules.types.DEVICE",
"data": {
"device_id": <device_id-pir-detector-1>,
"state_event": {
"name": "no human pass detected for 5 minutes",
"condition": {
"states.currentSensorStateData.humanPassDetectState": {"$eq": "no_human_pass_detected"},
"statesUpdateTime.currentSensorStateData.humanPassDetectState": {"$keep_period": {"$parameters": "keep_period"}}
},
"subscribeState": "states.currentSensorStateData.humanPassDetectState",
"delayStateUpdate": True/False
"parameters": [{"name": "keep_period", "type": "int", "value": 5}],
"description": "no human pass detected for 5 minutes",
}
}
},
{
"type": "scene.rules.types.WEATHER", # 天气条件,只能基于房子所在地的天气状态数据
"data": {
"house_id": <house_id>
"location": {latitude, longtitude, name,}, # e.g. Sydney,AU
"state_event": {
"name": "temperature great than defined value",
"condition": {"main.temp": {"$gt": {"$parameters": "temperature"}}},
"parameters": [{"name": "temperature", "type": "int", "value": 27}],
"description": "temperature great than defined value",
}
}
},
{
"type": "scene.rules.types.LOCATION",
"data": {
"user_id": "<user_id>", # 可以监控其他人的location,必须其他人授权
"state_event": {
"name": "user arrive at defined location range",
"condition": {"currentLocation": {"$arrive": [{"$parameters": "latitude"},{"$parameters": "longtitude"},{"$parameters": "radius"}]}},
"parameters": [
{"name": "latitude", "type": "int", "value": 27},
{"name": "longtitude", "type": "int", "value": 27},
{"name": "radius", "type": "int", "value": 50},
],
"description": "user arrive at defined location range",
}
}
},
{
"type": "scene.rules.types.LOCATION",
"data": {
"user_id": "<user_id>", # 可以监控其他家庭成员的location,必须其他人授权
"state_event": {
"name": "user leave away defined location range",
"condition": {"currentLocation": {"$leave": [{"$parameters": "latitude"},{"$parameters": "longtitude"},{"$parameters": "radius"}]}},
"parameters": [
{"name": "latitude", "type": "int", "value": 27},
{"name": "longtitude", "type": "int", "value": 27},
{"name": "radius", "type": "int", "value": 50},
],
"description": "user leave away defined location range",
}
}
},
# TIMER类型的condition,sps_core直接读取parameters
# 当 该场景被创建/更新的时候,提取TIMER类型 condition的parameters, 然后创建相应的cloud schedule job, 并记录该cloud schedule job id到该场景的condition
{
"type": "scene.rules.types.TIMER",
"data": {
"city_id": "<city_id>", # 表示当地的时区, 不需要,后台自己根据house
"state_event": {
"name": "time schedule",
"condition": None,
"parameters": [
{"name": "repeat", "type": "list", "value": [1,2,3,4,5,6,7]},
{"name": "time", "type": "time", "value": {"hour":, "minute":}}, # time类型的参数,
],
"description": "time schedule",
}
}
},
]
}
```
- 默认逻辑操作符 是 OR
- 当用户开始添加第二条 condition时,提示用户选择 逻辑操作符 AND(when all condition met) 还是 OR (when any condition met)
- 如果conditions中,带有多个 TIMER类型的condition,则逻辑操作符,只能是OR
```
# 关于 场景的 actions
(1) 执行设备指令
(2) 发送通知 (一个场景只能添加一个发送通知)
(3) 执行某个 manual 场景 (当场景是 manual场景时,该选项不可选,只有当场景是auto的时候可以)
(4) 启用/禁用 某个 auto场景 ()
actions: [
{
"type": "scene.actions.types.EXECUTE_DEVICE", EXECUTE_SCENE, ENABLE_DISABLE_SCENE, SEND_NOTIFICATION,
"data": {
devices: [device_id],
executions: [{
command: 'action.devices.commands.ArmDisarm',
challenge: {pin: '123455'}, # option
params: {
"isArmed": True
}
}]
}
},
{
"type": "scene.actions.types.EXECUTE_SCENE", EXECUTE_SCENE, ENABLE_DISABLE_SCENE, SEND_NOTIFICATION,
"data": {
scenes: [scene_id],
}
},
{
"type": "scene.actions.types.ENABLE_DISABLE_SCENE", EXECUTE_SCENE, ENABLE_DISABLE_SCENE, SEND_NOTIFICATION,
"data": {
scenes: [scene_id],
enable: True/False
}
},
{
"type": "scene.actions.types.SEND_NOTIFICATION", EXECUTE_SCENE, ENABLE_DISABLE_SCENE, SEND_NOTIFICATION,
"data": {
user_id: user_id
}
},
]
```
/event/weatherSub/<user_id>/<scene_id>
- condition
/event/device/<user_id>/<scene_id>
- condition
#### 4. 消息集合 | messages
- 系统消息,比如更新通知等
- 设备告警,比如安防检测类设备的告警触发/消除
- 场景通知,比如场景的执行动作 是给用户自己发送消息通知
/user/<user_id>/messages/<message_id>
- object: 消息主题
- time: 消息产生的10位时间戳
- type, device_alarm/scene_notification/house_member_invitation
- content: 消息正文
- house_id,
- device_id,
- scene_id,
- is_read, 是否已读
- is_accepted, 是否接受,用于 房子邀请类型消息
/user/<user_id>/messages_setting
- enable_notification
- donotdisturb_devices: [], 免打扰设备列表
- donotdisturb_time: [{hour:, minute:}, {hour:, minute:}]
- enable_device_alarms:
- enable_scene_notification:
- enable_system_notification:
/system_messages/<message_id>
- object:
- time:
- message:
- is_read:
#### 5. 家庭集合 | houses
/users/<user_id>/houses/<house_id>
- name
- location
- members: [user_id_1, user_id_2,...]
- rooms: collections
- devices: collections
- room: {id:, name:, floor:, rank_id}
/users/<user_id>/houses/<house_id>/rooms/<room_id>
- name
- rank_id: 排序用
- floor: 新建房间时,必须给房间指定floor,内定可选项: [1, 2, 3] means Floor_1, Floor_2, Floor_3,...
- devices, list, devices_id
>w 楼层作为房间的一个属性,int,类型。
新建的设备,如果没有选择房间,默认归属house, 设备的room字段为null
>w APP侧:
a. 全局维护一个devices_list,并监听整个devices_list
b. 当用户修改 room名称时,后台自动根据该room的devices列表,更新相应的devices的room_name,前端APP自动更新
c. 当用户 从设备详情页 修改 设备归属的房间时,后台自动根据room_id,更新相应的room document的devices列表,先从旧的room的device列表删除,再从新的room的device列表增加
更新事件:
ROOM 更新事件:只更新room doc,后台自动更新到相关的device doc
更新ROOM名称 / 排序ID / 归属FLOOR / 设备列表 —— 移除设备 / 更新ROOM 设备列表 —— 增加设备
DEVICE 归属ROOM更新事件,前端只是update device document, 后台自动更新到room document
#### 6. 问题集合 | issues
/users/<user_id>/issues/<issue_id>
- title
- content
- pictures
- email
- phone
- happen_time
- comments, collections
- is_close
/users/<user_id>/issues/<issue_id>/comments/<comment_id>
- content,回复内容
- pictures:相关的图片
- is_owner: 是否是用户自己的回复
- admin_id: 客服的ID,如果是客服回复的话
- time: 回复的时间
#### 7. 系统, realtime database
- about:
- company_introduction
- company_website
- company_logo
- business_email
- support_email
- support_phone
- user_protocol
- privacy_protocol
- open_sources_permission
- software_version
- launch_slide, image_url_list
- first_launch_introduction, image_url_list
#### admin
#### project
####
#### Google Action
Execution格式:
- challenge
- pin
- command: 即traits
- params