using System;
|
using System.Collections.Generic;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
public class AlexaDeviceListPage : FrameLayout
|
{
|
public AlexaDeviceListPage ()
|
{
|
BackgroundColor = SkinStyle.Current.MainColor;
|
}
|
|
public void ShowPage ()
|
{
|
#region 标题
|
var topView = new FrameLayout () {
|
Y = Application.GetRealHeight (36),
|
Height = Application.GetRealHeight (90),
|
};
|
AddChidren (topView);
|
|
var title = new Button () {
|
TextAlignment = TextAlignment.Center,
|
Text = "Alexa",
|
TextSize = 19,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
topView.AddChidren (title);
|
|
Button ItemButton = new Button () {
|
Width = Application.GetRealWidth (55),
|
Height = Application.GetRealHeight (55),
|
UnSelectedImagePath = "Item/+.png",
|
SelectedImagePath = "Item/+.png",
|
X = Application.GetRealWidth (640 - 80),
|
Y = Application.GetRealHeight (17),
|
};
|
topView.AddChidren (ItemButton);
|
|
var back = new Button () {
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (85),
|
UnSelectedImagePath = "Item/Back.png",
|
SelectedImagePath = "Item/BackSelected.png",
|
};
|
topView.AddChidren (back);
|
back.MouseUpEventHandler += (sender, e) => {
|
(Parent as PageLayout).PageIndex -= 1;
|
};
|
#endregion
|
|
var bodyView = new VerticalScrolViewLayout () {
|
Y = topView.Bottom,
|
Height = Application.GetRealHeight (1136 - 126),
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
};
|
AddChidren (bodyView);
|
var alexaDeviceLista = new List<UpdateDeviceObj> ();
|
var alexaSceneList = new List<SceneByRegion> ();
|
|
System.Threading.Tasks.Task.Factory.StartNew (() => {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start ("Please wait...");
|
});
|
try {
|
alexaDeviceLista = ReadDeviceList ();
|
alexaSceneList = ReadSceneList ();
|
|
if (alexaDeviceLista.Count > 0) {
|
Application.RunOnMainThread (() => {
|
InitDevcieRow (alexaDeviceLista, bodyView);
|
});
|
}
|
if (alexaSceneList.Count > 0) {
|
Application.RunOnMainThread (() => {
|
InitSceneRow (alexaSceneList, bodyView);
|
});
|
}
|
} catch (Exception ex) {
|
Console.WriteLine (ex.Message);
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
|
ItemButton.MouseUpEventHandler += (sender, e) => {
|
Action action = () => {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start ("please wait...");
|
});
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
alexaDeviceLista = ReadDeviceList ();
|
alexaSceneList = ReadSceneList ();
|
Application.RunOnMainThread (() => {
|
InitDevcieRow (alexaDeviceLista, bodyView);
|
});
|
} catch (Exception ex) {
|
Console.WriteLine (ex.Message);
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
};
|
|
Action<List<string>, List<string>> saveAction = (roomSceneFilePathList, roomDeviceFilePathList) => {
|
System.Threading.Tasks.Task.Factory.StartNew (() => {
|
try {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start ("please wait...");
|
});
|
foreach (var newDevicePath in roomDeviceFilePathList) {
|
var common = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (newDevicePath)));
|
//newDeviceList.Add (new UpdateDeviceObj () {
|
// DeviceName = common.Name, DeviceID = common.DeviceID, Id = 1, DeviceType = common.Type.ToString (), LoopID = common.LoopID,
|
// MAC = UserConfig.Instance.GatewayMAC, RegionID = UserConfig.Instance.CurrentRegion.RegionID, SubnetID = common.SubnetID
|
//});
|
if (common != null) {
|
var oldDevice = alexaDeviceLista.Find ((obj) => obj.SubnetID == common.SubnetID && obj.DeviceID == common.DeviceID && obj.LoopID == common.LoopID && obj.DeviceType == common.Type.ToString ());
|
if (oldDevice == null) {
|
AddDevice (common);
|
}
|
}
|
}
|
foreach (var oldDevice in alexaDeviceLista) {
|
var oldDevicePath = "Equipment_" + oldDevice.DeviceType + "_" + oldDevice.SubnetID + "_" + oldDevice.DeviceID + "_" + (oldDevice.LoopID.ToString ().Length < 2 ? "0" + oldDevice.LoopID.ToString () : oldDevice.LoopID.ToString ());
|
|
if (!roomDeviceFilePathList.Contains (oldDevicePath)) {
|
DelDevice (oldDevice.Id);
|
Console.WriteLine ("delDevice " + oldDevice.DeviceName);
|
}
|
}
|
|
foreach (var newScenePath in roomSceneFilePathList) {
|
var tempScene = Scene.GetSceneByFilePath (newScenePath);
|
if (tempScene != null) {
|
var oldScene = alexaSceneList.Find ((obj) => obj.SceneName == tempScene.Name);
|
if (oldScene == null) {
|
int sceneDeviceCount = tempScene.DeviceFilePathList.Count;
|
var uploadScene = new SceneAndDeviceList () { MAC = UserConfig.Instance.GatewayMAC, RegionID = UserConfig.Instance.CurrentRegion.RegionID, SceneName = tempScene.Name };
|
|
byte [] replyBytes = null;
|
if (!tempScene.busScene) {
|
foreach (var deviceFilePath in tempScene.DeviceFilePathList) {
|
var common = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (common.Type == DeviceType.FanModule) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<FanModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device != null) {
|
uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
|
Command = (int)Command.SetSingleLight, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
|
DeviceName = device.Name, DeviceType = "FanModule", LoopId = device.LoopID,
|
DataString = device.WindSpeed.ToString ()
|
});
|
}
|
} else if (common.Type == DeviceType.LightDimming) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightDimming> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device != null) {
|
uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
|
Command = (int)Command.SetSingleLight, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
|
DeviceName = device.Name, DeviceType = "LightDimming", LoopId = device.LoopID,
|
DataString = device.CurrentBrightness.ToString ()
|
});
|
}
|
} else if (common.Type == DeviceType.LightDALI) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightDALI> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device != null) {
|
uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
|
Command = (int)Command.SetSingleLight, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
|
DeviceName = device.Name, DeviceType = "LightDimming", LoopId = device.LoopID,
|
DataString = device.CurrentBrightness.ToString ()
|
});
|
}
|
} else if (common.Type == DeviceType.LightRGB) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightLogic> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device != null) {
|
uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
|
Command = (int)Command.SetLogicLoopColor, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
|
DeviceName = device.Name, DeviceType = "LightRGB", LoopId = device.LoopID,
|
DataString = device.CurrentBrightness + "," + device.RStatus + "," + device.GStatus + "," + device.BStatus
|
});
|
}
|
} else if (common.Type == DeviceType.LightSwitch || common.Type == DeviceType.LightSwitchSocket) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device != null) {
|
uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
|
Command = (int)Command.SetSingleLight, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
|
DeviceName = device.Name, DeviceType = "LightSwitch", LoopId = device.LoopID,
|
DataString = device.CurrentBrightness.ToString ()
|
});
|
}
|
} else if (common.Type == DeviceType.LightEnergySocket) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device != null) {
|
uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
|
Command = (int)Command.SetSingleLight, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
|
DeviceName = device.Name, DeviceType = "LightSwitch", LoopId = device.LoopID,
|
DataString = device.CurrentBrightness.ToString ()
|
});
|
}
|
} else if (common.Type == DeviceType.LightEnergySwitch) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device != null) {
|
uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
|
Command = (int)Command.SetSingleLight, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
|
DeviceName = device.Name, DeviceType = "LightSwitch", LoopId = device.LoopID,
|
DataString = device.CurrentBrightness.ToString ()
|
});
|
}
|
} else if (common.Type == DeviceType.CurtainModel) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainModel> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device != null) {
|
uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
|
Command = (int)Command.UpdataCurtainModelStutas, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
|
DeviceName = device.Name, DeviceType = "CurtainModule", LoopId = device.LoopID,
|
DataString = device.Status.ToString ()
|
});
|
}
|
} else if (common.Type == DeviceType.CurtainRoller) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainRoller> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device != null) {
|
uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
|
Command = (int)Command.UpdataCurtainModelStutas, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
|
DeviceName = device.Name, DeviceType = "CurtainRoller", LoopId = device.LoopID,
|
DataString = (device.Status + 3).ToString ()
|
});
|
}
|
} else if (common.Type == DeviceType.CurtainTrietex) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainTrietex> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device != null) {
|
uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
|
Command = (int)Command.UpdataCurtainModelStutas, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
|
DeviceName = device.Name, DeviceType = "CurtainRoller", LoopId = device.LoopID,
|
DataString = (device.Status + 3).ToString ()
|
});
|
}
|
} else if (common.Type == DeviceType.HVAC || common.Type == DeviceType.ACInfrared) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<HVAC> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device != null) {
|
uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
|
Command = (int)Command.SetACMode, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
|
DeviceName = device.Name, DeviceType = "HVAC", LoopId = device.LoopID,
|
DataString = device.Power + "," + device.TemperatureMode + "," + device.SetMode + "," + device.SetFanSpeed + "," + device.SetTemperature
|
});
|
}
|
} else if (common.Type == DeviceType.FoolHeat) {
|
//var device = Newtonsoft.Json.JsonConvert.DeserializeObject<FoolHeat> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
//if (device == null) {
|
// continue;
|
//}
|
//replyBytes = Control.ControlBytesSendHasReturn (Command.SetFoolHeat, device.SubnetID, device.DeviceID,
|
//new byte [] { device.LoopID, (byte)(device.Status + device.WorkingMode * 16), 0,device.WorkingMode,device.NormalTemperature, device.DayTemperature,
|
//device.NightTemperature, device.AwayTemperature , 0, 0 });
|
|
} else if (common.Type == DeviceType.FanModule) {
|
//var device = Newtonsoft.Json.JsonConvert.DeserializeObject<FanModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
//if (device == null) {
|
// continue;
|
//}
|
//replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, device.SubnetID, device.DeviceID, new byte [] { 1, (byte)device.WindSpeed });
|
} else if (common.Type == DeviceType.LogicModule) {
|
var device = Newtonsoft.Json.JsonConvert.DeserializeObject<LogicModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath)));
|
if (device != null) {
|
uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
|
Command = (int)Command.SetScene, SubnetId = device.SubnetID, DeviceId = device.DeviceID,
|
DeviceName = device.Name, DeviceType = "SceneControl", LoopId = device.AreaID,
|
DataString = device.AreaSceneID.ToString ()
|
});
|
}
|
}
|
|
}
|
} else {
|
foreach (var common in tempScene.GlobalSceneDeviceList) {
|
switch (common.obj1) {
|
case 0://0 无效 Invalid
|
break;
|
case 85://0x55 场景 Scene ||0x0002
|
uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
|
Command = (int)Command.SetScene, SubnetId = common.SubnetID, DeviceId = common.DeviceID,
|
DeviceName = common.Name, DeviceType = "SceneControl", LoopId = common.obj2,
|
DataString = common.obj3.ToString ()
|
});
|
//replyBytes = Control.ControlBytesSendHasReturn (Command.SetScene, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
|
break;
|
case 86://0x56 序列 Sequence ||0x001A
|
//replyBytes = Control.ControlBytesSendHasReturn (Command.SetSeries, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
|
break;
|
case 88://0x58 通用开关 Universal Switch ||0xe01c
|
uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
|
Command = (int)Command.SetCommonSwitch, SubnetId = common.SubnetID, DeviceId = common.DeviceID,
|
DeviceName = common.Name, DeviceType = "UVSwitch", LoopId = common.obj2,
|
DataString = common.obj3.ToString ()
|
});
|
//replyBytes = Control.ControlBytesSendHasReturn (Command.SetCommonSwitch, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
|
break;
|
case 89: //0x59 单路调节 Single Channel Lighting Control 0031
|
uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
|
Command = (int)Command.SetSingleLight, SubnetId = common.SubnetID, DeviceId = common.DeviceID,
|
DeviceName = common.Name, DeviceType = "LightDimming", LoopId = common.obj2,
|
DataString = common.obj3.ToString ()
|
});
|
//replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
|
break;
|
case 92://0x5c 窗帘开关 Curtain Switch e3e0
|
uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
|
Command = (int)Command.UpdataCurtainModelStutas, SubnetId = common.SubnetID, DeviceId = common.DeviceID,
|
DeviceName = common.Name, DeviceType = "CurtainModel", LoopId = common.obj2,
|
DataString = common.obj3.ToString ()
|
});
|
//replyBytes = Control.ControlBytesSendHasReturn (Command.UpdataCurtainModelStutas, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
|
break;
|
case 94://0x5e GPRS控制 GPRS Control E3D4
|
replyBytes = Control.ControlBytesSendHasReturn (Command.GPRSControl, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
|
break;
|
case 95://0x5f 面板控制 Panel Control e3d8
|
//replyBytes = Control.ControlBytesSendHasReturn (Command.InstructionPanelKey, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
|
break;
|
case 100://0x64 广播场景 Broadcast Scene ||0x0002
|
uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
|
Command = (int)Command.SetScene, SubnetId = common.SubnetID, DeviceId = common.DeviceID,
|
DeviceName = common.Name, DeviceType = "SceneControl", LoopId = common.obj2,
|
DataString = common.obj3.ToString ()
|
});
|
//replyBytes = Control.ControlBytesSendHasReturn (Command.SetScene, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
|
break;
|
case 101://0x65 广播回路 Broadcast Channel 0031
|
uploadScene.DeviceListObject.Add (new AddCloudSceneDeviceData () {
|
Command = (int)Command.SetSingleLight, SubnetId = common.SubnetID, DeviceId = common.DeviceID,
|
DeviceName = common.Name, DeviceType = "LightDimming", LoopId = common.obj2,
|
DataString = common.obj3.ToString ()
|
});
|
//replyBytes = Control.ControlBytesSendHasReturn (Command.SetSingleLight, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
|
break;
|
//case 102://0x66 消防模块 Security Module 011E
|
// replyBytes = Control.ControlBytesSendHasReturn (Command.SecurityModule, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
|
// break;
|
//case 103://0x67 音乐播放 Music Control 0218
|
//replyBytes = Control.ControlBytesSendHasReturn (Command.MusicControl, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
|
//break;
|
//104 通用控制 Universal Control
|
//105 连接页 Link Page
|
//107 RGB调节 RGB Control
|
//108 红外控制 Infrared Control
|
//case 109://109 逻辑灯调节 Logic Light Adjust || 0xE45E
|
// replyBytes = Control.ControlBytesSendHasReturn (Command.LogicLightAdjust, common.SubnetID, common.DeviceID, new byte [] { common.obj2, common.obj3, common.obj4, common.obj5 });
|
// break;
|
//}
|
//110 逻辑场景 Logic Scene
|
//112 LCD & LED休眠 LCD & LED Sleep
|
//113 服务器控制 Server control
|
}
|
}
|
}
|
|
AddScene (uploadScene);
|
}
|
}
|
|
}
|
|
alexaDeviceLista = ReadDeviceList ();
|
Application.RunOnMainThread (() => {
|
InitDevcieRow (alexaDeviceLista, bodyView);
|
});
|
alexaSceneList = ReadSceneList ();
|
Application.RunOnMainThread (() => {
|
InitSceneRow (alexaSceneList, bodyView);
|
});
|
|
} catch (Exception ex) {
|
Console.WriteLine (ex.Message);
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
};
|
|
System.Threading.Tasks.Task.Factory.StartNew (() => {
|
try {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start ("please wait...");
|
});
|
var tempRoom = new Room ();
|
foreach (var device in alexaDeviceLista) {//特殊处理服务器与本地设备类型不一样的设备
|
var deviceTypeSaveString = device.DeviceType;
|
if (deviceTypeSaveString == "CurtainModule") {
|
deviceTypeSaveString = "CurtainModel";
|
} else if (deviceTypeSaveString == "LightEnergySwitch") {
|
deviceTypeSaveString = "LightSwitch";
|
} else if (deviceTypeSaveString == "LightEnergySocket") {
|
deviceTypeSaveString = "LightSwitch";
|
} else if (deviceTypeSaveString == "LightSwitchSocket") {
|
deviceTypeSaveString = "LightSwitch";
|
} else if (deviceTypeSaveString == "LightLogic") {
|
deviceTypeSaveString = "LightRGB";
|
}else if (deviceTypeSaveString == "ACInfrared") {
|
deviceTypeSaveString = "HVAC";
|
}
|
|
var devicePath = "Equipment_" + deviceTypeSaveString + "_" + device.SubnetID + "_" + device.DeviceID + "_" + (device.LoopID.ToString ().Length < 2 ? "0" + device.LoopID.ToString () : device.LoopID.ToString ());
|
tempRoom.DeviceFilePathList.Add (devicePath);
|
}
|
foreach (var scene in alexaSceneList) {
|
tempRoom.SceneFilePathList.Add (scene.SceneName);
|
}
|
Application.RunOnMainThread (() => {
|
var userDeviceListPage = new AlexaSettingPage (tempRoom);
|
userDeviceListPage.Show ();
|
userDeviceListPage.ShowPage (action, saveAction);
|
});
|
} catch (Exception ex) {
|
Console.WriteLine (ex.Message);
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
};
|
}
|
|
#region 关于设备的方法
|
/// <summary>
|
/// 读取Alexa设备列表
|
/// </summary>
|
public List<UpdateDeviceObj> ReadDeviceList ()
|
{
|
var deviceList = new List<UpdateDeviceObj> ();
|
var requestObj = new DeviceByRegionListObj () { RegionID = UserConfig.Instance.CurrentRegion.RegionID };
|
var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
|
var revertObj = MainPage.RequestHttps ("DeviceByRegionList", requestJson);
|
if (revertObj.StateCode == "SUCCESS") {
|
deviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<UpdateDeviceObj>> (revertObj.ResponseData.ToString());
|
}
|
return deviceList;
|
}
|
|
/// <summary>
|
/// 添加设备
|
/// </summary>
|
public bool AddDevice (Common device)
|
{
|
var uploadDevice = new AlexaDevice () {
|
RegionID = UserConfig.Instance.CurrentRegion.RegionID, MAC = UserConfig.Instance.GatewayMAC.Replace (".", ""),
|
DeviceName = device.Name, DeviceID = device.DeviceID, SubnetID = device.SubnetID, LoopID = device.LoopID, DeviceType = device.Type.ToString ()
|
};
|
if (device.Type.ToString () == "CurtainModel") {
|
uploadDevice.DeviceType = "CurtainModule";
|
} else if (device.Type.ToString () == "LightEnergySwitch" || device.Type.ToString () == "LightSwitchSocket" || device.Type.ToString () =="LightEnergySocket") {
|
uploadDevice.DeviceType = "LightSwitch";
|
} else if (device.Type.ToString () == "ACInfrared") {
|
uploadDevice.DeviceType = "HVAC";
|
}
|
var requestObj = new UploadDevicesObj () { Device = uploadDevice };
|
var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
|
var revertObj = MainPage.RequestHttps ("UploadDevices", requestJson);
|
if (revertObj.StateCode == "SUCCESS") {
|
return true;
|
}
|
return false;
|
}
|
|
/// <summary>
|
/// 删除设备
|
/// </summary>
|
public bool DelDevice(int commonId)
|
{
|
var requestObj = new DelDeviceObj () { Id = commonId };
|
var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
|
var revertObj = MainPage.RequestHttps ("DelDevice", requestJson);
|
if (revertObj.StateCode == "SUCCESS") {
|
return true;
|
}
|
return false;
|
}
|
#endregion
|
|
#region 关于场景的方法
|
/// <summary>
|
/// 读取Alexa场景列表
|
/// </summary>
|
public List<SceneByRegion> ReadSceneList ()
|
{
|
var sceneList = new List<SceneByRegion> ();
|
var requestObj = new SceneByRegionListObj () { RegionID = UserConfig.Instance.CurrentRegion.RegionID };
|
var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
|
var revertObj = MainPage.RequestHttps ("SceneByRegionList", requestJson);
|
if (revertObj.StateCode == "SUCCESS") {
|
sceneList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SceneByRegion>> (revertObj.ResponseData.ToString ());
|
}
|
return sceneList;
|
}
|
|
/// <summary>
|
/// 添加场景
|
/// </summary>
|
public bool AddScene (SceneAndDeviceList sceneMark)
|
{
|
var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (sceneMark);
|
var revertObj = MainPage.RequestHttps ("AddSceneAndDeviceList", requestJson);
|
if (revertObj.StateCode == "SUCCESS") {
|
//var requestAddDeviceObj = new BindDeviceToSceneItemObj () { SceneId = sceneId, Command = command, DeviceID = 0, DataString = dataString };
|
//var requestAddDeviceJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestAddDeviceObj);
|
//var revertAddDeviceObj = MainPage.RequestHttps ("BindDeviceToSceneItem", requestAddDeviceJson);
|
//if (revertAddDeviceObj.StateCode == "SUCCESS") {
|
return true;
|
//}
|
}
|
return false;
|
}
|
|
/// <summary>
|
/// 上传场景设备控制数据
|
/// </summary>
|
//public bool AddDeviceDateToScene (int sceneId,string command,string dataString)
|
//{
|
// var requestAddDeviceObj = new BindDeviceToSceneItemObj () { SceneId = sceneId, Command = command, DeviceID = 0, DataString = dataString };
|
// var requestAddDeviceJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestAddDeviceObj);
|
// var revertAddDeviceObj = MainPage.RequestHttps ("BindDeviceToSceneItem", requestAddDeviceJson);
|
// if (revertAddDeviceObj.StateCode == "SUCCESS") {
|
// return true;
|
// }
|
// return false;
|
//}
|
|
/// <summary>
|
/// 删除场景
|
/// </summary>
|
public bool DelScene (int sceneId)
|
{
|
var requestObj = new DeleteScene () { Id = sceneId };
|
var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
|
var revertObj = MainPage.RequestHttps ("DeleteScene", requestJson);
|
if (revertObj.StateCode == "SUCCESS") {
|
return true;
|
}
|
return false;
|
}
|
#endregion
|
|
/// <summary>
|
/// 添加设备界面
|
/// </summary>
|
public void InitDevcieRow (List<UpdateDeviceObj> list, VerticalScrolViewLayout bodyView)
|
{
|
bodyView.RemoveAll ();
|
foreach (var device in list) {
|
var rowView = new RowLayout () {
|
Height = Application.GetRealHeight (110),
|
};
|
bodyView.AddChidren (rowView);
|
var btn = new Button () {
|
X = Application.GetRealWidth(60),
|
Width = Application.GetRealWidth (640 - 60),
|
Text = device.DeviceName,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
rowView.AddChidren (btn);
|
|
var btnDel = new Button () {
|
Text = "Delete",
|
BackgroundColor = SkinStyle.Current.DelColor,
|
};
|
rowView.AddRightView (btnDel);
|
|
btnDel.MouseUpEventHandler += (sender, e) => {
|
var alert = new Alert ("", "Do you want to delete device?", "No", "Yes");
|
alert.Show ();
|
alert.ResultEventHandler += (s, dd) => {
|
if (dd) {
|
if (DelDevice (device.Id)) {
|
rowView.RemoveFromParent ();
|
list.Remove (device);
|
}
|
}
|
};
|
};
|
}
|
}
|
|
/// <summary>
|
/// 添加场景界面
|
/// </summary>
|
public void InitSceneRow (List<SceneByRegion> list, VerticalScrolViewLayout bodyView)
|
{
|
foreach (var scene in list) {
|
var rowView = new RowLayout () {
|
Height = Application.GetRealHeight (110),
|
};
|
bodyView.AddChidren (rowView);
|
var btn = new Button () {
|
X = Application.GetRealWidth (60),
|
Width = Application.GetRealWidth (640 - 60),
|
Text = scene.SceneName,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
rowView.AddChidren (btn);
|
btn.MouseUpEventHandler += (dd,ff) => {
|
//var alexaSceneSettingPage = new AlecaSceneEditPage ();
|
//UserMiddle.SettingPageView.AddChidren (alexaSceneSettingPage);
|
//alexaSceneSettingPage.ShowScene (scene);
|
//UserMiddle.SettingPageView.PageIndex = 2;
|
};
|
|
var btnDel = new Button () {
|
Text = "Delete",
|
BackgroundColor = SkinStyle.Current.DelColor,
|
};
|
rowView.AddRightView (btnDel);
|
|
btnDel.MouseUpEventHandler += (sender, e) => {
|
var alert = new Alert ("", "Do you want to delete scene?", "No", "Yes");
|
alert.Show ();
|
alert.ResultEventHandler += (s, dd) => {
|
if (dd) {
|
if (DelScene (scene.SceneId)) {
|
rowView.RemoveFromParent ();
|
list.Remove (scene);
|
}
|
}
|
};
|
};
|
}
|
|
}
|
}
|
}
|