using System;
using System.Collections.Generic;
using System.Text;
using Shared.Common;
using ZigBee.Device;
namespace Shared.Phone.UserCenter
{
///
/// App体验账号的逻辑
///
public class HdlExperienceAccountLogic
{
#region ■ 变量声明___________________________
///
/// App体验账号的逻辑
///
private static HdlExperienceAccountLogic m_Current = null;
///
/// App体验账号的逻辑
///
public static HdlExperienceAccountLogic Current
{
get
{
if (m_Current == null)
{
m_Current = new HdlExperienceAccountLogic();
}
return m_Current;
}
}
///
/// 用来递增生成Mac用的
///
private int DeviceNumber = 0;
#endregion
#region ■ 初始化_____________________________
///
/// 初始化全部体验数据
///
public void InitAllExperienceData()
{
//初始化用户
this.InitUserInfoData();
//初始化住宅
this.InitHomeData();
//初始化楼层
this.InitFloorData();
//初始化房间
this.InitRoomData();
//初始化设备
this.InitDeviceData();
//初始化场景
this.InitSceneData();
//刷新左边刷新房间视图列表
HdlRoomLogic.Current.RefreshRoomListView();
}
#endregion
#region ■ 初始化用户_________________________
///
/// 初始化用户
///
private void InitUserInfoData()
{
UserCenterResourse.UserInfo = new UserInformation();
UserCenterResourse.UserInfo.AuthorityNo = 1;//给他管理员称号
UserCenterResourse.UserInfo.AuthorityText = Language.StringByID(R.MyInternationalizationString.Administrator);
//虚拟账号
UserCenterResourse.UserInfo.UserName = Language.StringByID(R.MyInternationalizationString.uVirtualAccount);
}
#endregion
#region ■ 初始化住宅_________________________
///
/// 初始化住宅
///
private void InitHomeData()
{
//初始化住宅ID
string homeId = "abcdefghijklmn";
//初始Guid
Config.Instance.Guid = "chushiGuid";
var path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, homeId);
if (System.IO.Directory.Exists(path) == true)
{
//再次启动的时候,重新开始
System.IO.Directory.Delete(path, true);
}
System.IO.Directory.CreateDirectory(path);
//注意,这里不清空当前住宅列表,保留它之前的住宅列表
//创建临时住宅
var house = new House() { Id = homeId, Name = Language.StringByID(R.MyInternationalizationString.uMyHome) };
house.IsVirtually = true;
house.Save(false);
Config.Instance.HomeId = house.Id;
Config.Instance.Home = HdlResidenceLogic.Current.GetHouseByHouseId(house.Id);
//预创建个人中心全部的文件夹
UserCenterLogic.CreatAllUserCenterDirectory();
}
#endregion
#region ■ 初始化楼层_________________________
///
/// 初始化楼层
///
private void InitFloorData()
{
Config.Instance.Home.FloorDics = new Dictionary();
//Config.Instance.Home.FloorDics["floorKey1"] = "1F";
//Config.Instance.Home.FloorDics["floorKey2"] = "2F";
//Config.Instance.Home.FloorDics["floorKey3"] = "3F";
//Config.Instance.Home.FloorDics["floorKey4"] = "4F";
//Config.Instance.Home.FloorDics["floorKey5"] = "5F";
}
#endregion
#region ■ 初始化房间_________________________
///
/// 获取房间样板列表
///
///
private Dictionary GetRoomSampleList()
{
var dicRoomName = new Dictionary();
//客厅
dicRoomName["KeTing"] = Language.StringByID(R.MyInternationalizationString.uLivingRoom);
//阳台
dicRoomName["YangTai"] = Language.StringByID(R.MyInternationalizationString.uBalcony);
//卧室
dicRoomName["WoShi"] = Language.StringByID(R.MyInternationalizationString.uBedroom);
//玄关
dicRoomName["XuanGuan"] = Language.StringByID(R.MyInternationalizationString.uVestibule);
//厨房
dicRoomName["ChuFang"] = Language.StringByID(R.MyInternationalizationString.uKitchen);
//走廊
dicRoomName["ZouLang"] = Language.StringByID(R.MyInternationalizationString.uCorridor);
return dicRoomName;
}
///
/// 初始化房间
///
private void InitRoomData()
{
//先刷新容器
HdlRoomLogic.Current.InitAllRoom();
//获取全部的楼层主键
var listFloorKey = this.GetAllFloorKeys();
var dicRoomName = this.GetRoomSampleList();
//设置初始楼层
Config.Instance.Home.CurrentFloorId = listFloorKey[0];
foreach (string floorKey in listFloorKey)
{
foreach (string roomId in dicRoomName.Keys)
{
//创建新房间
var newRoom = new Room();
newRoom.Id = floorKey + "_" + roomId;
newRoom.Name = dicRoomName[roomId];
newRoom.BackgroundImage = "RoomIcon/0.jpg";
newRoom.FloorId = floorKey;
HdlRoomLogic.Current.AddRoom(newRoom, false);
}
}
}
///
/// 获取全部的楼层主键
///
///
private List GetAllFloorKeys()
{
var listKey = new List();
foreach (var strKey in Config.Instance.Home.FloorDics.Keys)
{
listKey.Add(strKey);
}
if (listKey.Count == 0)
{
listKey.Add("");
}
return listKey;
}
#endregion
#region ■ 初始化设备_________________________
///
/// 设置需要创建的虚拟设备列表
///
///
private List GetVirtualDeviceList()
{
//floorKey1 _ KeTing YangTai WoShi XuanGuan ChuFang ZouLang
var list = new List();
//获取全部的楼层主键
var listFloorKey = this.GetAllFloorKeys();
foreach (var floorKey in listFloorKey)
{
//客厅
list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A2按键面板, RoomId = floorKey + "_KeTing", DeviceCount = 1 });
list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A3按键面板, RoomId = floorKey + "_KeTing", DeviceCount = 1 });
list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A4按键面板, RoomId = floorKey + "_KeTing", DeviceCount = 2 });
list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A空调网关, RoomId = floorKey + "_KeTing", DeviceCount = 1 });
//阳台
list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A220pir传感器, RoomId = floorKey + "_YangTai", DeviceCount = 1 });
list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A卷帘电机, RoomId = floorKey + "_YangTai", DeviceCount = 1 });
list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A开合帘电机, RoomId = floorKey + "_YangTai", DeviceCount = 1 });
list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A2按键面板, RoomId = floorKey + "_YangTai", DeviceCount = 1 });
//卧室
list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A1路调光器, RoomId = floorKey + "_WoShi", DeviceCount = 1 });
list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A3路继电器, RoomId = floorKey + "_WoShi", DeviceCount = 1 });
//玄关
list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A空气开关, RoomId = floorKey + "_XuanGuan", DeviceCount = 1 });
list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A1路调光器, RoomId = floorKey + "_XuanGuan", DeviceCount = 1 });
list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A门窗磁传感器, RoomId = floorKey + "_XuanGuan", DeviceCount = 1 });
//厨房
list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A4按键面板, RoomId = floorKey + "_ChuFang", DeviceCount = 1 });
list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A水浸传感器, RoomId = floorKey + "_ChuFang", DeviceCount = 1 });
list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A烟雾传感器, RoomId = floorKey + "_ChuFang", DeviceCount = 1 });
list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A燃气传感器, RoomId = floorKey + "_ChuFang", DeviceCount = 1 });
list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A吸顶燃气传感器, RoomId = floorKey + "_ChuFang", DeviceCount = 1 });
//走廊
list.Add(new AddDevicePra { DeviceType = VirtualDeviceEnum.A4按键面板, RoomId = floorKey + "_ZouLang", DeviceCount = 1 });
}
return list;
}
///
/// 初始化设备
///
private void InitDeviceData()
{
//先刷新容器
LocalDevice.Current.ReFreshByLocal();
//顺便也整一下网关(有可能它是从实体账号转为虚拟时,没有清空)
HdlGatewayLogic.Current.ReFreshByLocal();
HdlGatewayLogic.Current.RefreshAppOldSelectGatewayId();
Type thisType = m_Current.GetType();
//获取需要创建的虚拟设备列表
var list = this.GetVirtualDeviceList();
foreach (var data in list)
{
string methordName = "Zigbee" + data.DeviceType.ToString().Substring(1);
//反射指定的函数
var myMethod = thisType.GetMethod(methordName);
myMethod.Invoke(this, new object[] { data.DeviceCount, data.RoomId });
}
}
#endregion
#region ■ 初始化场景_________________________
///
/// 初始化场景
///
private void InitSceneData()
{
//刷新容器
HdlSceneLogic.Current.ReFreshByLocal();
//获取全部的楼层主键
var listFloorKey = this.GetAllFloorKeys();
//获取全部的房间模板列表
var dicRoom = this.GetRoomSampleList();
//floorKey1 _ KeTing YangTai WoShi XuanGuan ChuFang ZouLang
int sceneIdNo = 1;
//对每一个楼层
foreach (var floorKey in listFloorKey)
{
//对每一个房间
foreach (var strKey in dicRoom.Keys)
{
var room = HdlRoomLogic.Current.GetRoomById(floorKey + "_" + strKey);
if (room == null)
{
continue;
}
//灯全开
var listAdjust1 = this.InitVirtualSceneAdjustList(room, 1);
var sceneName = Language.StringByID(R.MyInternationalizationString.uAllLightOpen);
var scene = HdlSceneLogic.Current.AddVirtualScene(sceneIdNo, sceneName, listAdjust1);
sceneIdNo++;
HdlSceneLogic.Current.AddSceneToRoom(room, scene);
//灯全关
var listAdjust2 = this.InitVirtualSceneAdjustList(room, 0);
var sceneName2 = Language.StringByID(R.MyInternationalizationString.uAllLightClose);
var scene2 = HdlSceneLogic.Current.AddVirtualScene(sceneIdNo, sceneName2, listAdjust2);
sceneIdNo++;
HdlSceneLogic.Current.AddSceneToRoom(room, scene2);
}
}
}
///
/// 初始化虚拟场景的执行目标(statu 0:关 1:开)
///
///
///
///
private List InitVirtualSceneAdjustList(Room i_room, int statu)
{
var listBind = new List();
foreach (var mainKey in i_room.ListDevice)
{
var device = LocalDevice.Current.GetDevice(mainKey);
if (device == null) { continue; }
//只要继电器和灯
if (device.Type == DeviceType.OnOffOutput
|| device.Type == DeviceType.DimmableLight)
{
var data = new Scene.DeviceListData();
data.Type = 0;
data.DeviceAddr = device.DeviceAddr;
data.Epoint = device.DeviceEpoint;
data.TaskList.Add(new Safeguard.TaskListInfo() { TaskType = 1, Data1 = statu });
listBind.Add(data);
}
}
return listBind;
}
#endregion
#region ■ 创建虚拟设备列表___________________
public void Zigbee开合帘电机(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
var device = new Rollershade() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
device.WcdType = 4;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 100, 100, "MWM65B-ZB.20", i_RoomId);
this.DeviceNumber++;
}
}
public void Zigbee卷帘电机(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
var device = new Rollershade() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
device.WcdType = 0;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 101, 101, "MVSM35B-ZB.20", i_RoomId);
this.DeviceNumber++;
}
}
public void Zigbee4按键面板(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
//4个干接点
for (int j = 1; j <= 4; j++)
{
var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
//设置设备的基本信息
this.SetBaseDataToDevice(device, 200, 200, "MPT4/R4-ZB.18", i_RoomId);
}
//4个继电器
for (int j = 5; j <= 8; j++)
{
var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
device.DfunctionType = DeviceFunctionType.A灯光;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 200, 200, "MPT4/R4-ZB.18", i_RoomId);
device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + (j - 4);
}
//1温度探头
var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 9 };
device2.SensorDiv = 1;
//设置设备的基本信息
this.SetBaseDataToDevice(device2, 200, 200, "MPT4/R4-ZB.18", i_RoomId);
this.DeviceNumber++;
}
}
public void Zigbee3按键面板(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
//3个干接点
for (int j = 1; j <= 3; j++)
{
var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
//设置设备的基本信息
this.SetBaseDataToDevice(device, 201, 201, "MPT3/R3-ZB.18", i_RoomId);
}
//3个继电器
for (int j = 4; j <= 6; j++)
{
var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
device.DfunctionType = DeviceFunctionType.A灯光;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 201, 201, "MPT3/R3-ZB.18", i_RoomId);
device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + (j - 3);
}
//1温度探头
var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 7 };
device2.SensorDiv = 1;
//设置设备的基本信息
this.SetBaseDataToDevice(device2, 201, 201, "MPT3/R3-ZB.18", i_RoomId);
this.DeviceNumber++;
}
}
public void Zigbee2按键面板(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
//2个干接点
for (int j = 1; j <= 2; j++)
{
var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
//设置设备的基本信息
this.SetBaseDataToDevice(device, 202, 202, "MPT2/R2-ZB.18", i_RoomId);
}
//2个继电器
for (int j = 3; j <= 4; j++)
{
var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
device.DfunctionType = DeviceFunctionType.A灯光;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 202, 202, "MPT2/R2-ZB.18", i_RoomId);
device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + (j - 2);
}
//1温度探头
var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 5 };
device2.SensorDiv = 1;
//设置设备的基本信息
this.SetBaseDataToDevice(device2, 202, 202, "MPT2/R2-ZB.18", i_RoomId);
this.DeviceNumber++;
}
}
public void Zigbee简约4按键面板(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
//4个干接点
for (int j = 1; j <= 4; j++)
{
var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
//设置设备的基本信息
this.SetBaseDataToDevice(device, 220, 220, "MPT4R4L/S-ZB.18", i_RoomId);
}
//4个继电器
for (int j = 5; j <= 8; j++)
{
var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
device.DfunctionType = DeviceFunctionType.A灯光;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 220, 220, "MPT4R4L/S-ZB.18", i_RoomId);
device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + (j - 4);
}
//1温度探头
var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 9 };
device2.SensorDiv = 1;
//设置设备的基本信息
this.SetBaseDataToDevice(device2, 220, 220, "MPT4R4L/S-ZB.18", i_RoomId);
this.DeviceNumber++;
}
}
public void Zigbee简约3按键面板(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
//3个干接点
for (int j = 1; j <= 3; j++)
{
var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
//设置设备的基本信息
this.SetBaseDataToDevice(device, 221, 221, "MPT3R3L/S-ZB.18", i_RoomId);
}
//3个继电器
for (int j = 4; j <= 6; j++)
{
var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
device.DfunctionType = DeviceFunctionType.A灯光;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 221, 221, "MPT3R3L/S-ZB.18", i_RoomId);
device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + (j - 3);
}
//1温度探头
var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 7 };
device2.SensorDiv = 1;
//设置设备的基本信息
this.SetBaseDataToDevice(device2, 221, 221, "MPT3R3L/S-ZB.18", i_RoomId);
this.DeviceNumber++;
}
}
public void Zigbee简约2按键面板(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
//2个干接点
for (int j = 1; j <= 2; j++)
{
var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
//设置设备的基本信息
this.SetBaseDataToDevice(device, 222, 222, "MPT2R2L/S-ZB.18", i_RoomId);
}
//2个继电器
for (int j = 3; j <= 4; j++)
{
var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
device.DfunctionType = DeviceFunctionType.A灯光;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 222, 222, "MPT2R2L/S-ZB.18", i_RoomId);
device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + (j - 2);
}
//1温度探头
var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 5 };
device2.SensorDiv = 1;
//设置设备的基本信息
this.SetBaseDataToDevice(device2, 222, 222, "MPT2R2L/S-ZB.18", i_RoomId);
this.DeviceNumber++;
}
}
public void Zigbee220pir传感器(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
//1个传感器
var device = new IASZone() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
device.IasDeviceType = 13;
device.DeviceID = 1026;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 1200, 1200, "MSPIR01-ZB.10", i_RoomId);
//1个继电器
var device2 = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 2 };
device2.DfunctionType = DeviceFunctionType.A灯光;
//设置设备的基本信息
this.SetBaseDataToDevice(device2, 1200, 1200, "MSPIR01-ZB.10", i_RoomId);
device2.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + 1;
this.DeviceNumber++;
}
}
public void Zigbee燃气传感器(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
var device = new IASZone() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
device.IasDeviceType = 43;
device.DeviceID = 1026;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 1300, 1300, "MSG01/M-ZB.10", i_RoomId);
this.DeviceNumber++;
}
}
public void Zigbee吸顶燃气传感器(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
var device = new IASZone() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
device.IasDeviceType = 43;
device.DeviceID = 1026;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 1300, 1300, "MGCD01/ZB.10", i_RoomId);
this.DeviceNumber++;
}
}
public void Zigbee门窗磁传感器(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
var device = new IASZone() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
device.IasDeviceType = 21;
device.DeviceID = 1026;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 1301, 1301, "MSDC01/M-ZB.10", i_RoomId);
this.DeviceNumber++;
}
}
public void Zigbee烟雾传感器(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
var device = new IASZone() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
device.IasDeviceType = 40;
device.DeviceID = 1026;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 1301, 1301, "MSS01/M-ZB.10", i_RoomId);
this.DeviceNumber++;
}
}
public void Zigbee红外传感器(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
var device = new IASZone() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
device.IasDeviceType = 13;
device.DeviceID = 1026;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 1303, 1303, "MSPIR01/M-ZB.10", i_RoomId);
this.DeviceNumber++;
}
}
public void Zigbee水浸传感器(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
var device = new IASZone() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
device.IasDeviceType = 42;
device.DeviceID = 1026;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 1304, 1304, "MSW01/M-ZB.10", i_RoomId);
this.DeviceNumber++;
}
}
public void Zigbee紧急按键(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
var device = new IASZone() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
device.IasDeviceType = 44;
device.DeviceID = 1026;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 1305, 1305, "MBU01/M-ZB.10", i_RoomId);
this.DeviceNumber++;
}
}
public void Zigbee3路继电器(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
//3个继电器
for (int j = 1; j <= 3; j++)
{
var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
device.DfunctionType = DeviceFunctionType.A灯光;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 2300, 2300, "MPR0310-ZB.10", i_RoomId);
device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + j;
}
//7个干接点
for (int j = 4; j <= 10; j++)
{
var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
//设置设备的基本信息
this.SetBaseDataToDevice(device, 2300, 2300, "MPR0310-ZB.10", i_RoomId);
}
this.DeviceNumber++;
}
}
public void Zigbee1路调光器(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
//7个干接点
for (int j = 1; j <= 7; j++)
{
var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
//设置设备的基本信息
this.SetBaseDataToDevice(device, 2300, 2300, "MPD0101-ZB.10", i_RoomId);
}
//1个调光器
var device2 = new DimmableLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 8 };
device2.DfunctionType = DeviceFunctionType.A灯光;
//设置设备的基本信息
this.SetBaseDataToDevice(device2, 2300, 2300, "MPD0101-ZB.10", i_RoomId);
device2.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + 1;
this.DeviceNumber++;
}
}
public void Zigbee空调网关(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
//10个空调应该可以了
for (int j = 1; j <= 10; j++)
{
var device = new AC() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
//室温默认26℃
device.currentLocalTemperature = 26;
device.currentCoolingSetpoint = 26;
device.currentHeatingSetpoint = 26;
device.currentAutoSetpoint = 26;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 3600, 3600, "MAC/GW-ZB.10", i_RoomId);
}
this.DeviceNumber++;
}
}
public void Zigbee空气开关(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
var device = new AirSwitch() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
//设置设备的基本信息
this.SetBaseDataToDevice(device, 4100, 4100, "MBCI01-ZB.10", i_RoomId);
device.DfunctionType = DeviceFunctionType.A开关;
this.DeviceNumber++;
}
}
public void Zigbee智能门锁(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
var device = new ZigBee.Device.DoorLock() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
//设置设备的基本信息
this.SetBaseDataToDevice(device, 2800, 2800, "S-one", i_RoomId);
device.DfunctionType = DeviceFunctionType.A开关;
this.DeviceNumber++;
}
}
public void Zigbee方悦单开双控面板(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
//2个干接点
for (int j = 1; j <= 2; j++)
{
var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
//设置设备的基本信息
this.SetBaseDataToDevice(device, 240, 240, "MP2B/TILE-ZB.18", i_RoomId);
}
//1个继电器
for (int j = 3; j <= 3; j++)
{
var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
device.DfunctionType = DeviceFunctionType.A灯光;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 240, 240, "MP2B/TILE-ZB.18", i_RoomId);
device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + (j - 2);
}
//1温度探头
var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 4 };
device2.SensorDiv = 1;
//设置设备的基本信息
this.SetBaseDataToDevice(device2, 240, 240, "MP2B/TILE-ZB.18", i_RoomId);
this.DeviceNumber++;
}
}
public void Zigbee方悦双开四控面板(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
//4个干接点
for (int j = 1; j <= 4; j++)
{
var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
//设置设备的基本信息
this.SetBaseDataToDevice(device, 241, 241, "MP4B/TILE-ZB.18", i_RoomId);
}
//2个继电器
for (int j = 5; j <= 6; j++)
{
var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
device.DfunctionType = DeviceFunctionType.A灯光;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 241, 241, "MP4B/TILE-ZB.18", i_RoomId);
device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + (j - 4);
}
//1温度探头
var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 7 };
device2.SensorDiv = 1;
//设置设备的基本信息
this.SetBaseDataToDevice(device2, 241, 241, "MP4B/TILE-ZB.18", i_RoomId);
this.DeviceNumber++;
}
}
public void Zigbee方悦四开八控面板(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
//8个干接点
for (int j = 1; j <= 8; j++)
{
var device = new Panel() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
//设置设备的基本信息
this.SetBaseDataToDevice(device, 242, 242, "MP8B/TILE-ZB.18", i_RoomId);
}
//4个继电器
for (int j = 9; j <= 12; j++)
{
var device = new ToggleLight() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = j };
device.DfunctionType = DeviceFunctionType.A灯光;
//设置设备的基本信息
this.SetBaseDataToDevice(device, 242, 242, "MP8B/TILE-ZB.18", i_RoomId);
device.DeviceEpointName = Language.StringByID(R.MyInternationalizationString.uLight) + (j - 8);
}
//1温度探头
var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 13 };
device2.SensorDiv = 1;
//设置设备的基本信息
this.SetBaseDataToDevice(device2, 242, 242, "MP8B/TILE-ZB.18", i_RoomId);
this.DeviceNumber++;
}
}
public void Zigbee方悦新风面板(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
//1新风
var device = new FreshAir() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
//设置设备的基本信息
this.SetBaseDataToDevice(device, 250, 250, "MPFA/TILE-ZB.18", i_RoomId);
//1温度探头
var device2 = new TemperatureSensor() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 2 };
device2.SensorDiv = 1;
//设置设备的基本信息
this.SetBaseDataToDevice(device2, 250, 250, "MPFA/TILE-ZB.18", i_RoomId);
this.DeviceNumber++;
}
}
public void Zigbee方悦新风小模块(int i_DeviceCount, string i_RoomId)
{
for (int i = 0; i < i_DeviceCount; i++)
{
//1新风
var device = new FreshAir() { DeviceAddr = "DeviceAddr" + this.DeviceNumber, DeviceEpoint = 1 };
//设置设备的基本信息
this.SetBaseDataToDevice(device, 2310, 2310, "MFA01-ZB.10", i_RoomId);
this.DeviceNumber++;
}
}
///
/// 设置设备的基本信息
///
///
private void SetBaseDataToDevice(CommonDevice device, int HwVersion, int ImgTypeId,
string ModelIdentifier, string roomId)
{
device.DeviceEpointName = string.Empty;
device.HadReadDeviceStatu = true;
device.DeviceName = string.Empty;
device.IsOnline = 1;
device.HwVersion = HwVersion;
device.ImgTypeId = ImgTypeId;
device.DriveCode = 0;
device.ManufacturerName = "HDL";
device.ModelIdentifier = ModelIdentifier;
device.CurrentGateWayId = string.Empty;
//默认每个设备都可以定位,拥有开关功能
device.InClusterList.Add(new CommonDevice.InClusterObj { InCluster = 3 });
device.OutClusterList.Add(new CommonDevice.OutClusterObj { OutCluster = 3 });
if (device.Type == DeviceType.AirSwitch || device.Type == DeviceType.OnOffOutput
|| device.Type == DeviceType.DimmableLight || device.Type == DeviceType.ColorDimmableLight)
{
device.InClusterList.Add(new CommonDevice.InClusterObj { InCluster = 6 });
device.OutClusterList.Add(new CommonDevice.OutClusterObj { OutCluster = 6 });
}
if (device.Type == DeviceType.OnOffOutput || device.Type == DeviceType.DimmableLight
|| device.Type == DeviceType.ColorDimmableLight)
{
device.InClusterList.Add(new CommonDevice.InClusterObj { InCluster = 8 });
}
if (device.Type == DeviceType.WindowCoveringDevice)
{
device.InClusterList.Add(new CommonDevice.InClusterObj { InCluster = 258 });
}
//添加虚拟设备
LocalDevice.Current.AddVirtualDeviceToMemory(device);
var room = HdlRoomLogic.Current.GetRoomById(roomId);
if (room != null)
{
//添加房间
HdlRoomLogic.Current.AddDevice(room, device, true);
}
}
#endregion
#region ■ 设备枚举___________________________
///
/// 虚拟设备枚举
///
private enum VirtualDeviceEnum
{
A开合帘电机 = 1,
A卷帘电机 = 2,
A4按键面板 = 3,
A3按键面板 = 4,
A2按键面板 = 5,
A简约4按键面板 = 7,
A简约3按键面板 = 8,
A简约2按键面板 = 9,
A220pir传感器 = 10,
A燃气传感器 = 11,
A门窗磁传感器 = 12,
A烟雾传感器 = 13,
A红外传感器 = 14,
A水浸传感器 = 15,
A紧急按键 = 16,
A3路继电器 = 17,
A1路调光器 = 18,
A空调网关 = 19,
A空气开关 = 20,
A智能门锁 = 21,
A方悦单开双控面板 = 22,
A方悦双开四控面板 = 23,
A方悦四开八控面板 = 24,
A方悦新风面板 = 25,
A方悦新风小模块 = 26,
A吸顶燃气传感器 = 27,
}
#endregion
#region ■ 结构体_____________________________
///
/// 添加设备的参数
///
private class AddDevicePra
{
///
/// 设备类型
///
public VirtualDeviceEnum DeviceType = VirtualDeviceEnum.A空气开关;
///
/// 添加的设备个数(不是回路数)
///
public int DeviceCount = 1;
///
/// 将设备添加到的房间(不设置表示不添加到房间)
///
public string RoomId = string.Empty;
}
#endregion
}
}