using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Shared.Common;
using Shared.Phone.UserCenter.Device;
using Shared.Phone.UserCenter.DeviceBind;
using ZigBee.Device;
using static ZigBee.Device.BindObj;
using static ZigBee.Device.Panel;
namespace Shared.Phone.UserCenter.Device.Bind
{
///
/// /只使用于简约多功能面板的方法
///
public class MutilfunctionPanelMethod
{
#region 变量申明
///
/// 开关的个数 [每次进入到多功能绑定界面,都要被重新取值]
///
public static int curSwitchCount = 0;
///
/// 插座的个数
///
public static int curSocketCount = 0;
///
/// 灯光个数 [从继电器中分配的功能类型是灯光]
///
public static int curLightFromRelayCount = 0;
///
/// 调光个数
///
public static int curLightCount = 0;
///
/// 多功能面板中被绑定的目标
///
public static System.Collections.Generic.Dictionary> bindTargetsFromMutilfunctionPanelList = new System.Collections.Generic.Dictionary>();
#endregion
///
/// 获取面板已经绑定的匹配类型的列表
/// 当前类型 0:场景 1:开关 2:插座 3:灯光 4:遮阳 5:空调 6:新风
///
///
public static List GetMatchBindList(int curBindType)
{
var tempList = new List();
int count1 = 0;
int count2 = 0;
foreach (var key in bindTargetsFromMutilfunctionPanelList.Keys)
{
var bList = bindTargetsFromMutilfunctionPanelList[key];
foreach (var bDev in bList)
{
if (curBindType == 0)
{
if (bDev.KeyEpoint >= 32 && bDev.KeyEpoint <= 51)
{
tempList.Add(bDev);
}
}
var device = LocalDevice.Current.GetDevice(bDev.BindMacAddr, bDev.BindEpoint);
if (device == null)
{
continue;
}
switch (curBindType)
{
case 1:
if (bDev.KeyEpoint >= 52 && bDev.KeyEpoint <= 61)
{
if (device != null)
{
if (device.DfunctionType == DeviceFunctionType.A开关)
{
tempList.Add(bDev);
}
}
}
curSwitchCount = tempList.Count;
break;
case 2:
if (bDev.KeyEpoint >= 52 && bDev.KeyEpoint <= 61)
{
if (device != null)
{
if (device.DfunctionType == DeviceFunctionType.A插座)
{
tempList.Add(bDev);
}
}
}
curSocketCount = tempList.Count;
break;
case 3:
if (bDev.KeyEpoint >= 52 && bDev.KeyEpoint <= 61)
{
if (device != null)
{
if (device.DfunctionType == DeviceFunctionType.A灯光)
{
tempList.Add(bDev);
count1++;
}
}
}
curLightFromRelayCount = count1;
if (bDev.KeyEpoint >= 22 && bDev.KeyEpoint <= 28)
{
if (device != null)
{
if (device.Type == DeviceType.DimmableLight && bDev.BindCluster == 8)
{
tempList.Add(bDev);
count2++;
}
}
}
curLightCount = count2;
break;
case 4:
if (bDev.KeyEpoint >= 14 && bDev.KeyEpoint <= 21 && bDev.BindCluster == 258)
{
tempList.Add(bDev);
}
break;
case 5:
if (bDev.KeyEpoint >= 2 && bDev.KeyEpoint <= 4)
{
if (device != null)
{
//空调绑定类型
if (device.Type == DeviceType.Thermostat && bDev.BindCluster == 513)
{
tempList.Add(bDev);
}
}
}
break;
case 6:
if (bDev.KeyEpoint == 13)
{
if (device != null)
{
if (device.Type == DeviceType.FreshAir && bDev.BindCluster == 514)
{
tempList.Add(bDev);
}
}
}
break;
}
}
}
return tempList;
}
///
/// 支持匹配的端点个数
/// 当前类型 0:场景 1:开关 2:插座 3:灯光 4:遮阳 5:空调 6:新风
///
///
private static List MatchEpointList(int curBindType)
{
var tempList = new List();
switch (curBindType)
{
case 0:
for (int i = 32; i < 52; i++)
{
tempList.Add(i);
}
break;
case 1:
case 2:
for (int i = 52; i < 62; i++)
{
tempList.Add(i);
}
break;
case 3:
//最大有10个继电器的灯光,7个调光
for (int i = 52; i < 62; i++)
{
tempList.Add(i);
}
for (int i = MutilfunctionPanelMethod.curLightCount + 22; i < 29; i++)
{
tempList.Add(i);
}
break;
case 4:
for (int i = 14; i < 22; i++)
{
tempList.Add(i);
}
break;
case 5:
for (int i = 2; i < 5; i++)
{
tempList.Add(i);
}
break;
case 6:
for (int i = 13; i < 14; i++)
{
tempList.Add(i);
}
break;
//5~12地热 簇 0x0201
}
return tempList;
}
///
/// 获取面板支持绑定的端点列表
/// 当前类型 0:场景 1:开关 2:插座 3:灯光 4:遮阳 5:空调 6:新风
///
///
public static List GetMatchEpointList(int curBindType)
{
var tempList = MatchEpointList(curBindType);
foreach (var key in bindTargetsFromMutilfunctionPanelList.Keys)
{
var bList = bindTargetsFromMutilfunctionPanelList[key];
foreach (var bDev in bList)
{
if (curBindType == 0)
{
if (bDev.KeyEpoint >= 32 && bDev.KeyEpoint <= 51)
{
tempList.Remove(bDev.KeyEpoint);
}
}
var device = LocalDevice.Current.GetDevice(bDev.BindMacAddr, bDev.BindEpoint);
if (device == null)
{
continue;
}
switch (curBindType)
{
case 1:
case 2:
if (bDev.KeyEpoint >= 52 && bDev.KeyEpoint <= 61)
{
if (device != null)
{
if (device.DfunctionType == DeviceFunctionType.A开关)
{
tempList.Remove(bDev.KeyEpoint);
}
if (device.DfunctionType == DeviceFunctionType.A插座)
{
tempList.Remove(bDev.KeyEpoint);
}
if (device.DfunctionType == DeviceFunctionType.A灯光)
{
tempList.Remove(bDev.KeyEpoint);
}
}
}
break;
case 3:
if (bDev.KeyEpoint >= 52 && bDev.KeyEpoint <= 61)
{
if (device != null)
{
if (device.DfunctionType == DeviceFunctionType.A开关)
{
tempList.Remove(bDev.KeyEpoint);
}
if (device.DfunctionType == DeviceFunctionType.A插座)
{
tempList.Remove(bDev.KeyEpoint);
}
if (device.DfunctionType == DeviceFunctionType.A灯光)
{
tempList.Remove(bDev.KeyEpoint);
}
}
}
if (bDev.KeyEpoint >= 22 && bDev.KeyEpoint <= 28)
{
if (device != null)
{
if (device.Type == DeviceType.DimmableLight && bDev.BindCluster == 8)
{
tempList.Remove(bDev.KeyEpoint);
}
}
}
break;
case 4:
if (bDev.KeyEpoint >= 14 && bDev.KeyEpoint <= 21 && bDev.BindCluster == 258)
{
tempList.Remove(bDev.KeyEpoint);
}
break;
case 5:
if (bDev.KeyEpoint >= 2 && bDev.KeyEpoint <= 4)
{
if (device != null)
{
//空调绑定类型
if (device.Type == DeviceType.Thermostat && bDev.BindCluster == 513)
{
tempList.Remove(bDev.KeyEpoint);
}
}
}
break;
case 6:
if (bDev.KeyEpoint == 13)
{
if (device != null)
{
if (device.Type == DeviceType.FreshAir && bDev.BindCluster == 514)
{
tempList.Remove(bDev.KeyEpoint);
}
}
}
break;
}
}
}
return tempList;
}
///
/// 能显示的房间列表
///
public static List GetSupportRoomList(Panel curControlDev, List supportRoomList, List curBindTypeList, int curDeviceBindType)
{
var roomTempList = new List();
for (int i = 0; i < supportRoomList.Count; i++)
{
var room = supportRoomList[i];
//如果房间为喜爱[后来改名为常用房间],则不显示
if (room.IsLove == true)
{
continue;
}
List roomIncludeMatchDevice = new List();
List roomIncludeMatchScene = new List();
if (curDeviceBindType == 0)
{
foreach (var sceneId in room.ListSceneId)
{
var scene = HdlSceneLogic.Current.GetSceneUIBySceneId(sceneId);
if (scene == null)
{
continue;
}
var tempSc = curBindTypeList.Find(obj => obj.BindScenesId == sceneId);
if (tempSc == null)
{
//被绑定目标不能再次出现
roomIncludeMatchScene.Add(scene);
}
}
}
else
{
foreach (var de in room.ListDevice)
{
var device = LocalDevice.Current.GetDevice(de);
if (device != null)
{
var tempDev = curBindTypeList.Find(obj => obj.BindMacAddr + obj.BindEpoint == device.DeviceAddr + device.DeviceEpoint);
if (tempDev == null)
{
switch (curDeviceBindType)
{
case 1:
if (device.DfunctionType == DeviceFunctionType.A开关)
{
if (device.Type != DeviceType.AirSwitch)
{
roomIncludeMatchDevice.Add(device);
}
}
break;
case 2:
if (device.DfunctionType == DeviceFunctionType.A插座)
{
if (device.Type != DeviceType.AirSwitch)
{
roomIncludeMatchDevice.Add(device);
}
}
break;
case 3:
if (device.DfunctionType == DeviceFunctionType.A灯光)
{
if (device.Type != DeviceType.AirSwitch)
{
roomIncludeMatchDevice.Add(device);
}
}
//if (device.Type == DeviceType.DimmableLight)
//{
// roomIncludeMatchDevice.Add(device);
//}
break;
case 4:
if (device.Type == DeviceType.WindowCoveringDevice)
{
roomIncludeMatchDevice.Add(device);
}
break;
case 5:
if (device.Type == DeviceType.Thermostat)
{
if (BindInfo.checkRealAcDevice(device) == false)
{
continue;
}
roomIncludeMatchDevice.Add(device);
}
break;
case 6:
if (device.Type == DeviceType.FreshAir)
{
if (BindInfo.checkRealFreshAirDevice(device) == false)
{
continue;
}
roomIncludeMatchDevice.Add(device);
}
break;
}
}
}
}
}
if (curDeviceBindType == 0)
{
if (room.ListSceneId.Count == 0)
{
continue;
}
if (roomIncludeMatchScene.Count == 0)
{
continue;
}
}
else
{
if (room.ListDevice.Count == 0)
{
continue;
}
if (roomIncludeMatchDevice.Count == 0)
{
continue;
}
}
if (!string.IsNullOrEmpty(room.FloorId))
{
//有楼层
if (room.FloorId == curControlDev.currentSelectFloorId)
{
roomTempList.Add(room);
}
}
else
{
//没有楼层
roomTempList.Add(room);
}
}
return roomTempList;
}
///
/// 匹配的类型绑定文本个数提示
///
/// 当前类型 0:场景 1:开关 2:插座 3:灯光 4:遮阳 5:空调 6:新风
/// 开关和灯光动态个数
///
public static string MatchTypeBindTextTip(int curBindType, int countDynamic = 0)
{
string[] msgArry = Language.StringByID(R.MyInternationalizationString.AddMoreTip).Split(new string[] { "{0}" }, StringSplitOptions.RemoveEmptyEntries);
var tipText = msgArry[0];
switch (curBindType)
{
case 0:
//场景共20个
var temp0 = 20 - countDynamic;
tipText += temp0 + msgArry[1] + Language.StringByID(R.MyInternationalizationString.scene);
break;
case 1:
//开关共10个
var temp1 = 10 - countDynamic;
tipText += temp1 + msgArry[1] + Language.StringByID(R.MyInternationalizationString.uDeviceBelongId13);
break;
case 2:
//开关共10个
var temp2 = 10 - countDynamic;
tipText += temp2 + msgArry[1] + Language.StringByID(R.MyInternationalizationString.uDeviceBelongId14);
break;
case 3:
//开关中可分配灯光功能共10个,调光占7个
var temp3 = 17 - countDynamic;
tipText += temp3 + msgArry[1] + Language.StringByID(R.MyInternationalizationString.uDeviceBelongId15);
break;
case 4:
//遮阳共8个
var temp4 = 8 - countDynamic;
tipText += temp4 + msgArry[1] + Language.StringByID(R.MyInternationalizationString.uDeviceBelongId100);
break;
case 5:
//空调共3个
var temp5 = 3 - countDynamic;
tipText += temp5 + msgArry[1] + Language.StringByID(R.MyInternationalizationString.uDeviceBelongId3600);
break;
case 6:
//新风共1个
var temp6 = 1 - countDynamic;
tipText += temp6 + msgArry[1] + Language.StringByID(R.MyInternationalizationString.uDeviceBelongId2310);
break;
}
return tipText;
}
///
/// 所有房间中匹配的支持绑定的所有目标列表
///
///
///
/// 当前设备绑定类型 1:开关 2:插座 3:灯光 4:遮阳 5:空调 6:新风
/// 当前类型的绑定表
///
public static List GetAllRoomSupportDeviceList(List currentPanelSupportBindDeviceList, List supportRoomList, List curBindTypeList, int curDeviceBindType)
{
currentPanelSupportBindDeviceList.Clear();
List currentPanelBindSupportDeviceListTemp = new List();
foreach (var r in supportRoomList)
{
if (r.ListDevice.Count == 0)
{
continue;
}
foreach (var deviceKeys in r.ListDevice)
{
var device = LocalDevice.Current.GetDevice(deviceKeys);
if (device == null)
{
continue;
}
var tempDev = curBindTypeList.Find(obj => obj.BindMacAddr + obj.BindEpoint == deviceKeys);
if (tempDev == null)
{
//被绑定目标不能再次出现
switch (curDeviceBindType)
{
case 1:
if (device.DfunctionType == DeviceFunctionType.A开关)
{
if (device.Type != DeviceType.AirSwitch)
{
currentPanelBindSupportDeviceListTemp.Add(device);
}
}
break;
case 2:
if (device.DfunctionType == DeviceFunctionType.A插座)
{
if (device.Type != DeviceType.AirSwitch)
{
if (device.Type != DeviceType.AirSwitch)
{
currentPanelBindSupportDeviceListTemp.Add(device);
}
}
}
break;
case 3:
if (device.DfunctionType == DeviceFunctionType.A灯光)
{
currentPanelBindSupportDeviceListTemp.Add(device);
}
//if (device.Type == DeviceType.DimmableLight)
//{
// currentPanelBindSupportDeviceListTemp.Add(device);
//}
break;
case 4:
if (device.Type == DeviceType.WindowCoveringDevice)
{
currentPanelBindSupportDeviceListTemp.Add(device);
}
break;
case 5:
if (device.Type == DeviceType.Thermostat)
{
if (BindInfo.checkRealAcDevice(device) == false)
{
continue;
}
currentPanelBindSupportDeviceListTemp.Add(device);
}
break;
case 6:
if (device.Type == DeviceType.FreshAir)
{
if (BindInfo.checkRealFreshAirDevice(device) == false)
{
continue;
}
currentPanelBindSupportDeviceListTemp.Add(device);
}
break;
}
}
}
}
return currentPanelBindSupportDeviceListTemp;
}
///
/// 所有房间中匹配的支持绑定的所有目标列表
///
///
///
/// 当前类型的绑定表
/// 当前设备绑定类型 0:场景
///
public static List GetAllRoomSupportSceneList(List currentPanelSupportBindSceneList, List supportRoomList, List curBindTypeList, int curDeviceBindType = 0)
{
currentPanelSupportBindSceneList.Clear();
List currentPanelBindSupportSceneListTemp = new List();
foreach (var room in supportRoomList)
{
//如果房间为喜爱,则不显示
if (room.IsLove == true)
{
continue;
}
//如果房间中没有场景,则不显示
if (room.ListSceneId.Count == 0)
{
continue;
}
foreach (var sceneId in room.ListSceneId)
{
var scene = HdlSceneLogic.Current.GetSceneUIBySceneId(sceneId);
if (scene == null)
{
continue;
}
var tempSc = curBindTypeList.Find(obj => obj.BindScenesId == sceneId);
if (tempSc == null)
{
//被绑定目标不能再次出现
currentPanelSupportBindSceneList.Add(scene);
}
}
}
return currentPanelSupportBindSceneList;
}
///
/// 获取本地未分配的支持当前类型的绑定设备列表
///
///
///
/// 当前类型的绑定表
///
public static List GetUndistributeDeviceList(List undistruibuteDevList, List curBindTypeList, int curDeviceBindType)
{
undistruibuteDevList.Clear();
List UndistributeCommonDeviceListTemp = new List();
//获取本地设备列表
foreach (var tempDev in Shared.Common.LocalDevice.Current.listAllDevice)
{
//获取设备所属房间
var tempDevRoom = HdlRoomLogic.Current.GetRoomByDevice(tempDev);
if (tempDevRoom == null)
{
UndistributeCommonDeviceListTemp.Add(tempDev);
}
}
foreach (var device in UndistributeCommonDeviceListTemp)
{
var tempDev = curBindTypeList.Find(obj => obj.BindMacAddr + obj.BindEpoint == device.DeviceAddr + device.DeviceEpoint);
if (tempDev == null)
{
//被绑定目标不能再次出现
switch (curDeviceBindType)
{
case 1:
if (device.DfunctionType == DeviceFunctionType.A开关)
{
if (device.Type != DeviceType.AirSwitch)
{
undistruibuteDevList.Add(device);
}
}
break;
case 2:
if (device.DfunctionType == DeviceFunctionType.A插座)
{
if (device.Type != DeviceType.AirSwitch)
{
undistruibuteDevList.Add(device);
}
}
break;
case 3:
if (device.DfunctionType == DeviceFunctionType.A灯光)
{
if (device.Type != DeviceType.AirSwitch)
{
undistruibuteDevList.Add(device);
}
}
break;
case 4:
if (device.Type == DeviceType.WindowCoveringDevice)
{
undistruibuteDevList.Add(device);
}
break;
case 5:
if (device.Type == DeviceType.Thermostat)
{
if (BindInfo.checkRealAcDevice(device) == false)
{
continue;
}
undistruibuteDevList.Add(device);
}
break;
case 6:
if (device.Type == DeviceType.FreshAir)
{
if (BindInfo.checkRealFreshAirDevice(device) == false)
{
continue;
}
undistruibuteDevList.Add(device);
}
break;
}
}
}
return undistruibuteDevList;
}
///
/// 获取当前房间中匹配的支持绑定的场景列表
///
///
public static List GetCurRoomSupportSceneList(Room curRoom, List currentRoomSupportBindSceneList, List curBindTypeList, int curDeviceBindType = 0)
{
currentRoomSupportBindSceneList.Clear();
List curRoomDeviceListTemp = new List();
foreach (var sceneId in curRoom.ListSceneId)
{
var tempSc = curBindTypeList.Find(obj => obj.BindScenesId == sceneId);
if (tempSc != null)
{
//被绑定目标不能再次出现
continue;
}
var scene = HdlSceneLogic.Current.GetSceneUIBySceneId(sceneId);
if (scene != null)
{
curRoomDeviceListTemp.Add(scene);
}
}
return curRoomDeviceListTemp;
}
///
/// 获取当前房间中匹配的支持绑定的设备列表
///
///
public static List GetCurRoomSupportDeviceList(Room curRoom, List currentRoomSupportBindDeviceList, List curBindTypeList, int curDeviceBindType)
{
currentRoomSupportBindDeviceList.Clear();
List curRoomDeviceListTemp = new List();
foreach (var deviceKeys in curRoom.ListDevice)
{
var device = LocalDevice.Current.GetDevice(deviceKeys);
if (device != null)
{
//获取设备类型的
var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List() { device });
var tempDev = curBindTypeList.Find(obj => obj.BindMacAddr + obj.BindEpoint == device.DeviceAddr + device.DeviceEpoint);
if (tempDev != null)
{
//被绑定目标不能再次出现
continue;
}
switch (curDeviceBindType)
{
case 1:
if (device.DfunctionType == DeviceFunctionType.A开关)
{
if (device.Type != DeviceType.AirSwitch)
{
curRoomDeviceListTemp.Add(device);
}
}
break;
case 2:
if (device.DfunctionType == DeviceFunctionType.A插座)
{
if (device.Type != DeviceType.AirSwitch)
{
curRoomDeviceListTemp.Add(device);
}
}
break;
case 3:
if (device.DfunctionType == DeviceFunctionType.A灯光)
{
if (device.Type != DeviceType.AirSwitch)
{
curRoomDeviceListTemp.Add(device);
}
}
break;
case 4:
if (device.Type == DeviceType.WindowCoveringDevice)
{
if (deviceEnumInfo.ConcreteType != Common.DeviceConcreteType.ButtonPanel_SimpleMultifunction)
{
curRoomDeviceListTemp.Add(device);
}
}
break;
case 5:
if (device.Type == DeviceType.Thermostat)
{
if (BindInfo.checkRealAcDevice(device) == false)
{
continue;
}
curRoomDeviceListTemp.Add(device);
}
break;
case 6:
if (device.Type == DeviceType.FreshAir)
{
if (BindInfo.checkRealFreshAirDevice(device) == false)
{
continue;
}
curRoomDeviceListTemp.Add(device);
}
break;
}
}
}
return curRoomDeviceListTemp;
}
}
}