# 家庭房间

## home.getFamily({lang})

功能：获取家庭和房间列表

参数类型：Object

参数内容：

| 名称   | 类型     | 允许为空 | 说明                        |
|:-----|:-------|:-----|:--------------------------|
| lang | String | Y    | cn 返回中文信息，en 返回英文信息，默认 en |

响应的 data 参数：

| 名称              | 类型     | 允许为空 | 说明      |
|:----------------|:-------|:-----|:--------|
| familyList      | Array  | N    | 家庭列表    |
| currentFamilyId | String | N    | 当前家庭 id |

familyList item 说明:

| 名称       | 类型     | 允许为空 | 说明           |
|:---------|:-------|:-----|:-------------|
| id       | String | N    | 家庭 id        |
| apikey   | String | N    | 用户 apikey    |
| name     | String | N    | 家庭名称         |
| index    | Int    | N    | 家庭排序号 可能存在负数 |
| roomList | Array  | Y    | 房间列表         |                                  

roomList item 说明:

| 名称     | 类型      | 允许为空 | 说明           |
|:-------|:--------|:-----|:-------------|
| id	    | String	 | N	   | 房间 id        |         
| name	  | String	 | N	   | 房间名称         |                            
| index	 | Int	    | N	   | 房间排序号 可能存在负数 |                

## home.addFamily({name,sort,roomNameList})

功能：新增家庭

参数类型：Object

参数内容：

| 名称           | 类型     | 允许为空 | 说明                           |
|:-------------|:-------|:-----|:-----------------------------|
| name         | String | N    | 家庭名称                         |
| sort         | Int    | N    | 给新家庭分配序号的方式 1=更小的序号 2=更大的序号  |
| roomNameList | Int    | Y    | 房间名称列表 服务端按列表顺序对新创建的房间生成对应序号 |

响应的 data 参数：

| 名称        | 类型            | 允许为空 | 说明                           |
|:----------|:--------------|:-----|:-----------------------------|
| id	       | String	       | N	   | 家庭 id                        |         
| name	     | String	       | N	   | 家庭名称                         |                            
| index	    | Int	          | N	   | 家庭排序号                        |     
| roomList	 | Array\<Object\> | Y	   | 房间列表，参见[home.getFamily]接口的说明 | 

## home.addRoom({familyId, name, index})

功能：新增房间

参数类型：Object

参数内容：

| 名称        | 类型      | 允许为空 | 说明                          |
|:----------|:--------|:-----|:----------------------------|
| familyId	 | String	 | N	   | 房间所属的家庭 id                  |         
| name	     | String	 | N	   | 房间名称                        |                            
| sort	     | Int	    | N	   | 给新房间分配序号的方式 1=更小的序号 2=更大的序号 |     

响应的 data 参数：

| 名称     | 类型      | 允许为空 | 说明    |
|:-------|:--------|:-----|:------|
| id	    | String	 | N	   | 房间 id |         
| name	  | String	 | N	   | 房间名称  |                            
| index	 | Int	    | N	   | 房间排序号 |  

## home.setFamily({id,newName})

功能：修改家庭信息

参数类型：Object

参数内容：

| 名称       | 类型      | 允许为空 | 说明               |
|:---------|:--------|:-----|:-----------------|
| id	      | String	 | Y	   | 家庭 id，不填则为修改当前家庭 |         
| newName	 | String	 | N	   | 新的家庭名称           |                            

响应的 data 参数：空对象

## home.setRoom({id,newName})

功能：修改房间信息

参数类型：Object

参数内容：

| 名称       | 类型      | 允许为空 | 说明     |
|:---------|:--------|:-----|:-------|
| id	      | String	 | N	   | 房间的 id |         
| newName	 | String	 | N	   | 新的房间名称 |    

响应的 data 参数：空对象

## home.sortRoom({familyId,idList})

功能：对房间做排序

说明：客户端必须将家庭下的所有房间上传，统一排序

参数类型：Object

参数内容：

| 名称       | 类型            | 允许为空 | 说明                                 |
|:---------|:--------------|:-----|:-----------------------------------|
| familyId | Array\<Object\> | Y    | 家庭 id，不填则为修改当前家庭                   |
| idList   | String        | N    | 房间的 id 列表，比如列表序号 0 的房间的 index 即为 0 |

响应的 data 参数：空对象

## home.delFamily({id,deviceFamily,switchFamily})

功能：删除家庭

参数类型：Object

参数内容：

| 名称            | 类型      | 允许为空 | 说明                         |
|:--------------|:--------|:-----|:---------------------------|
| id            | String  | N    | 家庭 id                      |
| deviceFamily	 | String	 | N	   | 表示把将要删除的家庭下的设备迁移到另一个家庭的 id |         
| switchFamily	 | String	 | N	   | 表示删除家庭后要切换到的家庭 id          |                            

响应的 data 参数：空对象

## home.delRoom({id})

功能：删除房间

参数内容：

| 名称 | 类型     | 允许为空 | 说明    |
|:---|:-------|:-----|:------|
| id | String | N    | 房间 id |

响应的 data 参数：空对象

## home.sortThing({familyId,thingList})

功能：对家庭下的 Thing 做排序

说明：客户端必须将家庭下的所有设备和群组上传，统一排序

参数类型：Object

参数内容：

| 名称         | 类型            | 允许为空 | 说明                           |
|:-----------|:--------------|:-----|:-----------------------------|
| familyId   | String        | Y    | 家庭 id，如果为空，表示对当前家庭下的设备/群组做排序 |
| thingList	 | Array\<Object\> | N	   | thing 列表                     |                                

thingList 列表 item 说明:

| 名称        | 类型      | 允许为空 | 说明                                   |
|:----------|:--------|:-----|:-------------------------------------|
| itemType	 | Int     | N    | item 的类型 1=用户自己的设备 2=别人分享的设备 3=自己的群组 |
| id	       | String	 | N	   | 设备 deviceid / 群组 id                  |                                

响应的 data 参数：空对象

## home.setThing({roomId,oldThingList,newThingList})

功能：设置房间的 Thing

说明：客户端将房间原有的 thing 列表和调整后的 thing 列表传入，服务端据此计算出要从房间删除的 thing，以及要添加到房间的 thing。客户端应保证 oldThingList 的正确性，如果有遗漏项，可能导致从房间删除失败；如果其中一项不属于 roomid 所属的房间，服务端返回错误。

参数类型：Object

参数内容：

| 名称            | 类型     | 允许为空 | 说明                            |
|:--------------|:-------|:-----|:------------------------------|
| roomId        | String | N    | 房间 id                         |
| oldThingList	 | Array	 | N	   | 原来房间的 thing 列表，如果为空，则传入空列表 [] |                                
| newThingList	 | Array	 | N	   | 调整后房间的 thing 列表               |

响应的 data 参数：空对象

## home.switchFamily({id})

功能：切换当前家庭

参数类型：Object

参数内容：

| 名称 | 类型     | 允许为空 | 说明    |
|:---|:-------|:-----|:------|
| id | String | N    | 家庭 id |

响应的 data 参数：空对象

